Add and use UNIT_VOLT constant (#33994)

* Add and use UNIT_VOLT constant

* Run isort
This commit is contained in:
springstan 2020-04-11 02:04:58 +02:00 committed by GitHub
parent 32e87fc4c7
commit 04c4501455
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 125 additions and 64 deletions

View File

@ -12,6 +12,7 @@ from homeassistant.const import (
TIME_MINUTES, TIME_MINUTES,
TIME_SECONDS, TIME_SECONDS,
UNIT_PERCENTAGE, UNIT_PERCENTAGE,
UNIT_VOLT,
) )
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -29,7 +30,7 @@ SENSOR_TYPES = {
"badbatts": ["Bad Batteries", "", "mdi:information-outline"], "badbatts": ["Bad Batteries", "", "mdi:information-outline"],
"battdate": ["Battery Replaced", "", "mdi:calendar-clock"], "battdate": ["Battery Replaced", "", "mdi:calendar-clock"],
"battstat": ["Battery Status", "", "mdi:information-outline"], "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"], "bcharge": ["Battery", UNIT_PERCENTAGE, "mdi:battery"],
"cable": ["Cable Type", "", "mdi:ethernet-cable"], "cable": ["Cable Type", "", "mdi:ethernet-cable"],
"cumonbatt": ["Total Time on Battery", "", "mdi:timer"], "cumonbatt": ["Total Time on Battery", "", "mdi:timer"],
@ -42,33 +43,33 @@ SENSOR_TYPES = {
"endapc": ["Date and Time", "", "mdi:calendar-clock"], "endapc": ["Date and Time", "", "mdi:calendar-clock"],
"extbatts": ["External Batteries", "", "mdi:information-outline"], "extbatts": ["External Batteries", "", "mdi:information-outline"],
"firmware": ["Firmware Version", "", "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"], "hostname": ["Hostname", "", "mdi:information-outline"],
"humidity": ["Ambient Humidity", UNIT_PERCENTAGE, "mdi:water-percent"], "humidity": ["Ambient Humidity", UNIT_PERCENTAGE, "mdi:water-percent"],
"itemp": ["Internal Temperature", TEMP_CELSIUS, "mdi:thermometer"], "itemp": ["Internal Temperature", TEMP_CELSIUS, "mdi:thermometer"],
"lastxfer": ["Last Transfer", "", "mdi:transfer"], "lastxfer": ["Last Transfer", "", "mdi:transfer"],
"linefail": ["Input Voltage Status", "", "mdi:information-outline"], "linefail": ["Input Voltage Status", "", "mdi:information-outline"],
"linefreq": ["Line Frequency", "Hz", "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"], "loadpct": ["Load", UNIT_PERCENTAGE, "mdi:gauge"],
"loadapnt": ["Load Apparent Power", 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"], "mandate": ["Manufacture Date", "", "mdi:calendar"],
"masterupd": ["Master Update", "", "mdi:information-outline"], "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"], "maxtime": ["Battery Timeout", "", "mdi:timer-off"],
"mbattchg": ["Battery Shutdown", UNIT_PERCENTAGE, "mdi:battery-alert"], "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"], "mintimel": ["Shutdown Time", "", "mdi:timer"],
"model": ["Model", "", "mdi:information-outline"], "model": ["Model", "", "mdi:information-outline"],
"nombattv": ["Battery Nominal Voltage", "V", "mdi:flash"], "nombattv": ["Battery Nominal Voltage", UNIT_VOLT, "mdi:flash"],
"nominv": ["Nominal Input Voltage", "V", "mdi:flash"], "nominv": ["Nominal Input Voltage", UNIT_VOLT, "mdi:flash"],
"nomoutv": ["Nominal Output Voltage", "V", "mdi:flash"], "nomoutv": ["Nominal Output Voltage", UNIT_VOLT, "mdi:flash"],
"nompower": ["Nominal Output Power", POWER_WATT, "mdi:flash"], "nompower": ["Nominal Output Power", POWER_WATT, "mdi:flash"],
"nomapnt": ["Nominal Apparent Power", "VA", "mdi:flash"], "nomapnt": ["Nominal Apparent Power", "VA", "mdi:flash"],
"numxfers": ["Transfer Count", "", "mdi:counter"], "numxfers": ["Transfer Count", "", "mdi:counter"],
"outcurnt": ["Output Current", "A", "mdi:flash"], "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"], "reg1": ["Register 1 Fault", "", "mdi:information-outline"],
"reg2": ["Register 2 Fault", "", "mdi:information-outline"], "reg2": ["Register 2 Fault", "", "mdi:information-outline"],
"reg3": ["Register 3 Fault", "", "mdi:information-outline"], "reg3": ["Register 3 Fault", "", "mdi:information-outline"],
@ -95,7 +96,7 @@ INFERRED_UNITS = {
" Minutes": TIME_MINUTES, " Minutes": TIME_MINUTES,
" Seconds": TIME_SECONDS, " Seconds": TIME_SECONDS,
" Percent": UNIT_PERCENTAGE, " Percent": UNIT_PERCENTAGE,
" Volts": "V", " Volts": UNIT_VOLT,
" Ampere": "A", " Ampere": "A",
" Volt-Ampere": "VA", " Volt-Ampere": "VA",
" Watts": POWER_WATT, " Watts": POWER_WATT,

View File

@ -1,6 +1,6 @@
"""Definitions for DSMR Reader sensors added to MQTT.""" """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, UNIT_VOLT, VOLUME_CUBIC_METERS
def dsmr_transform(value): def dsmr_transform(value):
@ -86,17 +86,17 @@ DEFINITIONS = {
"dsmr/reading/phase_voltage_l1": { "dsmr/reading/phase_voltage_l1": {
"name": "Current voltage L1", "name": "Current voltage L1",
"icon": "mdi:flash", "icon": "mdi:flash",
"unit": "V", "unit": UNIT_VOLT,
}, },
"dsmr/reading/phase_voltage_l2": { "dsmr/reading/phase_voltage_l2": {
"name": "Current voltage L2", "name": "Current voltage L2",
"icon": "mdi:flash", "icon": "mdi:flash",
"unit": "V", "unit": UNIT_VOLT,
}, },
"dsmr/reading/phase_voltage_l3": { "dsmr/reading/phase_voltage_l3": {
"name": "Current voltage L3", "name": "Current voltage L3",
"icon": "mdi:flash", "icon": "mdi:flash",
"unit": "V", "unit": UNIT_VOLT,
}, },
"dsmr/consumption/gas/delivered": { "dsmr/consumption/gas/delivered": {
"name": "Gas usage", "name": "Gas usage",

View File

@ -7,6 +7,8 @@ from elkm1_lib.const import (
) )
from elkm1_lib.util import pretty_const, username from elkm1_lib.util import pretty_const, username
from homeassistant.const import UNIT_VOLT
from . import ElkAttachedEntity, create_elk_entities from . import ElkAttachedEntity, create_elk_entities
from .const import DOMAIN from .const import DOMAIN
@ -195,7 +197,7 @@ class ElkZone(ElkSensor):
if self._element.definition == ZoneType.TEMPERATURE.value: if self._element.definition == ZoneType.TEMPERATURE.value:
return self._temperature_unit return self._temperature_unit
if self._element.definition == ZoneType.ANALOG_ZONE.value: if self._element.definition == ZoneType.ANALOG_ZONE.value:
return "V" return UNIT_VOLT
return None return None
def _element_changed(self, element, changeset): def _element_changed(self, element, changeset):

View File

@ -6,7 +6,7 @@ import logging
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA 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 import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle from homeassistant.util import Throttle
@ -31,10 +31,10 @@ SENSOR_TYPES = {
"magnetometer_z": ["magnetometer_z", " ", "mdi:magnet"], "magnetometer_z": ["magnetometer_z", " ", "mdi:magnet"],
"temperature": ["temperature", TEMP_CELSIUS, "mdi:thermometer"], "temperature": ["temperature", TEMP_CELSIUS, "mdi:thermometer"],
"pressure": ["pressure", "hPa", "mdi:gauge"], "pressure": ["pressure", "hPa", "mdi:gauge"],
"voltage_0": ["voltage_0", "V", "mdi:flash"], "voltage_0": ["voltage_0", UNIT_VOLT, "mdi:flash"],
"voltage_1": ["voltage_1", "V", "mdi:flash"], "voltage_1": ["voltage_1", UNIT_VOLT, "mdi:flash"],
"voltage_2": ["voltage_2", "V", "mdi:flash"], "voltage_2": ["voltage_2", UNIT_VOLT, "mdi:flash"],
"voltage_3": ["voltage_3", "V", "mdi:flash"], "voltage_3": ["voltage_3", UNIT_VOLT, "mdi:flash"],
} }
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(

View File

@ -8,6 +8,7 @@ from homeassistant.const import (
TIME_HOURS, TIME_HOURS,
TIME_MINUTES, TIME_MINUTES,
TIME_SECONDS, TIME_SECONDS,
UNIT_VOLT,
) )
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -310,4 +311,4 @@ class VoltageSensor(GEMSensor):
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Return the unit of measurement for this sensor.""" """Return the unit of measurement for this sensor."""
return "V" return UNIT_VOLT

View File

@ -13,6 +13,7 @@ from homeassistant.const import (
CONF_PASSWORD, CONF_PASSWORD,
CONF_USERNAME, CONF_USERNAME,
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
UNIT_VOLT,
) )
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -57,17 +58,17 @@ INVERTER_SENSOR_TYPES = {
"e_total", "e_total",
"power", "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_amperage_input_1": ("Input 1 Amperage", "A", "ipv1", None),
"inverter_wattage_input_1": ("Input 1 Wattage", "W", "ppv1", "power"), "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_amperage_input_2": ("Input 2 Amperage", "A", "ipv2", None),
"inverter_wattage_input_2": ("Input 2 Wattage", "W", "ppv2", "power"), "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_amperage_input_3": ("Input 3 Amperage", "A", "ipv3", None),
"inverter_wattage_input_3": ("Input 3 Wattage", "W", "ppv3", "power"), "inverter_wattage_input_3": ("Input 3 Wattage", "W", "ppv3", "power"),
"inverter_internal_wattage": ("Internal wattage", "W", "ppv", "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_inverter_reactive_amperage": ("Reactive amperage", "A", "iacr", None),
"inverter_frequency": ("AC frequency", "Hz", "fac", None), "inverter_frequency": ("AC frequency", "Hz", "fac", None),
"inverter_current_wattage": ("Output power", "W", "pac", "power"), "inverter_current_wattage": ("Output power", "W", "pac", "power"),

View File

@ -11,6 +11,7 @@ from homeassistant.const import (
SPEED_KILOMETERS_PER_HOUR, SPEED_KILOMETERS_PER_HOUR,
TEMP_CELSIUS, TEMP_CELSIUS,
UNIT_PERCENTAGE, UNIT_PERCENTAGE,
UNIT_VOLT,
VOLUME_CUBIC_METERS, VOLUME_CUBIC_METERS,
) )
@ -40,7 +41,7 @@ HM_UNIT_HA_CAST = {
"BRIGHTNESS": "#", "BRIGHTNESS": "#",
"POWER": POWER_WATT, "POWER": POWER_WATT,
"CURRENT": "mA", "CURRENT": "mA",
"VOLTAGE": "V", "VOLTAGE": UNIT_VOLT,
"ENERGY_COUNTER": ENERGY_WATT_HOUR, "ENERGY_COUNTER": ENERGY_WATT_HOUR,
"GAS_POWER": VOLUME_CUBIC_METERS, "GAS_POWER": VOLUME_CUBIC_METERS,
"GAS_ENERGY_COUNTER": VOLUME_CUBIC_METERS, "GAS_ENERGY_COUNTER": VOLUME_CUBIC_METERS,

View File

@ -20,6 +20,7 @@ from homeassistant.const import (
TIME_YEARS, TIME_YEARS,
UNIT_PERCENTAGE, UNIT_PERCENTAGE,
UNIT_UV_INDEX, UNIT_UV_INDEX,
UNIT_VOLT,
) )
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
@ -91,7 +92,7 @@ UOM_FRIENDLY_NAME = {
"65": "SML", "65": "SML",
"69": "gal", "69": "gal",
"71": UNIT_UV_INDEX, "71": UNIT_UV_INDEX,
"72": "V", "72": UNIT_VOLT,
"73": POWER_WATT, "73": POWER_WATT,
"74": "W/m²", "74": "W/m²",
"75": "weekday", "75": "weekday",

View File

@ -1,7 +1,13 @@
"""Support for monitoring juicenet/juicepoint/juicebox based EVSE sensors.""" """Support for monitoring juicenet/juicepoint/juicebox based EVSE sensors."""
import logging 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 homeassistant.helpers.entity import Entity
from . import DOMAIN, JuicenetDevice from . import DOMAIN, JuicenetDevice
@ -11,7 +17,7 @@ _LOGGER = logging.getLogger(__name__)
SENSOR_TYPES = { SENSOR_TYPES = {
"status": ["Charging Status", None], "status": ["Charging Status", None],
"temperature": ["Temperature", TEMP_CELSIUS], "temperature": ["Temperature", TEMP_CELSIUS],
"voltage": ["Voltage", "V"], "voltage": ["Voltage", UNIT_VOLT],
"amps": ["Amps", "A"], "amps": ["Amps", "A"],
"watts": ["Watts", POWER_WATT], "watts": ["Watts", POWER_WATT],
"charge_time": ["Charge time", TIME_SECONDS], "charge_time": ["Charge time", TIME_SECONDS],

View File

@ -1,7 +1,12 @@
"""Constants for the LCN component.""" """Constants for the LCN component."""
from itertools import product 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" DOMAIN = "lcn"
DATA_LCN = "lcn" DATA_LCN = "lcn"
@ -157,7 +162,7 @@ VAR_UNITS = [
"PERCENT", "PERCENT",
"PPM", "PPM",
"VOLT", "VOLT",
"V", UNIT_VOLT,
"AMPERE", "AMPERE",
"AMP", "AMP",
"A", "A",

View File

@ -8,6 +8,7 @@ from homeassistant.const import (
TEMP_CELSIUS, TEMP_CELSIUS,
TEMP_FAHRENHEIT, TEMP_FAHRENHEIT,
UNIT_PERCENTAGE, UNIT_PERCENTAGE,
UNIT_VOLT,
) )
SENSORS = { SENSORS = {
@ -35,7 +36,7 @@ SENSORS = {
"S_VIBRATION": ["Hz", None], "S_VIBRATION": ["Hz", None],
"S_LIGHT_LEVEL": ["lx", "mdi:white-balance-sunny"], "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_CURRENT": ["A", "mdi:flash-auto"],
"V_PH": ["pH", None], "V_PH": ["pH", None],
"V_ORP": ["mV", None], "V_ORP": ["mV", None],

View File

@ -4,7 +4,13 @@ from homeassistant.components.sensor import (
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE, 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" DOMAIN = "nut"
@ -94,10 +100,15 @@ SENSOR_TYPES = {
None, None,
], ],
"battery.charger.status": ["Charging Status", "", "mdi:information-outline", None], "battery.charger.status": ["Charging Status", "", "mdi:information-outline", None],
"battery.voltage": ["Battery Voltage", "V", "mdi:flash", None], "battery.voltage": ["Battery Voltage", UNIT_VOLT, "mdi:flash", None],
"battery.voltage.nominal": ["Nominal Battery Voltage", "V", "mdi:flash", None], "battery.voltage.nominal": [
"battery.voltage.low": ["Low Battery Voltage", "V", "mdi:flash", None], "Nominal Battery Voltage",
"battery.voltage.high": ["High Battery Voltage", "V", "mdi:flash", None], 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.capacity": ["Battery Capacity", "Ah", "mdi:flash", None],
"battery.current": ["Battery Current", "A", "mdi:flash", None], "battery.current": ["Battery Current", "A", "mdi:flash", None],
"battery.current.total": ["Total Battery Current", "A", "mdi:flash", None], "battery.current.total": ["Total Battery Current", "A", "mdi:flash", None],
@ -137,16 +148,16 @@ SENSOR_TYPES = {
"mdi:information-outline", "mdi:information-outline",
None, None,
], ],
"input.transfer.low": ["Low Voltage Transfer", "V", "mdi:flash", None], "input.transfer.low": ["Low Voltage Transfer", UNIT_VOLT, "mdi:flash", None],
"input.transfer.high": ["High Voltage Transfer", "V", "mdi:flash", None], "input.transfer.high": ["High Voltage Transfer", UNIT_VOLT, "mdi:flash", None],
"input.transfer.reason": [ "input.transfer.reason": [
"Voltage Transfer Reason", "Voltage Transfer Reason",
"", "",
"mdi:information-outline", "mdi:information-outline",
None, None,
], ],
"input.voltage": ["Input Voltage", "V", "mdi:flash", None], "input.voltage": ["Input Voltage", UNIT_VOLT, "mdi:flash", None],
"input.voltage.nominal": ["Nominal Input Voltage", "V", "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": ["Input Line Frequency", "hz", "mdi:flash", None],
"input.frequency.nominal": [ "input.frequency.nominal": [
"Nominal Input Line Frequency", "Nominal Input Line Frequency",
@ -162,8 +173,8 @@ SENSOR_TYPES = {
], ],
"output.current": ["Output Current", "A", "mdi:flash", None], "output.current": ["Output Current", "A", "mdi:flash", None],
"output.current.nominal": ["Nominal 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": ["Output Voltage", UNIT_VOLT, "mdi:flash", None],
"output.voltage.nominal": ["Nominal Output Voltage", "V", "mdi:flash", None], "output.voltage.nominal": ["Nominal Output Voltage", UNIT_VOLT, "mdi:flash", None],
"output.frequency": ["Output Frequency", "hz", "mdi:flash", None], "output.frequency": ["Output Frequency", "hz", "mdi:flash", None],
"output.frequency.nominal": ["Nominal Output Frequency", "hz", "mdi:flash", None], "output.frequency.nominal": ["Nominal Output Frequency", "hz", "mdi:flash", None],
} }

View File

@ -8,7 +8,13 @@ from pyownet import protocol
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA 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 import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -75,9 +81,9 @@ SENSOR_TYPES = {
"counter_a": ["counter", "count"], "counter_a": ["counter", "count"],
"counter_b": ["counter", "count"], "counter_b": ["counter", "count"],
"HobbyBoard": ["none", "none"], "HobbyBoard": ["none", "none"],
"voltage": ["voltage", "V"], "voltage": ["voltage", UNIT_VOLT],
"voltage_VAD": ["voltage", "V"], "voltage_VAD": ["voltage", UNIT_VOLT],
"voltage_VDD": ["voltage", "V"], "voltage_VDD": ["voltage", UNIT_VOLT],
"current": ["current", "A"], "current": ["current", "A"],
} }

View File

@ -6,6 +6,7 @@ from homeassistant.const import (
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
POWER_WATT, POWER_WATT,
UNIT_PERCENTAGE, UNIT_PERCENTAGE,
UNIT_VOLT,
VOLUME_CUBIC_METERS, VOLUME_CUBIC_METERS,
) )
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -25,7 +26,7 @@ SENSOR_TYPES = {
"active_power", "active_power",
], ],
"current": ["Current", "mdi:gauge", "local", "A", "current"], "current": ["Current", "mdi:gauge", "local", "A", "current"],
"voltage": ["Voltage", "mdi:gauge", "local", "V", "voltage"], "voltage": ["Voltage", "mdi:gauge", "local", UNIT_VOLT, "voltage"],
"active_cosfi": [ "active_cosfi": [
"Power Factor", "Power Factor",
"mdi:gauge", "mdi:gauge",

View File

@ -17,6 +17,7 @@ from homeassistant.const import (
TEMP_CELSIUS, TEMP_CELSIUS,
TEMP_FAHRENHEIT, TEMP_FAHRENHEIT,
UNIT_PERCENTAGE, UNIT_PERCENTAGE,
UNIT_VOLT,
) )
from . import SmartThingsEntity from . import SmartThingsEntity
@ -233,7 +234,7 @@ CAPABILITY_TO_SENSORS = {
Map(Attribute.ultraviolet_index, "Ultraviolet Index", None, None) Map(Attribute.ultraviolet_index, "Ultraviolet Index", None, None)
], ],
Capability.voltage_measurement: [ 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_mode: [Map(Attribute.washer_mode, "Washer Mode", None, None)],
Capability.washer_operating_state: [ Capability.washer_operating_state: [

View File

@ -16,6 +16,7 @@ from homeassistant.const import (
POWER_WATT, POWER_WATT,
TEMP_CELSIUS, TEMP_CELSIUS,
TEMP_FAHRENHEIT, TEMP_FAHRENHEIT,
UNIT_VOLT,
) )
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -40,8 +41,20 @@ INVERTER_MODES = (
# Supported sensor types: # Supported sensor types:
# Key: ['json_key', 'name', unit, icon, attribute name] # Key: ['json_key', 'name', unit, icon, attribute name]
SENSOR_TYPES = { SENSOR_TYPES = {
"current_AC_voltage": ["gridvoltage", "Grid Voltage", "V", "mdi:current-ac", None], "current_AC_voltage": [
"current_DC_voltage": ["dcvoltage", "DC Voltage", "V", "mdi:current-dc", None], "gridvoltage",
"Grid Voltage",
UNIT_VOLT,
"mdi:current-ac",
None,
],
"current_DC_voltage": [
"dcvoltage",
"DC Voltage",
UNIT_VOLT,
"mdi:current-dc",
None,
],
"current_frequency": [ "current_frequency": [
"gridfrequency", "gridfrequency",
"Grid Frequency", "Grid Frequency",
@ -122,7 +135,7 @@ SENSOR_TYPES = {
"optimizer_voltage": [ "optimizer_voltage": [
"optimizervoltage", "optimizervoltage",
"Average Optimizer Voltage", "Average Optimizer Voltage",
"V", UNIT_VOLT,
"mdi:solar-panel", "mdi:solar-panel",
None, None,
], ],

View File

@ -1,7 +1,12 @@
"""Constants for the Solar-Log integration.""" """Constants for the Solar-Log integration."""
from datetime import timedelta 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" DOMAIN = "solarlog"
@ -17,8 +22,8 @@ SENSOR_TYPES = {
"time": ["TIME", "last update", None, "mdi:calendar-clock"], "time": ["TIME", "last update", None, "mdi:calendar-clock"],
"power_ac": ["powerAC", "power AC", POWER_WATT, "mdi:solar-power"], "power_ac": ["powerAC", "power AC", POWER_WATT, "mdi:solar-power"],
"power_dc": ["powerDC", "power DC", POWER_WATT, "mdi:solar-power"], "power_dc": ["powerDC", "power DC", POWER_WATT, "mdi:solar-power"],
"voltage_ac": ["voltageAC", "voltage AC", "V", "mdi:flash"], "voltage_ac": ["voltageAC", "voltage AC", UNIT_VOLT, "mdi:flash"],
"voltage_dc": ["voltageDC", "voltage DC", "V", "mdi:flash"], "voltage_dc": ["voltageDC", "voltage DC", UNIT_VOLT, "mdi:flash"],
"yield_day": ["yieldDAY", "yield day", ENERGY_KILO_WATT_HOUR, "mdi:solar-power"], "yield_day": ["yieldDAY", "yield day", ENERGY_KILO_WATT_HOUR, "mdi:solar-power"],
"yield_yesterday": [ "yield_yesterday": [
"yieldYESTERDAY", "yieldYESTERDAY",

View File

@ -1,6 +1,6 @@
"""Reads vehicle status from StarLine API.""" """Reads vehicle status from StarLine API."""
from homeassistant.components.sensor import DEVICE_CLASS_TEMPERATURE 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.entity import Entity
from homeassistant.helpers.icon import icon_for_battery_level, icon_for_signal_level from homeassistant.helpers.icon import icon_for_battery_level, icon_for_signal_level
@ -9,7 +9,7 @@ from .const import DOMAIN
from .entity import StarlineEntity from .entity import StarlineEntity
SENSOR_TYPES = { SENSOR_TYPES = {
"battery": ["Battery", None, "V", None], "battery": ["Battery", None, UNIT_VOLT, None],
"balance": ["Balance", None, None, "mdi:cash-multiple"], "balance": ["Balance", None, None, "mdi:cash-multiple"],
"ctemp": ["Interior Temperature", DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None], "ctemp": ["Interior Temperature", DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None],
"etemp": ["Engine Temperature", DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None], "etemp": ["Engine Temperature", DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None],

View File

@ -7,7 +7,7 @@ import voluptuous as vol
import xmltodict import xmltodict
from homeassistant.components.sensor import PLATFORM_SCHEMA 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 import config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle from homeassistant.util import Throttle
@ -43,7 +43,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
dev = [] dev = []
for mtu in gateway.data: for mtu in gateway.data:
dev.append(Ted5000Sensor(gateway, name, mtu, POWER_WATT)) 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) add_entities(dev)
return True return True
@ -54,7 +54,7 @@ class Ted5000Sensor(Entity):
def __init__(self, gateway, name, mtu, unit): def __init__(self, gateway, name, mtu, unit):
"""Initialize the sensor.""" """Initialize the sensor."""
units = {POWER_WATT: "power", "V": "voltage"} units = {POWER_WATT: "power", UNIT_VOLT: "voltage"}
self._gateway = gateway self._gateway = gateway
self._name = "{} mtu{} {}".format(name, mtu, units[unit]) self._name = "{} mtu{} {}".format(name, mtu, units[unit])
self._mtu = mtu self._mtu = mtu
@ -108,4 +108,4 @@ class Ted5000Gateway:
power = int(doc["LiveData"]["Power"]["MTU%d" % mtu]["PowerNow"]) power = int(doc["LiveData"]["Power"]["MTU%d" % mtu]["PowerNow"])
voltage = int(doc["LiveData"]["Voltage"]["MTU%d" % mtu]["VoltageNow"]) 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}

View File

@ -12,6 +12,7 @@ from homeassistant.const import (
CONF_PASSWORD, CONF_PASSWORD,
CONF_USERNAME, CONF_USERNAME,
UNIT_PERCENTAGE, UNIT_PERCENTAGE,
UNIT_VOLT,
) )
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import dispatcher_send from homeassistant.helpers.dispatcher import dispatcher_send
@ -280,7 +281,7 @@ class WirelessTagBaseSensor(Entity):
"""Return the state attributes.""" """Return the state attributes."""
return { return {
ATTR_BATTERY_LEVEL: int(self._tag.battery_remaining * 100), 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_SIGNAL_STRENGTH: f"{self._tag.signal_strength}dBm",
ATTR_TAG_OUT_OF_RANGE: not self._tag.is_in_range, ATTR_TAG_OUT_OF_RANGE: not self._tag.is_in_range,
ATTR_TAG_POWER_CONSUMPTION: f"{self._tag.power_consumption:.2f}{UNIT_PERCENTAGE}", ATTR_TAG_POWER_CONSUMPTION: f"{self._tag.power_consumption:.2f}{UNIT_PERCENTAGE}",

View File

@ -345,6 +345,9 @@ ATTR_TEMPERATURE = "temperature"
# Power units # Power units
POWER_WATT = "W" POWER_WATT = "W"
# Voltage units
UNIT_VOLT = "V"
# Energy units # Energy units
ENERGY_KILO_WATT_HOUR = "kWh" ENERGY_KILO_WATT_HOUR = "kWh"
ENERGY_WATT_HOUR = "Wh" ENERGY_WATT_HOUR = "Wh"

View File

@ -2,6 +2,7 @@
import logging import logging
from homeassistant.components.sensor import DOMAIN from homeassistant.components.sensor import DOMAIN
from homeassistant.const import UNIT_VOLT
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import assert_setup_component from tests.common import assert_setup_component
@ -11,7 +12,7 @@ BASE_CFG = {
"platform": "sma", "platform": "sma",
"host": "1.1.1.1", "host": "1.1.1.1",
"password": "", "password": "",
"custom": {"my_sensor": {"key": "1234567890123", "unit": "V"}}, "custom": {"my_sensor": {"key": "1234567890123", "unit": UNIT_VOLT}},
} }