diff --git a/homeassistant/components/shelly/sensor.py b/homeassistant/components/shelly/sensor.py index 6bc3b52b65f..c951cf7c5ea 100644 --- a/homeassistant/components/shelly/sensor.py +++ b/homeassistant/components/shelly/sensor.py @@ -22,9 +22,9 @@ from homeassistant.const import ( ENERGY_KILO_WATT_HOUR, LIGHT_LUX, PERCENTAGE, - POWER_WATT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, TEMP_CELSIUS, + UnitOfPower, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory @@ -97,7 +97,7 @@ SENSORS: Final = { ("light", "power"): BlockSensorDescription( key="light|power", name="Power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, value=lambda value: round(value, 1), device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, @@ -106,7 +106,7 @@ SENSORS: Final = { ("device", "power"): BlockSensorDescription( key="device|power", name="Power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, value=lambda value: round(value, 1), device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, @@ -114,7 +114,7 @@ SENSORS: Final = { ("emeter", "power"): BlockSensorDescription( key="emeter|power", name="Power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, value=lambda value: round(value, 1), device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, @@ -147,7 +147,7 @@ SENSORS: Final = { ("relay", "power"): BlockSensorDescription( key="relay|power", name="Power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, value=lambda value: round(value, 1), device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, @@ -155,7 +155,7 @@ SENSORS: Final = { ("roller", "rollerPower"): BlockSensorDescription( key="roller|rollerPower", name="Power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, value=lambda value: round(value, 1), device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, @@ -317,7 +317,7 @@ RPC_SENSORS: Final = { key="switch", sub_key="apower", name="Power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, value=lambda status, _: round(float(status), 1), device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, diff --git a/homeassistant/components/sma/sensor.py b/homeassistant/components/sma/sensor.py index b06ec499a24..df56757db5b 100644 --- a/homeassistant/components/sma/sensor.py +++ b/homeassistant/components/sma/sensor.py @@ -11,7 +11,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT +from homeassistant.const import ENERGY_KILO_WATT_HOUR, UnitOfPower from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -73,7 +73,7 @@ class SMAsensor(CoordinatorEntity, SensorEntity): if self.native_unit_of_measurement == ENERGY_KILO_WATT_HOUR: self._attr_state_class = SensorStateClass.TOTAL_INCREASING self._attr_device_class = SensorDeviceClass.ENERGY - if self.native_unit_of_measurement == POWER_WATT: + if self.native_unit_of_measurement == UnitOfPower.WATT: self._attr_state_class = SensorStateClass.MEASUREMENT self._attr_device_class = SensorDeviceClass.POWER diff --git a/homeassistant/components/smappee/sensor.py b/homeassistant/components/smappee/sensor.py index ff258677b3e..7344a3ff8db 100644 --- a/homeassistant/components/smappee/sensor.py +++ b/homeassistant/components/smappee/sensor.py @@ -14,7 +14,7 @@ from homeassistant.const import ( ELECTRIC_POTENTIAL_VOLT, ENERGY_KILO_WATT_HOUR, ENERGY_WATT_HOUR, - POWER_WATT, + UnitOfPower, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo @@ -53,7 +53,7 @@ TREND_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( SmappeePollingSensorEntityDescription( key="total_power", name="Total consumption - Active power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, sensor_id="total_power", device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, @@ -62,7 +62,7 @@ TREND_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( SmappeePollingSensorEntityDescription( key="alwayson", name="Always on - Active power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, sensor_id="alwayson", device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, @@ -104,7 +104,7 @@ REACTIVE_SENSORS: tuple[SmappeeSensorEntityDescription, ...] = ( SmappeeSensorEntityDescription( key="total_reactive_power", name="Total consumption - Reactive power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, sensor_id="total_reactive_power", device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, @@ -114,7 +114,7 @@ SOLAR_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( SmappeePollingSensorEntityDescription( key="solar_power", name="Total production - Active power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, sensor_id="solar_power", device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, @@ -254,7 +254,7 @@ async def async_setup_entry( description=SmappeeSensorEntityDescription( key="load", name=measurement.name, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, sensor_id=measurement_id, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, diff --git a/homeassistant/components/solaredge/const.py b/homeassistant/components/solaredge/const.py index fd989fc8a2a..b4536a30d99 100644 --- a/homeassistant/components/solaredge/const.py +++ b/homeassistant/components/solaredge/const.py @@ -3,7 +3,7 @@ from datetime import timedelta import logging from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass -from homeassistant.const import ENERGY_WATT_HOUR, PERCENTAGE, POWER_WATT +from homeassistant.const import ENERGY_WATT_HOUR, PERCENTAGE, UnitOfPower from .models import SolarEdgeSensorEntityDescription @@ -70,7 +70,7 @@ SENSOR_TYPES = [ name="Current Power", icon="mdi:solar-power", state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, ), SolarEdgeSensorEntityDescription( diff --git a/homeassistant/components/solax/sensor.py b/homeassistant/components/solax/sensor.py index 307d3c4c373..8a73f5f0776 100644 --- a/homeassistant/components/solax/sensor.py +++ b/homeassistant/components/solax/sensor.py @@ -21,8 +21,8 @@ from homeassistant.const import ( ENERGY_KILO_WATT_HOUR, FREQUENCY_HERTZ, PERCENTAGE, - POWER_WATT, TEMP_CELSIUS, + UnitOfPower, ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady @@ -70,7 +70,7 @@ SENSOR_DESCRIPTIONS: dict[tuple[Units, bool], SensorEntityDescription] = { (Units.W, False): SensorEntityDescription( key=f"{Units.W}_{False}", device_class=SensorDeviceClass.POWER, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, state_class=SensorStateClass.MEASUREMENT, ), (Units.PERCENT, False): SensorEntityDescription( diff --git a/homeassistant/components/spider/sensor.py b/homeassistant/components/spider/sensor.py index d8006885553..35b6513528f 100644 --- a/homeassistant/components/spider/sensor.py +++ b/homeassistant/components/spider/sensor.py @@ -7,7 +7,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT +from homeassistant.const import ENERGY_KILO_WATT_HOUR, UnitOfPower from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -76,7 +76,7 @@ class SpiderPowerPlugPower(SensorEntity): _attr_device_class = SensorDeviceClass.POWER _attr_state_class = SensorStateClass.MEASUREMENT - _attr_native_unit_of_measurement = POWER_WATT + _attr_native_unit_of_measurement = UnitOfPower.WATT def __init__(self, api, power_plug) -> None: """Initialize the Spider Power Plug.""" diff --git a/homeassistant/components/switcher_kis/sensor.py b/homeassistant/components/switcher_kis/sensor.py index 33e2fb91a43..c75d27d67d4 100644 --- a/homeassistant/components/switcher_kis/sensor.py +++ b/homeassistant/components/switcher_kis/sensor.py @@ -11,7 +11,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import POWER_WATT, UnitOfElectricCurrent +from homeassistant.const import UnitOfElectricCurrent, UnitOfPower from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import device_registry from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -38,7 +38,7 @@ class AttributeDescription: POWER_SENSORS = { "power_consumption": AttributeDescription( name="Power Consumption", - unit=POWER_WATT, + unit=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, ), diff --git a/homeassistant/components/system_bridge/sensor.py b/homeassistant/components/system_bridge/sensor.py index ab34e6b91b5..64f37bde91f 100644 --- a/homeassistant/components/system_bridge/sensor.py +++ b/homeassistant/components/system_bridge/sensor.py @@ -21,9 +21,9 @@ from homeassistant.const import ( FREQUENCY_HERTZ, FREQUENCY_MEGAHERTZ, PERCENTAGE, - POWER_WATT, REVOLUTIONS_PER_MINUTE, TEMP_CELSIUS, + UnitOfPower, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -455,7 +455,7 @@ async def async_setup_entry( entity_registry_enabled_default=False, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, value=lambda data, k=gpu["key"]: getattr(data.gpu, f"{k}_power"), ), entry.data[CONF_PORT], diff --git a/homeassistant/components/tasmota/sensor.py b/homeassistant/components/tasmota/sensor.py index b505a52f78e..3dc67bec8b5 100644 --- a/homeassistant/components/tasmota/sensor.py +++ b/homeassistant/components/tasmota/sensor.py @@ -27,7 +27,6 @@ from homeassistant.const import ( LIGHT_LUX, MASS_KILOGRAMS, PERCENTAGE, - POWER_WATT, PRESSURE_HPA, SIGNAL_STRENGTH_DECIBELS, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, @@ -38,6 +37,7 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, TEMP_KELVIN, UnitOfApparentPower, + UnitOfPower, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -221,7 +221,7 @@ SENSOR_UNIT_MAP = { hc.LIGHT_LUX: LIGHT_LUX, hc.MASS_KILOGRAMS: MASS_KILOGRAMS, hc.PERCENTAGE: PERCENTAGE, - hc.POWER_WATT: POWER_WATT, + hc.POWER_WATT: UnitOfPower.WATT, hc.PRESSURE_HPA: PRESSURE_HPA, hc.SIGNAL_STRENGTH_DECIBELS: SIGNAL_STRENGTH_DECIBELS, hc.SIGNAL_STRENGTH_DECIBELS_MILLIWATT: SIGNAL_STRENGTH_DECIBELS_MILLIWATT, diff --git a/homeassistant/components/tibber/sensor.py b/homeassistant/components/tibber/sensor.py index 31106990a03..0b35034013c 100644 --- a/homeassistant/components/tibber/sensor.py +++ b/homeassistant/components/tibber/sensor.py @@ -31,8 +31,8 @@ from homeassistant.const import ( ENERGY_KILO_WATT_HOUR, EVENT_HOMEASSISTANT_STOP, PERCENTAGE, - POWER_WATT, SIGNAL_STRENGTH_DECIBELS, + UnitOfPower, ) from homeassistant.core import Event, HomeAssistant, callback from homeassistant.exceptions import PlatformNotReady @@ -61,33 +61,33 @@ RT_SENSORS: tuple[SensorEntityDescription, ...] = ( key="averagePower", name="average power", device_class=SensorDeviceClass.POWER, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, ), SensorEntityDescription( key="power", name="power", device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, ), SensorEntityDescription( key="powerProduction", name="power production", device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, ), SensorEntityDescription( key="minPower", name="min power", device_class=SensorDeviceClass.POWER, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, ), SensorEntityDescription( key="maxPower", name="max power", device_class=SensorDeviceClass.POWER, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, ), SensorEntityDescription( key="accumulatedConsumption", diff --git a/homeassistant/components/toon/sensor.py b/homeassistant/components/toon/sensor.py index 0fceb1a8a0a..68ce4440279 100644 --- a/homeassistant/components/toon/sensor.py +++ b/homeassistant/components/toon/sensor.py @@ -13,8 +13,8 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ENERGY_KILO_WATT_HOUR, PERCENTAGE, - POWER_WATT, TEMP_CELSIUS, + UnitOfPower, UnitOfVolume, ) from homeassistant.core import HomeAssistant @@ -212,7 +212,7 @@ SENSOR_ENTITIES: tuple[ToonSensorEntityDescription, ...] = ( name="Average Power Usage", section="power_usage", measurement="average", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, entity_registry_enabled_default=False, cls=ToonElectricityMeterDeviceSensor, @@ -272,7 +272,7 @@ SENSOR_ENTITIES: tuple[ToonSensorEntityDescription, ...] = ( name="Current Power Usage", section="power_usage", measurement="current", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, cls=ToonElectricityMeterDeviceSensor, @@ -372,7 +372,7 @@ SENSOR_ENTITIES_SOLAR: tuple[ToonSensorEntityDescription, ...] = ( name="Current Solar Power Production", section="power_usage", measurement="current_solar", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, cls=ToonSolarDeviceSensor, @@ -382,7 +382,7 @@ SENSOR_ENTITIES_SOLAR: tuple[ToonSensorEntityDescription, ...] = ( name="Max Solar Power Production Today", section="power_usage", measurement="day_max_solar", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, cls=ToonSolarDeviceSensor, ), @@ -391,7 +391,7 @@ SENSOR_ENTITIES_SOLAR: tuple[ToonSensorEntityDescription, ...] = ( name="Solar Power Production to Grid", section="power_usage", measurement="current_produced", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, cls=ToonSolarDeviceSensor, @@ -431,7 +431,7 @@ SENSOR_ENTITIES_SOLAR: tuple[ToonSensorEntityDescription, ...] = ( name="Average Solar Power Production to Grid", section="power_usage", measurement="average_produced", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, entity_registry_enabled_default=False, cls=ToonSolarDeviceSensor, diff --git a/homeassistant/components/tplink/sensor.py b/homeassistant/components/tplink/sensor.py index 7ba28702114..8fe47f56772 100644 --- a/homeassistant/components/tplink/sensor.py +++ b/homeassistant/components/tplink/sensor.py @@ -18,7 +18,7 @@ from homeassistant.const import ( ELECTRIC_CURRENT_AMPERE, ELECTRIC_POTENTIAL_VOLT, ENERGY_KILO_WATT_HOUR, - POWER_WATT, + UnitOfPower, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -46,7 +46,7 @@ class TPLinkSensorEntityDescription(SensorEntityDescription): ENERGY_SENSORS: tuple[TPLinkSensorEntityDescription, ...] = ( TPLinkSensorEntityDescription( key=ATTR_CURRENT_POWER_W, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, name="Current Consumption", diff --git a/homeassistant/components/tuya/const.py b/homeassistant/components/tuya/const.py index d5d2f64ce42..3b7a46680f8 100644 --- a/homeassistant/components/tuya/const.py +++ b/homeassistant/components/tuya/const.py @@ -22,8 +22,6 @@ from homeassistant.const import ( ENERGY_WATT_HOUR, LIGHT_LUX, PERCENTAGE, - POWER_KILO_WATT, - POWER_WATT, PRESSURE_BAR, PRESSURE_HPA, PRESSURE_INHG, @@ -37,6 +35,7 @@ from homeassistant.const import ( VOLUME_CUBIC_FEET, VOLUME_CUBIC_METERS, Platform, + UnitOfPower, ) DOMAIN = "tuya" @@ -505,12 +504,12 @@ UNITS = ( conversion_fn=lambda x: x * 1000, ), UnitOfMeasurement( - unit=POWER_WATT, + unit=UnitOfPower.WATT, aliases={"watt"}, device_classes={SensorDeviceClass.POWER}, ), UnitOfMeasurement( - unit=POWER_KILO_WATT, + unit=UnitOfPower.KILO_WATT, aliases={"kilowatt"}, device_classes={SensorDeviceClass.POWER}, ), diff --git a/homeassistant/components/tuya/sensor.py b/homeassistant/components/tuya/sensor.py index b675a6b7033..626cb3bbc1b 100644 --- a/homeassistant/components/tuya/sensor.py +++ b/homeassistant/components/tuya/sensor.py @@ -16,9 +16,9 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ELECTRIC_POTENTIAL_VOLT, PERCENTAGE, - POWER_KILO_WATT, TIME_MINUTES, UnitOfElectricCurrent, + UnitOfPower, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -675,7 +675,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = { name="Phase A power", device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=POWER_KILO_WATT, + native_unit_of_measurement=UnitOfPower.KILO_WATT, subkey="power", ), TuyaSensorEntityDescription( @@ -699,7 +699,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = { name="Phase B power", device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=POWER_KILO_WATT, + native_unit_of_measurement=UnitOfPower.KILO_WATT, subkey="power", ), TuyaSensorEntityDescription( @@ -723,7 +723,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = { name="Phase C power", device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=POWER_KILO_WATT, + native_unit_of_measurement=UnitOfPower.KILO_WATT, subkey="power", ), TuyaSensorEntityDescription( @@ -757,7 +757,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = { name="Phase A power", device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=POWER_KILO_WATT, + native_unit_of_measurement=UnitOfPower.KILO_WATT, subkey="power", ), TuyaSensorEntityDescription( @@ -781,7 +781,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = { name="Phase B power", device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=POWER_KILO_WATT, + native_unit_of_measurement=UnitOfPower.KILO_WATT, subkey="power", ), TuyaSensorEntityDescription( @@ -805,7 +805,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = { name="Phase C power", device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=POWER_KILO_WATT, + native_unit_of_measurement=UnitOfPower.KILO_WATT, subkey="power", ), TuyaSensorEntityDescription( diff --git a/homeassistant/components/vera/sensor.py b/homeassistant/components/vera/sensor.py index 9f488fad33e..532e44f4a43 100644 --- a/homeassistant/components/vera/sensor.py +++ b/homeassistant/components/vera/sensor.py @@ -15,10 +15,10 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( LIGHT_LUX, PERCENTAGE, - POWER_WATT, TEMP_CELSIUS, TEMP_FAHRENHEIT, Platform, + UnitOfPower, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -90,7 +90,7 @@ class VeraSensor(VeraDevice[veraApi.VeraSensor], SensorEntity): if self.vera_device.category == veraApi.CATEGORY_HUMIDITY_SENSOR: return PERCENTAGE if self.vera_device.category == veraApi.CATEGORY_POWER_METER: - return POWER_WATT + return UnitOfPower.WATT return None def update(self) -> None: diff --git a/homeassistant/components/vesync/sensor.py b/homeassistant/components/vesync/sensor.py index c5a2e7182a9..3926e0fbee6 100644 --- a/homeassistant/components/vesync/sensor.py +++ b/homeassistant/components/vesync/sensor.py @@ -21,7 +21,7 @@ from homeassistant.const import ( ELECTRIC_POTENTIAL_VOLT, ENERGY_KILO_WATT_HOUR, PERCENTAGE, - POWER_WATT, + UnitOfPower, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -105,7 +105,7 @@ SENSORS: tuple[VeSyncSensorEntityDescription, ...] = ( key="power", name="current power", device_class=SensorDeviceClass.POWER, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda device: device.details["power"], update_fn=update_energy, diff --git a/homeassistant/components/wallbox/sensor.py b/homeassistant/components/wallbox/sensor.py index 9ce76d59608..3c2c5171a70 100644 --- a/homeassistant/components/wallbox/sensor.py +++ b/homeassistant/components/wallbox/sensor.py @@ -17,7 +17,7 @@ from homeassistant.const import ( ENERGY_KILO_WATT_HOUR, LENGTH_KILOMETERS, PERCENTAGE, - POWER_KILO_WATT, + UnitOfPower, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -62,7 +62,7 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = { key=CHARGER_CHARGING_POWER_KEY, name="Charging Power", precision=2, - native_unit_of_measurement=POWER_KILO_WATT, + native_unit_of_measurement=UnitOfPower.KILO_WATT, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, ), diff --git a/homeassistant/components/wemo/sensor.py b/homeassistant/components/wemo/sensor.py index b79ce08a1e0..7ebd834579e 100644 --- a/homeassistant/components/wemo/sensor.py +++ b/homeassistant/components/wemo/sensor.py @@ -13,7 +13,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT +from homeassistant.const import ENERGY_KILO_WATT_HOUR, UnitOfPower from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -37,7 +37,7 @@ ATTRIBUTE_SENSORS = ( name="Current Power", device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, key="current_power_watts", unique_id_suffix="currentpower", state_conversion=lambda state: round(cast(float, state), 2), diff --git a/homeassistant/components/wiz/sensor.py b/homeassistant/components/wiz/sensor.py index d2042d6ea9c..ea4e57dc18b 100644 --- a/homeassistant/components/wiz/sensor.py +++ b/homeassistant/components/wiz/sensor.py @@ -8,7 +8,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import POWER_WATT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT +from homeassistant.const import SIGNAL_STRENGTH_DECIBELS_MILLIWATT, UnitOfPower from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -36,7 +36,7 @@ POWER_SENSORS: tuple[SensorEntityDescription, ...] = ( name="Current power", state_class=SensorStateClass.MEASUREMENT, device_class=SensorDeviceClass.POWER, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, ), ) diff --git a/homeassistant/components/xiaomi_aqara/sensor.py b/homeassistant/components/xiaomi_aqara/sensor.py index 5deed77d775..2e698ffa4f9 100644 --- a/homeassistant/components/xiaomi_aqara/sensor.py +++ b/homeassistant/components/xiaomi_aqara/sensor.py @@ -14,9 +14,9 @@ from homeassistant.const import ( ATTR_BATTERY_LEVEL, LIGHT_LUX, PERCENTAGE, - POWER_WATT, PRESSURE_HPA, TEMP_CELSIUS, + UnitOfPower, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -65,7 +65,7 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = { ), "load_power": SensorEntityDescription( key="load_power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, ), diff --git a/homeassistant/components/youless/sensor.py b/homeassistant/components/youless/sensor.py index cb79d4606a7..eec5a799589 100644 --- a/homeassistant/components/youless/sensor.py +++ b/homeassistant/components/youless/sensor.py @@ -12,7 +12,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_DEVICE, ENERGY_KILO_WATT_HOUR, - POWER_WATT, + UnitOfPower, UnitOfVolume, ) from homeassistant.core import HomeAssistant @@ -117,7 +117,7 @@ class GasSensor(YoulessBaseSensor): class CurrentPowerSensor(YoulessBaseSensor): """The current power usage sensor.""" - _attr_native_unit_of_measurement = POWER_WATT + _attr_native_unit_of_measurement = UnitOfPower.WATT _attr_device_class = SensorDeviceClass.POWER _attr_state_class = SensorStateClass.MEASUREMENT @@ -220,7 +220,7 @@ class ExtraMeterSensor(YoulessBaseSensor): class ExtraMeterPowerSensor(YoulessBaseSensor): """The Youless extra meter power value sensor (s0).""" - _attr_native_unit_of_measurement = POWER_WATT + _attr_native_unit_of_measurement = UnitOfPower.WATT _attr_device_class = SensorDeviceClass.POWER _attr_state_class = SensorStateClass.MEASUREMENT diff --git a/homeassistant/components/zwave_me/sensor.py b/homeassistant/components/zwave_me/sensor.py index ec115d60675..3748ed52516 100644 --- a/homeassistant/components/zwave_me/sensor.py +++ b/homeassistant/components/zwave_me/sensor.py @@ -19,9 +19,9 @@ from homeassistant.const import ( ENERGY_KILO_WATT_HOUR, LIGHT_LUX, PERCENTAGE, - POWER_WATT, PRESSURE_KPA, TEMP_CELSIUS, + UnitOfPower, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -97,7 +97,7 @@ SENSORS_MAP: dict[str, ZWaveMeSensorEntityDescription] = { "meterElectric_watt": ZWaveMeSensorEntityDescription( key="meterElectric_watt", device_class=SensorDeviceClass.POWER, - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, state_class=SensorStateClass.MEASUREMENT, ), "temperature": ZWaveMeSensorEntityDescription(