From fb9b0ead94be5d7a9a8bc3b4e1a46e68ae657151 Mon Sep 17 00:00:00 2001 From: springstan Date: Sat, 11 Apr 2020 00:18:17 +0200 Subject: [PATCH 1/2] Add and use UNIT_VOLT constant --- homeassistant/components/apcupsd/sensor.py | 23 ++++++------- .../components/dsmr_reader/definitions.py | 8 ++--- homeassistant/components/elkm1/sensor.py | 3 +- homeassistant/components/envirophat/sensor.py | 10 +++--- .../components/greeneye_monitor/sensor.py | 3 +- .../components/growatt_server/sensor.py | 9 ++--- homeassistant/components/homematic/sensor.py | 3 +- homeassistant/components/isy994/sensor.py | 3 +- homeassistant/components/juicenet/sensor.py | 10 ++++-- homeassistant/components/lcn/const.py | 9 +++-- homeassistant/components/mysensors/sensor.py | 3 +- homeassistant/components/nut/const.py | 33 ++++++++++++------- homeassistant/components/onewire/sensor.py | 14 +++++--- homeassistant/components/smappee/sensor.py | 3 +- .../components/smartthings/sensor.py | 3 +- .../components/solaredge_local/sensor.py | 19 +++++++++-- homeassistant/components/solarlog/const.py | 11 +++++-- homeassistant/components/starline/sensor.py | 4 +-- homeassistant/components/ted5000/sensor.py | 8 ++--- .../components/wirelesstag/__init__.py | 3 +- homeassistant/const.py | 3 ++ tests/components/sma/test_sensor.py | 3 +- 22 files changed, 124 insertions(+), 64 deletions(-) diff --git a/homeassistant/components/apcupsd/sensor.py b/homeassistant/components/apcupsd/sensor.py index 85bbe5c950e7d..6989f58d3bbb5 100644 --- a/homeassistant/components/apcupsd/sensor.py +++ b/homeassistant/components/apcupsd/sensor.py @@ -12,6 +12,7 @@ TIME_MINUTES, TIME_SECONDS, UNIT_PERCENTAGE, + UNIT_VOLT, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -29,7 +30,7 @@ "badbatts": ["Bad Batteries", "", "mdi:information-outline"], "battdate": ["Battery Replaced", "", "mdi:calendar-clock"], "battstat": ["Battery Status", "", "mdi:information-outline"], - "battv": ["Battery Voltage", "V", "mdi:flash"], + "battv": ["Battery Voltage", UNIT_VOLT, "mdi:flash"], "bcharge": ["Battery", UNIT_PERCENTAGE, "mdi:battery"], "cable": ["Cable Type", "", "mdi:ethernet-cable"], "cumonbatt": ["Total Time on Battery", "", "mdi:timer"], @@ -42,33 +43,33 @@ "endapc": ["Date and Time", "", "mdi:calendar-clock"], "extbatts": ["External Batteries", "", "mdi:information-outline"], "firmware": ["Firmware Version", "", "mdi:information-outline"], - "hitrans": ["Transfer High", "V", "mdi:flash"], + "hitrans": ["Transfer High", UNIT_VOLT, "mdi:flash"], "hostname": ["Hostname", "", "mdi:information-outline"], "humidity": ["Ambient Humidity", UNIT_PERCENTAGE, "mdi:water-percent"], "itemp": ["Internal Temperature", TEMP_CELSIUS, "mdi:thermometer"], "lastxfer": ["Last Transfer", "", "mdi:transfer"], "linefail": ["Input Voltage Status", "", "mdi:information-outline"], "linefreq": ["Line Frequency", "Hz", "mdi:information-outline"], - "linev": ["Input Voltage", "V", "mdi:flash"], + "linev": ["Input Voltage", UNIT_VOLT, "mdi:flash"], "loadpct": ["Load", UNIT_PERCENTAGE, "mdi:gauge"], "loadapnt": ["Load Apparent Power", UNIT_PERCENTAGE, "mdi:gauge"], - "lotrans": ["Transfer Low", "V", "mdi:flash"], + "lotrans": ["Transfer Low", UNIT_VOLT, "mdi:flash"], "mandate": ["Manufacture Date", "", "mdi:calendar"], "masterupd": ["Master Update", "", "mdi:information-outline"], - "maxlinev": ["Input Voltage High", "V", "mdi:flash"], + "maxlinev": ["Input Voltage High", UNIT_VOLT, "mdi:flash"], "maxtime": ["Battery Timeout", "", "mdi:timer-off"], "mbattchg": ["Battery Shutdown", UNIT_PERCENTAGE, "mdi:battery-alert"], - "minlinev": ["Input Voltage Low", "V", "mdi:flash"], + "minlinev": ["Input Voltage Low", UNIT_VOLT, "mdi:flash"], "mintimel": ["Shutdown Time", "", "mdi:timer"], "model": ["Model", "", "mdi:information-outline"], - "nombattv": ["Battery Nominal Voltage", "V", "mdi:flash"], - "nominv": ["Nominal Input Voltage", "V", "mdi:flash"], - "nomoutv": ["Nominal Output Voltage", "V", "mdi:flash"], + "nombattv": ["Battery Nominal Voltage", UNIT_VOLT, "mdi:flash"], + "nominv": ["Nominal Input Voltage", UNIT_VOLT, "mdi:flash"], + "nomoutv": ["Nominal Output Voltage", UNIT_VOLT, "mdi:flash"], "nompower": ["Nominal Output Power", POWER_WATT, "mdi:flash"], "nomapnt": ["Nominal Apparent Power", "VA", "mdi:flash"], "numxfers": ["Transfer Count", "", "mdi:counter"], "outcurnt": ["Output Current", "A", "mdi:flash"], - "outputv": ["Output Voltage", "V", "mdi:flash"], + "outputv": ["Output Voltage", UNIT_VOLT, "mdi:flash"], "reg1": ["Register 1 Fault", "", "mdi:information-outline"], "reg2": ["Register 2 Fault", "", "mdi:information-outline"], "reg3": ["Register 3 Fault", "", "mdi:information-outline"], @@ -95,7 +96,7 @@ " Minutes": TIME_MINUTES, " Seconds": TIME_SECONDS, " Percent": UNIT_PERCENTAGE, - " Volts": "V", + " Volts": UNIT_VOLT, " Ampere": "A", " Volt-Ampere": "VA", " Watts": POWER_WATT, diff --git a/homeassistant/components/dsmr_reader/definitions.py b/homeassistant/components/dsmr_reader/definitions.py index 64eb2d9ea80c1..eb218fede6666 100644 --- a/homeassistant/components/dsmr_reader/definitions.py +++ b/homeassistant/components/dsmr_reader/definitions.py @@ -1,6 +1,6 @@ """Definitions for DSMR Reader sensors added to MQTT.""" -from homeassistant.const import ENERGY_KILO_WATT_HOUR, VOLUME_CUBIC_METERS +from homeassistant.const import ENERGY_KILO_WATT_HOUR, VOLUME_CUBIC_METERS, UNIT_VOLT def dsmr_transform(value): @@ -86,17 +86,17 @@ def tariff_transform(value): "dsmr/reading/phase_voltage_l1": { "name": "Current voltage L1", "icon": "mdi:flash", - "unit": "V", + "unit": UNIT_VOLT, }, "dsmr/reading/phase_voltage_l2": { "name": "Current voltage L2", "icon": "mdi:flash", - "unit": "V", + "unit": UNIT_VOLT, }, "dsmr/reading/phase_voltage_l3": { "name": "Current voltage L3", "icon": "mdi:flash", - "unit": "V", + "unit": UNIT_VOLT, }, "dsmr/consumption/gas/delivered": { "name": "Gas usage", diff --git a/homeassistant/components/elkm1/sensor.py b/homeassistant/components/elkm1/sensor.py index 79987d806a1fe..89e39407a8cb3 100644 --- a/homeassistant/components/elkm1/sensor.py +++ b/homeassistant/components/elkm1/sensor.py @@ -7,6 +7,7 @@ ) from elkm1_lib.util import pretty_const, username +from homeassistant.const import UNIT_VOLT from . import ElkAttachedEntity, create_elk_entities from .const import DOMAIN @@ -195,7 +196,7 @@ def unit_of_measurement(self): if self._element.definition == ZoneType.TEMPERATURE.value: return self._temperature_unit if self._element.definition == ZoneType.ANALOG_ZONE.value: - return "V" + return UNIT_VOLT return None def _element_changed(self, element, changeset): diff --git a/homeassistant/components/envirophat/sensor.py b/homeassistant/components/envirophat/sensor.py index ce1f154f911aa..81420cf389f0d 100644 --- a/homeassistant/components/envirophat/sensor.py +++ b/homeassistant/components/envirophat/sensor.py @@ -6,7 +6,7 @@ import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import CONF_DISPLAY_OPTIONS, CONF_NAME, TEMP_CELSIUS +from homeassistant.const import CONF_DISPLAY_OPTIONS, CONF_NAME, TEMP_CELSIUS, UNIT_VOLT import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle @@ -31,10 +31,10 @@ "magnetometer_z": ["magnetometer_z", " ", "mdi:magnet"], "temperature": ["temperature", TEMP_CELSIUS, "mdi:thermometer"], "pressure": ["pressure", "hPa", "mdi:gauge"], - "voltage_0": ["voltage_0", "V", "mdi:flash"], - "voltage_1": ["voltage_1", "V", "mdi:flash"], - "voltage_2": ["voltage_2", "V", "mdi:flash"], - "voltage_3": ["voltage_3", "V", "mdi:flash"], + "voltage_0": ["voltage_0", UNIT_VOLT, "mdi:flash"], + "voltage_1": ["voltage_1", UNIT_VOLT, "mdi:flash"], + "voltage_2": ["voltage_2", UNIT_VOLT, "mdi:flash"], + "voltage_3": ["voltage_3", UNIT_VOLT, "mdi:flash"], } PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( diff --git a/homeassistant/components/greeneye_monitor/sensor.py b/homeassistant/components/greeneye_monitor/sensor.py index ff5aff6fe500e..18d564765d1e3 100644 --- a/homeassistant/components/greeneye_monitor/sensor.py +++ b/homeassistant/components/greeneye_monitor/sensor.py @@ -8,6 +8,7 @@ TIME_HOURS, TIME_MINUTES, TIME_SECONDS, + UNIT_VOLT, ) from homeassistant.helpers.entity import Entity @@ -310,4 +311,4 @@ def state(self): @property def unit_of_measurement(self): """Return the unit of measurement for this sensor.""" - return "V" + return UNIT_VOLT diff --git a/homeassistant/components/growatt_server/sensor.py b/homeassistant/components/growatt_server/sensor.py index b7cea620a6628..6742b39e8b019 100644 --- a/homeassistant/components/growatt_server/sensor.py +++ b/homeassistant/components/growatt_server/sensor.py @@ -13,6 +13,7 @@ CONF_PASSWORD, CONF_USERNAME, ENERGY_KILO_WATT_HOUR, + UNIT_VOLT, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -57,17 +58,17 @@ "e_total", "power", ), - "inverter_voltage_input_1": ("Input 1 voltage", "V", "vpv1", None), + "inverter_voltage_input_1": ("Input 1 voltage", UNIT_VOLT, "vpv1", None), "inverter_amperage_input_1": ("Input 1 Amperage", "A", "ipv1", None), "inverter_wattage_input_1": ("Input 1 Wattage", "W", "ppv1", "power"), - "inverter_voltage_input_2": ("Input 2 voltage", "V", "vpv2", None), + "inverter_voltage_input_2": ("Input 2 voltage", UNIT_VOLT, "vpv2", None), "inverter_amperage_input_2": ("Input 2 Amperage", "A", "ipv2", None), "inverter_wattage_input_2": ("Input 2 Wattage", "W", "ppv2", "power"), - "inverter_voltage_input_3": ("Input 3 voltage", "V", "vpv3", None), + "inverter_voltage_input_3": ("Input 3 voltage", UNIT_VOLT, "vpv3", None), "inverter_amperage_input_3": ("Input 3 Amperage", "A", "ipv3", None), "inverter_wattage_input_3": ("Input 3 Wattage", "W", "ppv3", "power"), "inverter_internal_wattage": ("Internal wattage", "W", "ppv", "power"), - "inverter_reactive_voltage": ("Reactive voltage", "V", "vacr", None), + "inverter_reactive_voltage": ("Reactive voltage", UNIT_VOLT, "vacr", None), "inverter_inverter_reactive_amperage": ("Reactive amperage", "A", "iacr", None), "inverter_frequency": ("AC frequency", "Hz", "fac", None), "inverter_current_wattage": ("Output power", "W", "pac", "power"), diff --git a/homeassistant/components/homematic/sensor.py b/homeassistant/components/homematic/sensor.py index c0a269bd58288..d36b05fd129e8 100644 --- a/homeassistant/components/homematic/sensor.py +++ b/homeassistant/components/homematic/sensor.py @@ -11,6 +11,7 @@ SPEED_KILOMETERS_PER_HOUR, TEMP_CELSIUS, UNIT_PERCENTAGE, + UNIT_VOLT, VOLUME_CUBIC_METERS, ) @@ -40,7 +41,7 @@ "BRIGHTNESS": "#", "POWER": POWER_WATT, "CURRENT": "mA", - "VOLTAGE": "V", + "VOLTAGE": UNIT_VOLT, "ENERGY_COUNTER": ENERGY_WATT_HOUR, "GAS_POWER": VOLUME_CUBIC_METERS, "GAS_ENERGY_COUNTER": VOLUME_CUBIC_METERS, diff --git a/homeassistant/components/isy994/sensor.py b/homeassistant/components/isy994/sensor.py index 9e2f3e90957a3..a21b484ec9b65 100644 --- a/homeassistant/components/isy994/sensor.py +++ b/homeassistant/components/isy994/sensor.py @@ -20,6 +20,7 @@ TIME_YEARS, UNIT_PERCENTAGE, UNIT_UV_INDEX, + UNIT_VOLT, ) from homeassistant.helpers.typing import ConfigType @@ -91,7 +92,7 @@ "65": "SML", "69": "gal", "71": UNIT_UV_INDEX, - "72": "V", + "72": UNIT_VOLT, "73": POWER_WATT, "74": "W/m²", "75": "weekday", diff --git a/homeassistant/components/juicenet/sensor.py b/homeassistant/components/juicenet/sensor.py index 6ddb8279811e1..93eec19d41b02 100644 --- a/homeassistant/components/juicenet/sensor.py +++ b/homeassistant/components/juicenet/sensor.py @@ -1,7 +1,13 @@ """Support for monitoring juicenet/juicepoint/juicebox based EVSE sensors.""" import logging -from homeassistant.const import ENERGY_WATT_HOUR, POWER_WATT, TEMP_CELSIUS, TIME_SECONDS +from homeassistant.const import ( + ENERGY_WATT_HOUR, + POWER_WATT, + TEMP_CELSIUS, + TIME_SECONDS, + UNIT_VOLT, +) from homeassistant.helpers.entity import Entity from . import DOMAIN, JuicenetDevice @@ -11,7 +17,7 @@ SENSOR_TYPES = { "status": ["Charging Status", None], "temperature": ["Temperature", TEMP_CELSIUS], - "voltage": ["Voltage", "V"], + "voltage": ["Voltage", UNIT_VOLT], "amps": ["Amps", "A"], "watts": ["Watts", POWER_WATT], "charge_time": ["Charge time", TIME_SECONDS], diff --git a/homeassistant/components/lcn/const.py b/homeassistant/components/lcn/const.py index 0a46190fbf931..7a881ab9d8565 100644 --- a/homeassistant/components/lcn/const.py +++ b/homeassistant/components/lcn/const.py @@ -1,7 +1,12 @@ """Constants for the LCN component.""" from itertools import product -from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, UNIT_PERCENTAGE +from homeassistant.const import ( + TEMP_CELSIUS, + TEMP_FAHRENHEIT, + UNIT_PERCENTAGE, + UNIT_VOLT, +) DOMAIN = "lcn" DATA_LCN = "lcn" @@ -157,7 +162,7 @@ "PERCENT", "PPM", "VOLT", - "V", + UNIT_VOLT, "AMPERE", "AMP", "A", diff --git a/homeassistant/components/mysensors/sensor.py b/homeassistant/components/mysensors/sensor.py index 997728ed49523..16c8d37f4477a 100644 --- a/homeassistant/components/mysensors/sensor.py +++ b/homeassistant/components/mysensors/sensor.py @@ -8,6 +8,7 @@ TEMP_CELSIUS, TEMP_FAHRENHEIT, UNIT_PERCENTAGE, + UNIT_VOLT, ) SENSORS = { @@ -35,7 +36,7 @@ "S_VIBRATION": ["Hz", None], "S_LIGHT_LEVEL": ["lx", "mdi:white-balance-sunny"], }, - "V_VOLTAGE": ["V", "mdi:flash"], + "V_VOLTAGE": [UNIT_VOLT, "mdi:flash"], "V_CURRENT": ["A", "mdi:flash-auto"], "V_PH": ["pH", None], "V_ORP": ["mV", None], diff --git a/homeassistant/components/nut/const.py b/homeassistant/components/nut/const.py index ae960cc432556..93b11309f90a9 100644 --- a/homeassistant/components/nut/const.py +++ b/homeassistant/components/nut/const.py @@ -4,7 +4,13 @@ DEVICE_CLASS_POWER, DEVICE_CLASS_TEMPERATURE, ) -from homeassistant.const import POWER_WATT, TEMP_CELSIUS, TIME_SECONDS, UNIT_PERCENTAGE +from homeassistant.const import ( + POWER_WATT, + TEMP_CELSIUS, + TIME_SECONDS, + UNIT_PERCENTAGE, + UNIT_VOLT, +) DOMAIN = "nut" @@ -93,10 +99,15 @@ None, ], "battery.charger.status": ["Charging Status", "", "mdi:information-outline", None], - "battery.voltage": ["Battery Voltage", "V", "mdi:flash", None], - "battery.voltage.nominal": ["Nominal Battery Voltage", "V", "mdi:flash", None], - "battery.voltage.low": ["Low Battery Voltage", "V", "mdi:flash", None], - "battery.voltage.high": ["High Battery Voltage", "V", "mdi:flash", None], + "battery.voltage": ["Battery Voltage", UNIT_VOLT, "mdi:flash", None], + "battery.voltage.nominal": [ + "Nominal Battery Voltage", + UNIT_VOLT, + "mdi:flash", + None, + ], + "battery.voltage.low": ["Low Battery Voltage", UNIT_VOLT, "mdi:flash", None], + "battery.voltage.high": ["High Battery Voltage", UNIT_VOLT, "mdi:flash", None], "battery.capacity": ["Battery Capacity", "Ah", "mdi:flash", None], "battery.current": ["Battery Current", "A", "mdi:flash", None], "battery.current.total": ["Total Battery Current", "A", "mdi:flash", None], @@ -136,16 +147,16 @@ "mdi:information-outline", None, ], - "input.transfer.low": ["Low Voltage Transfer", "V", "mdi:flash", None], - "input.transfer.high": ["High Voltage Transfer", "V", "mdi:flash", None], + "input.transfer.low": ["Low Voltage Transfer", UNIT_VOLT, "mdi:flash", None], + "input.transfer.high": ["High Voltage Transfer", UNIT_VOLT, "mdi:flash", None], "input.transfer.reason": [ "Voltage Transfer Reason", "", "mdi:information-outline", None, ], - "input.voltage": ["Input Voltage", "V", "mdi:flash", None], - "input.voltage.nominal": ["Nominal Input Voltage", "V", "mdi:flash", None], + "input.voltage": ["Input Voltage", UNIT_VOLT, "mdi:flash", None], + "input.voltage.nominal": ["Nominal Input Voltage", UNIT_VOLT, "mdi:flash", None], "input.frequency": ["Input Line Frequency", "hz", "mdi:flash", None], "input.frequency.nominal": [ "Nominal Input Line Frequency", @@ -161,8 +172,8 @@ ], "output.current": ["Output Current", "A", "mdi:flash", None], "output.current.nominal": ["Nominal Output Current", "A", "mdi:flash", None], - "output.voltage": ["Output Voltage", "V", "mdi:flash", None], - "output.voltage.nominal": ["Nominal Output Voltage", "V", "mdi:flash", None], + "output.voltage": ["Output Voltage", UNIT_VOLT, "mdi:flash", None], + "output.voltage.nominal": ["Nominal Output Voltage", UNIT_VOLT, "mdi:flash", None], "output.frequency": ["Output Frequency", "hz", "mdi:flash", None], "output.frequency.nominal": ["Nominal Output Frequency", "hz", "mdi:flash", None], } diff --git a/homeassistant/components/onewire/sensor.py b/homeassistant/components/onewire/sensor.py index 90d943dd755fa..d38c115c9d4ce 100644 --- a/homeassistant/components/onewire/sensor.py +++ b/homeassistant/components/onewire/sensor.py @@ -8,7 +8,13 @@ import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import CONF_HOST, CONF_PORT, TEMP_CELSIUS, UNIT_PERCENTAGE +from homeassistant.const import ( + CONF_HOST, + CONF_PORT, + TEMP_CELSIUS, + UNIT_PERCENTAGE, + UNIT_VOLT, +) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -75,9 +81,9 @@ "counter_a": ["counter", "count"], "counter_b": ["counter", "count"], "HobbyBoard": ["none", "none"], - "voltage": ["voltage", "V"], - "voltage_VAD": ["voltage", "V"], - "voltage_VDD": ["voltage", "V"], + "voltage": ["voltage", UNIT_VOLT], + "voltage_VAD": ["voltage", UNIT_VOLT], + "voltage_VDD": ["voltage", UNIT_VOLT], "current": ["current", "A"], } diff --git a/homeassistant/components/smappee/sensor.py b/homeassistant/components/smappee/sensor.py index 8f1e034dcacb1..324b4ea10e2d4 100644 --- a/homeassistant/components/smappee/sensor.py +++ b/homeassistant/components/smappee/sensor.py @@ -7,6 +7,7 @@ POWER_WATT, UNIT_PERCENTAGE, VOLUME_CUBIC_METERS, + UNIT_VOLT, ) from homeassistant.helpers.entity import Entity @@ -25,7 +26,7 @@ "active_power", ], "current": ["Current", "mdi:gauge", "local", "A", "current"], - "voltage": ["Voltage", "mdi:gauge", "local", "V", "voltage"], + "voltage": ["Voltage", "mdi:gauge", "local", UNIT_VOLT, "voltage"], "active_cosfi": [ "Power Factor", "mdi:gauge", diff --git a/homeassistant/components/smartthings/sensor.py b/homeassistant/components/smartthings/sensor.py index 630fbaadd3a47..da581bb969ef7 100644 --- a/homeassistant/components/smartthings/sensor.py +++ b/homeassistant/components/smartthings/sensor.py @@ -17,6 +17,7 @@ TEMP_CELSIUS, TEMP_FAHRENHEIT, UNIT_PERCENTAGE, + UNIT_VOLT, ) from . import SmartThingsEntity @@ -233,7 +234,7 @@ Map(Attribute.ultraviolet_index, "Ultraviolet Index", None, None) ], Capability.voltage_measurement: [ - Map(Attribute.voltage, "Voltage Measurement", "V", None) + Map(Attribute.voltage, "Voltage Measurement", UNIT_VOLT, None) ], Capability.washer_mode: [Map(Attribute.washer_mode, "Washer Mode", None, None)], Capability.washer_operating_state: [ diff --git a/homeassistant/components/solaredge_local/sensor.py b/homeassistant/components/solaredge_local/sensor.py index ecf9dfde8b15f..8d1b7262fc080 100644 --- a/homeassistant/components/solaredge_local/sensor.py +++ b/homeassistant/components/solaredge_local/sensor.py @@ -16,6 +16,7 @@ POWER_WATT, TEMP_CELSIUS, TEMP_FAHRENHEIT, + UNIT_VOLT, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -40,8 +41,20 @@ # Supported sensor types: # Key: ['json_key', 'name', unit, icon, attribute name] SENSOR_TYPES = { - "current_AC_voltage": ["gridvoltage", "Grid Voltage", "V", "mdi:current-ac", None], - "current_DC_voltage": ["dcvoltage", "DC Voltage", "V", "mdi:current-dc", None], + "current_AC_voltage": [ + "gridvoltage", + "Grid Voltage", + UNIT_VOLT, + "mdi:current-ac", + None, + ], + "current_DC_voltage": [ + "dcvoltage", + "DC Voltage", + UNIT_VOLT, + "mdi:current-dc", + None, + ], "current_frequency": [ "gridfrequency", "Grid Frequency", @@ -122,7 +135,7 @@ "optimizer_voltage": [ "optimizervoltage", "Average Optimizer Voltage", - "V", + UNIT_VOLT, "mdi:solar-panel", None, ], diff --git a/homeassistant/components/solarlog/const.py b/homeassistant/components/solarlog/const.py index 26176e97e46cf..b8512531f36ad 100644 --- a/homeassistant/components/solarlog/const.py +++ b/homeassistant/components/solarlog/const.py @@ -1,7 +1,12 @@ """Constants for the Solar-Log integration.""" from datetime import timedelta -from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT, UNIT_PERCENTAGE +from homeassistant.const import ( + ENERGY_KILO_WATT_HOUR, + POWER_WATT, + UNIT_PERCENTAGE, + UNIT_VOLT, +) DOMAIN = "solarlog" @@ -17,8 +22,8 @@ "time": ["TIME", "last update", None, "mdi:calendar-clock"], "power_ac": ["powerAC", "power AC", POWER_WATT, "mdi:solar-power"], "power_dc": ["powerDC", "power DC", POWER_WATT, "mdi:solar-power"], - "voltage_ac": ["voltageAC", "voltage AC", "V", "mdi:flash"], - "voltage_dc": ["voltageDC", "voltage DC", "V", "mdi:flash"], + "voltage_ac": ["voltageAC", "voltage AC", UNIT_VOLT, "mdi:flash"], + "voltage_dc": ["voltageDC", "voltage DC", UNIT_VOLT, "mdi:flash"], "yield_day": ["yieldDAY", "yield day", ENERGY_KILO_WATT_HOUR, "mdi:solar-power"], "yield_yesterday": [ "yieldYESTERDAY", diff --git a/homeassistant/components/starline/sensor.py b/homeassistant/components/starline/sensor.py index 8e17caad86ce2..09642e6647943 100644 --- a/homeassistant/components/starline/sensor.py +++ b/homeassistant/components/starline/sensor.py @@ -1,6 +1,6 @@ """Reads vehicle status from StarLine API.""" from homeassistant.components.sensor import DEVICE_CLASS_TEMPERATURE -from homeassistant.const import TEMP_CELSIUS, UNIT_PERCENTAGE +from homeassistant.const import TEMP_CELSIUS, UNIT_PERCENTAGE, UNIT_VOLT from homeassistant.helpers.entity import Entity from homeassistant.helpers.icon import icon_for_battery_level, icon_for_signal_level @@ -9,7 +9,7 @@ from .entity import StarlineEntity SENSOR_TYPES = { - "battery": ["Battery", None, "V", None], + "battery": ["Battery", None, UNIT_VOLT, None], "balance": ["Balance", None, None, "mdi:cash-multiple"], "ctemp": ["Interior Temperature", DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None], "etemp": ["Engine Temperature", DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None], diff --git a/homeassistant/components/ted5000/sensor.py b/homeassistant/components/ted5000/sensor.py index 2e6246d06ddbf..3982c7f0d0466 100644 --- a/homeassistant/components/ted5000/sensor.py +++ b/homeassistant/components/ted5000/sensor.py @@ -7,7 +7,7 @@ import xmltodict from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, POWER_WATT +from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, POWER_WATT, UNIT_VOLT from homeassistant.helpers import config_validation as cv from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle @@ -43,7 +43,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): dev = [] for mtu in gateway.data: dev.append(Ted5000Sensor(gateway, name, mtu, POWER_WATT)) - dev.append(Ted5000Sensor(gateway, name, mtu, "V")) + dev.append(Ted5000Sensor(gateway, name, mtu, UNIT_VOLT)) add_entities(dev) return True @@ -54,7 +54,7 @@ class Ted5000Sensor(Entity): def __init__(self, gateway, name, mtu, unit): """Initialize the sensor.""" - units = {POWER_WATT: "power", "V": "voltage"} + units = {POWER_WATT: "power", UNIT_VOLT: "voltage"} self._gateway = gateway self._name = "{} mtu{} {}".format(name, mtu, units[unit]) self._mtu = mtu @@ -108,4 +108,4 @@ def update(self): power = int(doc["LiveData"]["Power"]["MTU%d" % mtu]["PowerNow"]) voltage = int(doc["LiveData"]["Voltage"]["MTU%d" % mtu]["VoltageNow"]) - self.data[mtu] = {POWER_WATT: power, "V": voltage / 10} + self.data[mtu] = {POWER_WATT: power, UNIT_VOLT: voltage / 10} diff --git a/homeassistant/components/wirelesstag/__init__.py b/homeassistant/components/wirelesstag/__init__.py index 7296179a126f4..335b24b855745 100644 --- a/homeassistant/components/wirelesstag/__init__.py +++ b/homeassistant/components/wirelesstag/__init__.py @@ -12,6 +12,7 @@ CONF_PASSWORD, CONF_USERNAME, UNIT_PERCENTAGE, + UNIT_VOLT, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import dispatcher_send @@ -280,7 +281,7 @@ def device_state_attributes(self): """Return the state attributes.""" return { ATTR_BATTERY_LEVEL: int(self._tag.battery_remaining * 100), - ATTR_VOLTAGE: f"{self._tag.battery_volts:.2f}V", + ATTR_VOLTAGE: f"{self._tag.battery_volts:.2f}{UNIT_VOLT}", ATTR_TAG_SIGNAL_STRENGTH: f"{self._tag.signal_strength}dBm", ATTR_TAG_OUT_OF_RANGE: not self._tag.is_in_range, ATTR_TAG_POWER_CONSUMPTION: f"{self._tag.power_consumption:.2f}{UNIT_PERCENTAGE}", diff --git a/homeassistant/const.py b/homeassistant/const.py index 42b944e9fb3e5..d69f0370720a6 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -345,6 +345,9 @@ # Power units POWER_WATT = "W" +# Voltage units +UNIT_VOLT = "V" + # Energy units ENERGY_KILO_WATT_HOUR = "kWh" ENERGY_WATT_HOUR = "Wh" diff --git a/tests/components/sma/test_sensor.py b/tests/components/sma/test_sensor.py index 3caf889c52226..73d6dff677310 100644 --- a/tests/components/sma/test_sensor.py +++ b/tests/components/sma/test_sensor.py @@ -1,6 +1,7 @@ """SMA sensor tests.""" import logging +from homeassistant.const import UNIT_VOLT from homeassistant.components.sensor import DOMAIN from homeassistant.setup import async_setup_component @@ -11,7 +12,7 @@ "platform": "sma", "host": "1.1.1.1", "password": "", - "custom": {"my_sensor": {"key": "1234567890123", "unit": "V"}}, + "custom": {"my_sensor": {"key": "1234567890123", "unit": UNIT_VOLT}}, } From 50a9e2bc35ba33ea5ca002e8cc0388b7ac6e0cb5 Mon Sep 17 00:00:00 2001 From: springstan Date: Sat, 11 Apr 2020 00:28:55 +0200 Subject: [PATCH 2/2] Run isort --- homeassistant/components/dsmr_reader/definitions.py | 2 +- homeassistant/components/elkm1/sensor.py | 1 + homeassistant/components/smappee/sensor.py | 2 +- tests/components/sma/test_sensor.py | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/dsmr_reader/definitions.py b/homeassistant/components/dsmr_reader/definitions.py index eb218fede6666..87e6d6ff87290 100644 --- a/homeassistant/components/dsmr_reader/definitions.py +++ b/homeassistant/components/dsmr_reader/definitions.py @@ -1,6 +1,6 @@ """Definitions for DSMR Reader sensors added to MQTT.""" -from homeassistant.const import ENERGY_KILO_WATT_HOUR, VOLUME_CUBIC_METERS, UNIT_VOLT +from homeassistant.const import ENERGY_KILO_WATT_HOUR, UNIT_VOLT, VOLUME_CUBIC_METERS def dsmr_transform(value): diff --git a/homeassistant/components/elkm1/sensor.py b/homeassistant/components/elkm1/sensor.py index 89e39407a8cb3..0c7a454990de2 100644 --- a/homeassistant/components/elkm1/sensor.py +++ b/homeassistant/components/elkm1/sensor.py @@ -8,6 +8,7 @@ from elkm1_lib.util import pretty_const, username from homeassistant.const import UNIT_VOLT + from . import ElkAttachedEntity, create_elk_entities from .const import DOMAIN diff --git a/homeassistant/components/smappee/sensor.py b/homeassistant/components/smappee/sensor.py index 324b4ea10e2d4..5948f7e42231f 100644 --- a/homeassistant/components/smappee/sensor.py +++ b/homeassistant/components/smappee/sensor.py @@ -6,8 +6,8 @@ ENERGY_KILO_WATT_HOUR, POWER_WATT, UNIT_PERCENTAGE, - VOLUME_CUBIC_METERS, UNIT_VOLT, + VOLUME_CUBIC_METERS, ) from homeassistant.helpers.entity import Entity diff --git a/tests/components/sma/test_sensor.py b/tests/components/sma/test_sensor.py index 73d6dff677310..2556a0d2e768a 100644 --- a/tests/components/sma/test_sensor.py +++ b/tests/components/sma/test_sensor.py @@ -1,8 +1,8 @@ """SMA sensor tests.""" import logging -from homeassistant.const import UNIT_VOLT from homeassistant.components.sensor import DOMAIN +from homeassistant.const import UNIT_VOLT from homeassistant.setup import async_setup_component from tests.common import assert_setup_component