diff --git a/homeassistant/components/apcupsd/sensor.py b/homeassistant/components/apcupsd/sensor.py index 4ebe0ac8aaf..09f9b324bdd 100644 --- a/homeassistant/components/apcupsd/sensor.py +++ b/homeassistant/components/apcupsd/sensor.py @@ -6,7 +6,7 @@ import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA import homeassistant.helpers.config_validation as cv from homeassistant.components import apcupsd -from homeassistant.const import (TEMP_CELSIUS, CONF_RESOURCES) +from homeassistant.const import (TEMP_CELSIUS, CONF_RESOURCES, POWER_WATT) from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) @@ -57,7 +57,7 @@ SENSOR_TYPES = { 'nombattv': ['Battery Nominal Voltage', 'V', 'mdi:flash'], 'nominv': ['Nominal Input Voltage', 'V', 'mdi:flash'], 'nomoutv': ['Nominal Output Voltage', 'V', 'mdi:flash'], - 'nompower': ['Nominal Output Power', 'W', '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'], @@ -93,7 +93,7 @@ INFERRED_UNITS = { ' Volts': 'V', ' Ampere': 'A', ' Volt-Ampere': 'VA', - ' Watts': 'W', + ' Watts': POWER_WATT, ' Hz': 'Hz', ' C': TEMP_CELSIUS, ' Percent Load Capacity': '%', diff --git a/homeassistant/components/edp_redy/sensor.py b/homeassistant/components/edp_redy/sensor.py index 926a073832c..389ae77f35b 100644 --- a/homeassistant/components/edp_redy/sensor.py +++ b/homeassistant/components/edp_redy/sensor.py @@ -2,6 +2,7 @@ import logging from homeassistant.helpers.entity import Entity +from homeassistant.const import POWER_WATT from homeassistant.components.edp_redy import EdpRedyDevice, EDP_REDY @@ -29,7 +30,7 @@ async def async_setup_platform( # Create a sensor for global active power devices.append(EdpRedySensor(session, ACTIVE_POWER_ID, "Power Home", - 'mdi:flash', 'W')) + 'mdi:flash', POWER_WATT)) async_add_entities(devices, True) @@ -89,7 +90,7 @@ class EdpRedyModuleSensor(EdpRedyDevice, Entity): @property def unit_of_measurement(self): """Return the unit of measurement of this sensor.""" - return 'W' + return POWER_WATT async def async_update(self): """Parse the data for this sensor.""" diff --git a/homeassistant/components/enocean/sensor.py b/homeassistant/components/enocean/sensor.py index d2e88ed3825..8d79de2c50d 100644 --- a/homeassistant/components/enocean/sensor.py +++ b/homeassistant/components/enocean/sensor.py @@ -4,7 +4,7 @@ import logging import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import (CONF_NAME, CONF_ID) +from homeassistant.const import (CONF_NAME, CONF_ID, POWER_WATT) from homeassistant.helpers.entity import Entity import homeassistant.helpers.config_validation as cv from homeassistant.components import enocean @@ -59,4 +59,4 @@ class EnOceanSensor(enocean.EnOceanDevice, Entity): @property def unit_of_measurement(self): """Return the unit of measurement.""" - return 'W' + return POWER_WATT diff --git a/homeassistant/components/homematic/sensor.py b/homeassistant/components/homematic/sensor.py index c4d97dca3fe..1bdd2323108 100644 --- a/homeassistant/components/homematic/sensor.py +++ b/homeassistant/components/homematic/sensor.py @@ -2,7 +2,7 @@ import logging from homeassistant.components.homematic import ATTR_DISCOVER_DEVICES, HMDevice -from homeassistant.const import STATE_UNKNOWN +from homeassistant.const import STATE_UNKNOWN, POWER_WATT _LOGGER = logging.getLogger(__name__) @@ -24,7 +24,7 @@ HM_UNIT_HA_CAST = { 'TEMPERATURE': '°C', 'ACTUAL_TEMPERATURE': '°C', 'BRIGHTNESS': '#', - 'POWER': 'W', + 'POWER': POWER_WATT, 'CURRENT': 'mA', 'VOLTAGE': 'V', 'ENERGY_COUNTER': 'Wh', diff --git a/homeassistant/components/homematicip_cloud/sensor.py b/homeassistant/components/homematicip_cloud/sensor.py index d755735e0e0..f1a20e46922 100644 --- a/homeassistant/components/homematicip_cloud/sensor.py +++ b/homeassistant/components/homematicip_cloud/sensor.py @@ -5,7 +5,7 @@ from homeassistant.components.homematicip_cloud import ( DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice) from homeassistant.const import ( DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_TEMPERATURE, - TEMP_CELSIUS) + TEMP_CELSIUS, POWER_WATT) _LOGGER = logging.getLogger(__name__) @@ -223,4 +223,4 @@ class HomematicipPowerSensor(HomematicipGenericDevice): @property def unit_of_measurement(self): """Return the unit this state is expressed in.""" - return 'W' + return POWER_WATT diff --git a/homeassistant/components/isy994/sensor.py b/homeassistant/components/isy994/sensor.py index 60212d081de..2115c19f496 100644 --- a/homeassistant/components/isy994/sensor.py +++ b/homeassistant/components/isy994/sensor.py @@ -5,7 +5,8 @@ from typing import Callable from homeassistant.components.isy994 import ( ISY994_NODES, ISY994_WEATHER, ISYDevice) from homeassistant.components.sensor import DOMAIN -from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, UNIT_UV_INDEX +from homeassistant.const import ( + TEMP_CELSIUS, TEMP_FAHRENHEIT, UNIT_UV_INDEX, POWER_WATT) from homeassistant.helpers.typing import ConfigType _LOGGER = logging.getLogger(__name__) @@ -75,7 +76,7 @@ UOM_FRIENDLY_NAME = { '69': 'gal', '71': UNIT_UV_INDEX, '72': 'V', - '73': 'W', + '73': POWER_WATT, '74': 'W/m²', '75': 'weekday', '76': 'Wind Direction (°)', diff --git a/homeassistant/components/juicenet/sensor.py b/homeassistant/components/juicenet/sensor.py index e3786627075..35cf5628d6f 100644 --- a/homeassistant/components/juicenet/sensor.py +++ b/homeassistant/components/juicenet/sensor.py @@ -1,7 +1,7 @@ """Support for monitoring juicenet/juicepoint/juicebox based EVSE sensors.""" import logging -from homeassistant.const import TEMP_CELSIUS +from homeassistant.const import TEMP_CELSIUS, POWER_WATT from homeassistant.helpers.entity import Entity from homeassistant.components.juicenet import JuicenetDevice, DOMAIN @@ -14,7 +14,7 @@ SENSOR_TYPES = { 'temperature': ['Temperature', TEMP_CELSIUS], 'voltage': ['Voltage', 'V'], 'amps': ['Amps', 'A'], - 'watts': ['Watts', 'W'], + 'watts': ['Watts', POWER_WATT], 'charge_time': ['Charge time', 's'], 'energy_added': ['Energy added', 'Wh'] } diff --git a/homeassistant/components/mysensors/sensor.py b/homeassistant/components/mysensors/sensor.py index ce6d5da2b4c..7aa19e2157c 100644 --- a/homeassistant/components/mysensors/sensor.py +++ b/homeassistant/components/mysensors/sensor.py @@ -1,7 +1,7 @@ """Support for MySensors sensors.""" from homeassistant.components import mysensors from homeassistant.components.sensor import DOMAIN -from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT +from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, POWER_WATT SENSORS = { 'V_TEMP': [None, 'mdi:thermometer'], @@ -12,7 +12,7 @@ SENSORS = { 'V_WEIGHT': ['kg', 'mdi:weight-kilogram'], 'V_DISTANCE': ['m', 'mdi:ruler'], 'V_IMPEDANCE': ['ohm', None], - 'V_WATT': ['W', None], + 'V_WATT': [POWER_WATT, None], 'V_KWH': ['kWh', None], 'V_FLOW': ['m', None], 'V_VOLUME': ['m³', None], diff --git a/homeassistant/components/rfxtrx/__init__.py b/homeassistant/components/rfxtrx/__init__.py index a7b703ef2ab..411f0538bde 100644 --- a/homeassistant/components/rfxtrx/__init__.py +++ b/homeassistant/components/rfxtrx/__init__.py @@ -6,7 +6,8 @@ import voluptuous as vol from homeassistant.const import ( ATTR_ENTITY_ID, ATTR_NAME, ATTR_STATE, CONF_DEVICE, CONF_DEVICES, - EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, TEMP_CELSIUS) + EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, TEMP_CELSIUS, + POWER_WATT) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity from homeassistant.util import slugify @@ -40,8 +41,8 @@ DATA_TYPES = OrderedDict([ ('Barometer', ''), ('Wind direction', ''), ('Rain rate', ''), - ('Energy usage', 'W'), - ('Total usage', 'W'), + ('Energy usage', POWER_WATT), + ('Total usage', POWER_WATT), ('Sound', ''), ('Sensor Status', ''), ('Counter value', ''), diff --git a/homeassistant/components/sense/sensor.py b/homeassistant/components/sense/sensor.py index 2995b860e5b..8fefea03506 100644 --- a/homeassistant/components/sense/sensor.py +++ b/homeassistant/components/sense/sensor.py @@ -3,6 +3,7 @@ from datetime import timedelta import logging from homeassistant.components.sense import SENSE_DATA +from homeassistant.const import POWER_WATT from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle @@ -90,7 +91,7 @@ class Sense(Entity): self._state = None if sensor_type == ACTIVE_TYPE: - self._unit_of_measurement = 'W' + self._unit_of_measurement = POWER_WATT else: self._unit_of_measurement = 'kWh' diff --git a/homeassistant/components/sensor/efergy.py b/homeassistant/components/sensor/efergy.py index 54666c74f96..18a8fa2e02d 100644 --- a/homeassistant/components/sensor/efergy.py +++ b/homeassistant/components/sensor/efergy.py @@ -10,7 +10,7 @@ import requests import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import CONF_CURRENCY +from homeassistant.const import CONF_CURRENCY, POWER_WATT import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -34,11 +34,11 @@ DEFAULT_PERIOD = 'year' DEFAULT_UTC_OFFSET = '0' SENSOR_TYPES = { - CONF_INSTANT: ['Energy Usage', 'W'], + CONF_INSTANT: ['Energy Usage', POWER_WATT], CONF_AMOUNT: ['Energy Consumed', 'kWh'], CONF_BUDGET: ['Energy Budget', None], CONF_COST: ['Energy Cost', None], - CONF_CURRENT_VALUES: ['Per-Device Usage', 'W'] + CONF_CURRENT_VALUES: ['Per-Device Usage', POWER_WATT] } TYPES_SCHEMA = vol.In(SENSOR_TYPES) diff --git a/homeassistant/components/sensor/eliqonline.py b/homeassistant/components/sensor/eliqonline.py index 8e750a8d5e1..b03164a30d4 100644 --- a/homeassistant/components/sensor/eliqonline.py +++ b/homeassistant/components/sensor/eliqonline.py @@ -10,7 +10,7 @@ import logging import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import (CONF_ACCESS_TOKEN, CONF_NAME) +from homeassistant.const import (CONF_ACCESS_TOKEN, CONF_NAME, POWER_WATT) from homeassistant.helpers.entity import Entity import homeassistant.helpers.config_validation as cv from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -27,7 +27,7 @@ ICON = 'mdi:gauge' SCAN_INTERVAL = timedelta(seconds=60) -UNIT_OF_MEASUREMENT = 'W' +UNIT_OF_MEASUREMENT = POWER_WATT PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_ACCESS_TOKEN): cv.string, diff --git a/homeassistant/components/sensor/emoncms.py b/homeassistant/components/sensor/emoncms.py index 7546224d4c5..5d619878d98 100644 --- a/homeassistant/components/sensor/emoncms.py +++ b/homeassistant/components/sensor/emoncms.py @@ -14,7 +14,7 @@ import homeassistant.helpers.config_validation as cv from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.const import ( CONF_API_KEY, CONF_URL, CONF_VALUE_TEMPLATE, CONF_UNIT_OF_MEASUREMENT, - CONF_ID, CONF_SCAN_INTERVAL, STATE_UNKNOWN) + CONF_ID, CONF_SCAN_INTERVAL, STATE_UNKNOWN, POWER_WATT) from homeassistant.helpers.entity import Entity from homeassistant.helpers import template from homeassistant.util import Throttle @@ -34,7 +34,7 @@ CONF_ONLY_INCLUDE_FEEDID = 'include_only_feed_id' CONF_SENSOR_NAMES = 'sensor_names' DECIMALS = 2 -DEFAULT_UNIT = 'W' +DEFAULT_UNIT = POWER_WATT MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=5) diff --git a/homeassistant/components/sensor/enphase_envoy.py b/homeassistant/components/sensor/enphase_envoy.py index 4bbf7eec01b..1bfee88d41c 100644 --- a/homeassistant/components/sensor/enphase_envoy.py +++ b/homeassistant/components/sensor/enphase_envoy.py @@ -11,14 +11,15 @@ import voluptuous as vol from homeassistant.helpers.entity import Entity from homeassistant.components.sensor import PLATFORM_SCHEMA import homeassistant.helpers.config_validation as cv -from homeassistant.const import (CONF_IP_ADDRESS, CONF_MONITORED_CONDITIONS) +from homeassistant.const import ( + CONF_IP_ADDRESS, CONF_MONITORED_CONDITIONS, POWER_WATT) REQUIREMENTS = ['envoy_reader==0.3'] _LOGGER = logging.getLogger(__name__) SENSORS = { - "production": ("Envoy Current Energy Production", 'W'), + "production": ("Envoy Current Energy Production", POWER_WATT), "daily_production": ("Envoy Today's Energy Production", "Wh"), "seven_days_production": ("Envoy Last Seven Days Energy Production", "Wh"), "lifetime_production": ("Envoy Lifetime Energy Production", "Wh"), diff --git a/homeassistant/components/sensor/greeneye_monitor.py b/homeassistant/components/sensor/greeneye_monitor.py index 3793ea7846c..4dee9d69b42 100644 --- a/homeassistant/components/sensor/greeneye_monitor.py +++ b/homeassistant/components/sensor/greeneye_monitor.py @@ -6,7 +6,7 @@ https://home-assistant.io/components/sensors.greeneye_monitor_temperature/ """ import logging -from homeassistant.const import CONF_NAME, CONF_TEMPERATURE_UNIT +from homeassistant.const import CONF_NAME, CONF_TEMPERATURE_UNIT, POWER_WATT from homeassistant.helpers.entity import Entity from ..greeneye_monitor import ( @@ -33,7 +33,7 @@ DEPENDENCIES = ['greeneye_monitor'] DATA_PULSES = 'pulses' DATA_WATT_SECONDS = 'watt_seconds' -UNIT_WATTS = 'W' +UNIT_WATTS = POWER_WATT COUNTER_ICON = 'mdi:counter' CURRENT_SENSOR_ICON = 'mdi:flash' diff --git a/homeassistant/components/sensor/neurio_energy.py b/homeassistant/components/sensor/neurio_energy.py index addb7925bc2..a9fbc316751 100644 --- a/homeassistant/components/sensor/neurio_energy.py +++ b/homeassistant/components/sensor/neurio_energy.py @@ -11,7 +11,7 @@ import requests.exceptions import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import (CONF_API_KEY) +from homeassistant.const import (CONF_API_KEY, POWER_WATT) from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle import homeassistant.helpers.config_validation as cv @@ -148,7 +148,7 @@ class NeurioEnergy(Entity): self._state = None if sensor_type == ACTIVE_TYPE: - self._unit_of_measurement = 'W' + self._unit_of_measurement = POWER_WATT elif sensor_type == DAILY_TYPE: self._unit_of_measurement = 'kWh' diff --git a/homeassistant/components/sensor/nut.py b/homeassistant/components/sensor/nut.py index 79ad176e42e..1464c0d91c1 100644 --- a/homeassistant/components/sensor/nut.py +++ b/homeassistant/components/sensor/nut.py @@ -13,7 +13,8 @@ from homeassistant.components.sensor import PLATFORM_SCHEMA import homeassistant.helpers.config_validation as cv from homeassistant.const import ( CONF_HOST, CONF_PORT, CONF_NAME, CONF_USERNAME, CONF_PASSWORD, - TEMP_CELSIUS, CONF_RESOURCES, CONF_ALIAS, ATTR_STATE, STATE_UNKNOWN) + TEMP_CELSIUS, CONF_RESOURCES, CONF_ALIAS, ATTR_STATE, STATE_UNKNOWN, + POWER_WATT) from homeassistant.exceptions import PlatformNotReady from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle @@ -63,8 +64,8 @@ SENSOR_TYPES = { 'ups.efficiency': ['Efficiency', '%', 'mdi:gauge'], 'ups.power': ['Current Apparent Power', 'VA', 'mdi:flash'], 'ups.power.nominal': ['Nominal Power', 'VA', 'mdi:flash'], - 'ups.realpower': ['Current Real Power', 'W', 'mdi:flash'], - 'ups.realpower.nominal': ['Nominal Real Power', 'W', 'mdi:flash'], + 'ups.realpower': ['Current Real Power', POWER_WATT, 'mdi:flash'], + 'ups.realpower.nominal': ['Nominal Real Power', POWER_WATT, 'mdi:flash'], 'ups.beeper.status': ['Beeper Status', '', 'mdi:information-outline'], 'ups.type': ['UPS Type', '', 'mdi:information-outline'], 'ups.watchdog.status': ['Watchdog Status', '', 'mdi:information-outline'], diff --git a/homeassistant/components/sensor/solaredge.py b/homeassistant/components/sensor/solaredge.py index fa49cdb3bfe..be21316948a 100644 --- a/homeassistant/components/sensor/solaredge.py +++ b/homeassistant/components/sensor/solaredge.py @@ -12,7 +12,7 @@ import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.const import ( - CONF_API_KEY, CONF_MONITORED_CONDITIONS, CONF_NAME) + CONF_API_KEY, CONF_MONITORED_CONDITIONS, CONF_NAME, POWER_WATT) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle @@ -36,7 +36,7 @@ SENSOR_TYPES = { 'mdi:solar-power'], 'energy_today': ['lastDayData', "Energy today", 'Wh', 'mdi:solar-power'], - 'current_power': ['currentPower', "Current Power", 'W', + 'current_power': ['currentPower', "Current Power", POWER_WATT, 'mdi:solar-power'] } diff --git a/homeassistant/components/sensor/ted5000.py b/homeassistant/components/sensor/ted5000.py index 82a1ec8bb68..23a20b3e830 100644 --- a/homeassistant/components/sensor/ted5000.py +++ b/homeassistant/components/sensor/ted5000.py @@ -11,7 +11,8 @@ import requests import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import (CONF_HOST, CONF_NAME, CONF_PORT) +from homeassistant.const import ( + CONF_HOST, CONF_NAME, CONF_PORT, POWER_WATT) from homeassistant.helpers import config_validation as cv from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle @@ -46,7 +47,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): dev = [] for mtu in gateway.data: - dev.append(Ted5000Sensor(gateway, name, mtu, 'W')) + dev.append(Ted5000Sensor(gateway, name, mtu, POWER_WATT)) dev.append(Ted5000Sensor(gateway, name, mtu, 'V')) add_entities(dev) @@ -58,7 +59,7 @@ class Ted5000Sensor(Entity): def __init__(self, gateway, name, mtu, unit): """Initialize the sensor.""" - units = {'W': 'power', 'V': 'voltage'} + units = {POWER_WATT: 'power', 'V': 'voltage'} self._gateway = gateway self._name = '{} mtu{} {}'.format(name, mtu, units[unit]) self._mtu = mtu @@ -114,4 +115,4 @@ class Ted5000Gateway: voltage = int(doc["LiveData"]["Voltage"]["MTU%d" % mtu] ["VoltageNow"]) - self.data[mtu] = {'W': power, 'V': voltage / 10} + self.data[mtu] = {POWER_WATT: power, 'V': voltage / 10} diff --git a/homeassistant/components/sensor/volkszaehler.py b/homeassistant/components/sensor/volkszaehler.py index 47aa580e3d4..d81400d300e 100644 --- a/homeassistant/components/sensor/volkszaehler.py +++ b/homeassistant/components/sensor/volkszaehler.py @@ -11,7 +11,7 @@ import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.const import ( - CONF_HOST, CONF_NAME, CONF_PORT, CONF_MONITORED_CONDITIONS) + CONF_HOST, CONF_NAME, CONF_PORT, CONF_MONITORED_CONDITIONS, POWER_WATT) from homeassistant.exceptions import PlatformNotReady from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv @@ -31,10 +31,10 @@ DEFAULT_PORT = 80 MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=1) SENSOR_TYPES = { - 'average': ['Average', 'W', 'mdi:power-off'], + 'average': ['Average', POWER_WATT, 'mdi:power-off'], 'consumption': ['Consumption', 'Wh', 'mdi:power-plug'], - 'max': ['Max', 'W', 'mdi:arrow-up'], - 'min': ['Min', 'W', 'mdi:arrow-down'], + 'max': ['Max', POWER_WATT, 'mdi:arrow-up'], + 'min': ['Min', POWER_WATT, 'mdi:arrow-down'], } PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ diff --git a/homeassistant/components/smappee/sensor.py b/homeassistant/components/smappee/sensor.py index 67213ab15bf..afe06d83f47 100644 --- a/homeassistant/components/smappee/sensor.py +++ b/homeassistant/components/smappee/sensor.py @@ -4,6 +4,7 @@ from datetime import timedelta from homeassistant.components.smappee import DATA_SMAPPEE from homeassistant.helpers.entity import Entity +from homeassistant.const import POWER_WATT DEPENDENCIES = ['smappee'] @@ -12,9 +13,10 @@ _LOGGER = logging.getLogger(__name__) SENSOR_PREFIX = 'Smappee' SENSOR_TYPES = { 'solar': - ['Solar', 'mdi:white-balance-sunny', 'local', 'W', 'solar'], + ['Solar', 'mdi:white-balance-sunny', 'local', POWER_WATT, 'solar'], 'active_power': - ['Active Power', 'mdi:power-plug', 'local', 'W', 'active_power'], + ['Active Power', 'mdi:power-plug', 'local', POWER_WATT, + 'active_power'], 'current': ['Current', 'mdi:gauge', 'local', 'A', 'current'], 'voltage': diff --git a/homeassistant/components/smartthings/sensor.py b/homeassistant/components/smartthings/sensor.py index 50beefdb5b2..680098adc7e 100644 --- a/homeassistant/components/smartthings/sensor.py +++ b/homeassistant/components/smartthings/sensor.py @@ -5,7 +5,7 @@ from typing import Optional, Sequence from homeassistant.const import ( DEVICE_CLASS_BATTERY, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TIMESTAMP, MASS_KILOGRAMS, - TEMP_CELSIUS, TEMP_FAHRENHEIT) + TEMP_CELSIUS, TEMP_FAHRENHEIT, POWER_WATT) from . import SmartThingsEntity from .const import DATA_BROKERS, DOMAIN @@ -85,7 +85,7 @@ CAPABILITY_TO_SENSORS = { 'ovenSetpoint': [ Map('ovenSetpoint', "Oven Set Point", None, None)], 'powerMeter': [ - Map('power', "Power Meter", 'W', None)], + Map('power', "Power Meter", POWER_WATT, None)], 'powerSource': [ Map('powerSource', "Power Source", None, None)], 'refrigerationSetpoint': [ diff --git a/homeassistant/components/switch/fritzdect.py b/homeassistant/components/switch/fritzdect.py index a04de7618af..2aefcec9670 100644 --- a/homeassistant/components/switch/fritzdect.py +++ b/homeassistant/components/switch/fritzdect.py @@ -12,7 +12,7 @@ import voluptuous as vol from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA) from homeassistant.const import ( - CONF_HOST, CONF_PASSWORD, CONF_USERNAME) + CONF_HOST, CONF_PASSWORD, CONF_USERNAME, POWER_WATT) import homeassistant.helpers.config_validation as cv from homeassistant.const import TEMP_CELSIUS, ATTR_TEMPERATURE @@ -25,7 +25,7 @@ DEFAULT_HOST = 'fritz.box' ATTR_CURRENT_CONSUMPTION = 'current_consumption' ATTR_CURRENT_CONSUMPTION_UNIT = 'current_consumption_unit' -ATTR_CURRENT_CONSUMPTION_UNIT_VALUE = 'W' +ATTR_CURRENT_CONSUMPTION_UNIT_VALUE = POWER_WATT ATTR_TOTAL_CONSUMPTION = 'total_consumption' ATTR_TOTAL_CONSUMPTION_UNIT = 'total_consumption_unit' diff --git a/homeassistant/components/tellduslive/sensor.py b/homeassistant/components/tellduslive/sensor.py index 48133fd69e6..42c93aa52f9 100644 --- a/homeassistant/components/tellduslive/sensor.py +++ b/homeassistant/components/tellduslive/sensor.py @@ -5,7 +5,7 @@ from homeassistant.components import sensor, tellduslive from homeassistant.components.tellduslive.entry import TelldusLiveEntity from homeassistant.const import ( DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_TEMPERATURE, - TEMP_CELSIUS) + TEMP_CELSIUS, POWER_WATT) from homeassistant.helpers.dispatcher import async_dispatcher_connect _LOGGER = logging.getLogger(__name__) @@ -33,7 +33,7 @@ SENSOR_TYPES = { SENSOR_TYPE_WINDAVERAGE: ['Wind average', 'm/s', '', None], SENSOR_TYPE_WINDGUST: ['Wind gust', 'm/s', '', None], SENSOR_TYPE_UV: ['UV', 'UV', '', None], - SENSOR_TYPE_WATT: ['Power', 'W', '', None], + SENSOR_TYPE_WATT: ['Power', POWER_WATT, '', None], SENSOR_TYPE_LUMINANCE: ['Luminance', 'lx', None, DEVICE_CLASS_ILLUMINANCE], SENSOR_TYPE_DEW_POINT: ['Dew Point', TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE], diff --git a/homeassistant/components/zha/sensor.py b/homeassistant/components/zha/sensor.py index 6dcdbb845dc..16ca8ec3d71 100644 --- a/homeassistant/components/zha/sensor.py +++ b/homeassistant/components/zha/sensor.py @@ -7,7 +7,7 @@ at https://home-assistant.io/components/sensor.zha/ import logging from homeassistant.components.sensor import DOMAIN -from homeassistant.const import TEMP_CELSIUS +from homeassistant.const import TEMP_CELSIUS, POWER_WATT from homeassistant.helpers.dispatcher import async_dispatcher_connect from .core.const import ( DATA_ZHA, DATA_ZHA_DISPATCHERS, ZHA_DISCOVERY_NEW, HUMIDITY, TEMPERATURE, @@ -69,8 +69,8 @@ UNIT_REGISTRY = { TEMPERATURE: TEMP_CELSIUS, PRESSURE: 'hPa', ILLUMINANCE: 'lx', - METERING: 'W', - ELECTRICAL_MEASUREMENT: 'W', + METERING: POWER_WATT, + ELECTRICAL_MEASUREMENT: POWER_WATT, GENERIC: None } diff --git a/homeassistant/const.py b/homeassistant/const.py index 54901feb73b..49194c06c17 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -319,6 +319,9 @@ ATTR_DEVICE_CLASS = 'device_class' ATTR_TEMPERATURE = 'temperature' # #### UNITS OF MEASUREMENT #### +# Power units +POWER_WATT = 'W' + # Temperature units TEMP_CELSIUS = '°C' TEMP_FAHRENHEIT = '°F'