From ebdf9a86584dae7585b158e58fb69c1cb14e7e44 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 19 Dec 2022 10:58:37 +0100 Subject: [PATCH] Use UnitOfEnergy in integrations (o-z) (#84221) --- homeassistant/components/oncue/sensor.py | 4 +-- homeassistant/components/openevse/sensor.py | 6 ++--- homeassistant/components/ovo_energy/sensor.py | 6 ++--- homeassistant/components/p1_monitor/sensor.py | 18 ++++++------- homeassistant/components/plugwise/sensor.py | 25 +++++++++---------- homeassistant/components/powerwall/sensor.py | 4 +-- .../components/pure_energie/sensor.py | 6 ++--- homeassistant/components/pvoutput/sensor.py | 9 +++---- .../components/pvpc_hourly_pricing/sensor.py | 4 +-- .../components/rainforest_eagle/sensor.py | 8 +++--- homeassistant/components/renault/sensor.py | 4 +-- homeassistant/components/shelly/sensor.py | 16 ++++++------ homeassistant/components/sma/sensor.py | 4 +-- homeassistant/components/smappee/sensor.py | 21 ++++++---------- .../components/smart_meter_texas/sensor.py | 4 +-- homeassistant/components/solaredge/const.py | 20 +++++++-------- homeassistant/components/solax/sensor.py | 6 ++--- homeassistant/components/spider/sensor.py | 4 +-- homeassistant/components/srp_energy/sensor.py | 4 +-- homeassistant/components/tasmota/sensor.py | 4 +-- homeassistant/components/toon/sensor.py | 20 +++++++-------- homeassistant/components/tplink/sensor.py | 6 ++--- homeassistant/components/tuya/const.py | 7 +++--- .../components/utility_meter/sensor.py | 7 +++--- homeassistant/components/vesync/sensor.py | 10 ++++---- homeassistant/components/wallbox/sensor.py | 6 ++--- homeassistant/components/wemo/sensor.py | 4 +-- homeassistant/components/youless/sensor.py | 13 +++------- homeassistant/components/zwave_me/sensor.py | 4 +-- 29 files changed, 120 insertions(+), 134 deletions(-) diff --git a/homeassistant/components/oncue/sensor.py b/homeassistant/components/oncue/sensor.py index 9dcbbeb10b8..62112200286 100644 --- a/homeassistant/components/oncue/sensor.py +++ b/homeassistant/components/oncue/sensor.py @@ -11,13 +11,13 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ENERGY_KILO_WATT_HOUR, PERCENTAGE, PRESSURE_PSI, TEMP_CELSIUS, TEMP_FAHRENHEIT, UnitOfElectricCurrent, UnitOfElectricPotential, + UnitOfEnergy, UnitOfFrequency, UnitOfPower, ) @@ -152,7 +152,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( ), SensorEntityDescription( key="GensetTotalEnergy", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), diff --git a/homeassistant/components/openevse/sensor.py b/homeassistant/components/openevse/sensor.py index 5bb469a3d99..9fecb141058 100644 --- a/homeassistant/components/openevse/sensor.py +++ b/homeassistant/components/openevse/sensor.py @@ -17,9 +17,9 @@ from homeassistant.components.sensor import ( from homeassistant.const import ( CONF_HOST, CONF_MONITORED_VARIABLES, - ENERGY_KILO_WATT_HOUR, TEMP_CELSIUS, TIME_MINUTES, + UnitOfEnergy, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -64,14 +64,14 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="usage_session", name="Usage this Session", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), SensorEntityDescription( key="usage_total", name="Total Usage", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), diff --git a/homeassistant/components/ovo_energy/sensor.py b/homeassistant/components/ovo_energy/sensor.py index 532bb25cbc8..6f3d463a1f4 100644 --- a/homeassistant/components/ovo_energy/sensor.py +++ b/homeassistant/components/ovo_energy/sensor.py @@ -16,7 +16,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ENERGY_KILO_WATT_HOUR +from homeassistant.const import UnitOfEnergy from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType @@ -46,7 +46,7 @@ SENSOR_TYPES_ELECTRICITY: tuple[OVOEnergySensorEntityDescription, ...] = ( name="OVO Last Electricity Reading", device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, value=lambda usage: usage.electricity[-1].consumption, ), OVOEnergySensorEntityDescription( @@ -80,7 +80,7 @@ SENSOR_TYPES_GAS: tuple[OVOEnergySensorEntityDescription, ...] = ( name="OVO Last Gas Reading", device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, icon="mdi:gas-cylinder", value=lambda usage: usage.gas[-1].consumption, ), diff --git a/homeassistant/components/p1_monitor/sensor.py b/homeassistant/components/p1_monitor/sensor.py index 90d447e2e16..f192dd44300 100644 --- a/homeassistant/components/p1_monitor/sensor.py +++ b/homeassistant/components/p1_monitor/sensor.py @@ -14,9 +14,9 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_HOST, CURRENCY_EURO, - ENERGY_KILO_WATT_HOUR, UnitOfElectricCurrent, UnitOfElectricPotential, + UnitOfEnergy, UnitOfPower, UnitOfVolume, ) @@ -55,14 +55,14 @@ SENSORS_SMARTMETER: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="energy_consumption_high", name="Energy Consumption - High Tariff", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), SensorEntityDescription( key="energy_consumption_low", name="Energy Consumption - Low Tariff", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), @@ -76,14 +76,14 @@ SENSORS_SMARTMETER: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="energy_production_high", name="Energy Production - High Tariff", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), SensorEntityDescription( key="energy_production_low", name="Energy Production - Low Tariff", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), @@ -193,25 +193,25 @@ SENSORS_SETTINGS: tuple[SensorEntityDescription, ...] = ( key="energy_consumption_price_low", name="Energy Consumption Price - Low", state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=f"{CURRENCY_EURO}/{ENERGY_KILO_WATT_HOUR}", + native_unit_of_measurement=f"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}", ), SensorEntityDescription( key="energy_consumption_price_high", name="Energy Consumption Price - High", state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=f"{CURRENCY_EURO}/{ENERGY_KILO_WATT_HOUR}", + native_unit_of_measurement=f"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}", ), SensorEntityDescription( key="energy_production_price_low", name="Energy Production Price - Low", state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=f"{CURRENCY_EURO}/{ENERGY_KILO_WATT_HOUR}", + native_unit_of_measurement=f"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}", ), SensorEntityDescription( key="energy_production_price_high", name="Energy Production Price - High", state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=f"{CURRENCY_EURO}/{ENERGY_KILO_WATT_HOUR}", + native_unit_of_measurement=f"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}", ), ) diff --git a/homeassistant/components/plugwise/sensor.py b/homeassistant/components/plugwise/sensor.py index 7c0fa8f0a4f..82f40938624 100644 --- a/homeassistant/components/plugwise/sensor.py +++ b/homeassistant/components/plugwise/sensor.py @@ -9,11 +9,10 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ENERGY_KILO_WATT_HOUR, - ENERGY_WATT_HOUR, PERCENTAGE, PRESSURE_BAR, TEMP_CELSIUS, + UnitOfEnergy, UnitOfPower, UnitOfVolume, ) @@ -123,28 +122,28 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="electricity_consumed_interval", name="Electricity consumed interval", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL, ), SensorEntityDescription( key="electricity_consumed_peak_interval", name="Electricity consumed peak interval", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL, ), SensorEntityDescription( key="electricity_consumed_off_peak_interval", name="Electricity consumed off peak interval", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL, ), SensorEntityDescription( key="electricity_produced_interval", name="Electricity produced interval", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL, entity_registry_enabled_default=False, @@ -152,14 +151,14 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="electricity_produced_peak_interval", name="Electricity produced peak interval", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL, ), SensorEntityDescription( key="electricity_produced_off_peak_interval", name="Electricity produced off peak interval", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL, ), @@ -180,14 +179,14 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="electricity_consumed_off_peak_cumulative", name="Electricity consumed off peak cumulative", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), SensorEntityDescription( key="electricity_consumed_peak_cumulative", name="Electricity consumed peak cumulative", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), @@ -208,14 +207,14 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="electricity_produced_off_peak_cumulative", name="Electricity produced off peak cumulative", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), SensorEntityDescription( key="electricity_produced_peak_cumulative", name="Electricity produced peak cumulative", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), @@ -243,7 +242,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="net_electricity_cumulative", name="Net electricity cumulative", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL, ), diff --git a/homeassistant/components/powerwall/sensor.py b/homeassistant/components/powerwall/sensor.py index a748a045663..88f71d9511f 100644 --- a/homeassistant/components/powerwall/sensor.py +++ b/homeassistant/components/powerwall/sensor.py @@ -14,10 +14,10 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ENERGY_KILO_WATT_HOUR, PERCENTAGE, UnitOfElectricCurrent, UnitOfElectricPotential, + UnitOfEnergy, UnitOfFrequency, UnitOfPower, ) @@ -203,7 +203,7 @@ class PowerWallEnergyDirectionSensor(PowerWallEntity, SensorEntity): """Representation of an Powerwall Direction Energy sensor.""" _attr_state_class = SensorStateClass.TOTAL - _attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR + _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR _attr_device_class = SensorDeviceClass.ENERGY def __init__( diff --git a/homeassistant/components/pure_energie/sensor.py b/homeassistant/components/pure_energie/sensor.py index 8e092183f94..7d584c7c1a8 100644 --- a/homeassistant/components/pure_energie/sensor.py +++ b/homeassistant/components/pure_energie/sensor.py @@ -12,7 +12,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_HOST, ENERGY_KILO_WATT_HOUR, UnitOfPower +from homeassistant.const import CONF_HOST, UnitOfEnergy, UnitOfPower from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -48,7 +48,7 @@ SENSORS: tuple[PureEnergieSensorEntityDescription, ...] = ( PureEnergieSensorEntityDescription( key="energy_consumption_total", name="Energy Consumption", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, value_fn=lambda data: data.smartbridge.energy_consumption_total, @@ -56,7 +56,7 @@ SENSORS: tuple[PureEnergieSensorEntityDescription, ...] = ( PureEnergieSensorEntityDescription( key="energy_production_total", name="Energy Production", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, value_fn=lambda data: data.smartbridge.energy_production_total, diff --git a/homeassistant/components/pvoutput/sensor.py b/homeassistant/components/pvoutput/sensor.py index d4a5b408700..bf5dd76d503 100644 --- a/homeassistant/components/pvoutput/sensor.py +++ b/homeassistant/components/pvoutput/sensor.py @@ -14,10 +14,9 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ENERGY_KILO_WATT_HOUR, - ENERGY_WATT_HOUR, TEMP_CELSIUS, UnitOfElectricPotential, + UnitOfEnergy, UnitOfPower, ) from homeassistant.core import HomeAssistant @@ -47,7 +46,7 @@ SENSORS: tuple[PVOutputSensorEntityDescription, ...] = ( PVOutputSensorEntityDescription( key="energy_consumption", name="Energy consumed", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, value_fn=lambda status: status.energy_consumption, @@ -55,7 +54,7 @@ SENSORS: tuple[PVOutputSensorEntityDescription, ...] = ( PVOutputSensorEntityDescription( key="energy_generation", name="Energy generated", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, value_fn=lambda status: status.energy_generation, @@ -63,7 +62,7 @@ SENSORS: tuple[PVOutputSensorEntityDescription, ...] = ( PVOutputSensorEntityDescription( key="normalized_output", name="Efficiency", - native_unit_of_measurement=f"{ENERGY_KILO_WATT_HOUR}/{UnitOfPower.KILO_WATT}", + native_unit_of_measurement=f"{UnitOfEnergy.KILO_WATT_HOUR}/{UnitOfPower.KILO_WATT}", state_class=SensorStateClass.MEASUREMENT, value_fn=lambda status: status.normalized_output, ), diff --git a/homeassistant/components/pvpc_hourly_pricing/sensor.py b/homeassistant/components/pvpc_hourly_pricing/sensor.py index 8cfae034bff..7419b8eef46 100644 --- a/homeassistant/components/pvpc_hourly_pricing/sensor.py +++ b/homeassistant/components/pvpc_hourly_pricing/sensor.py @@ -12,7 +12,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_NAME, CURRENCY_EURO, ENERGY_KILO_WATT_HOUR +from homeassistant.const import CONF_NAME, CURRENCY_EURO, UnitOfEnergy from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.device_registry import DeviceEntryType from homeassistant.helpers.entity import DeviceInfo @@ -30,7 +30,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="PVPC", icon="mdi:currency-eur", - native_unit_of_measurement=f"{CURRENCY_EURO}/{ENERGY_KILO_WATT_HOUR}", + native_unit_of_measurement=f"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}", state_class=SensorStateClass.MEASUREMENT, ), ) diff --git a/homeassistant/components/rainforest_eagle/sensor.py b/homeassistant/components/rainforest_eagle/sensor.py index c2b7cab9d47..0680aa7455d 100644 --- a/homeassistant/components/rainforest_eagle/sensor.py +++ b/homeassistant/components/rainforest_eagle/sensor.py @@ -8,7 +8,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ENERGY_KILO_WATT_HOUR, UnitOfPower +from homeassistant.const import UnitOfEnergy, UnitOfPower from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -30,14 +30,14 @@ SENSORS = ( SensorEntityDescription( key="zigbee:CurrentSummationDelivered", name="Eagle-200 Total Meter Energy Delivered", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), SensorEntityDescription( key="zigbee:CurrentSummationReceived", name="Eagle-200 Total Meter Energy Received", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), @@ -58,7 +58,7 @@ async def async_setup_entry( SensorEntityDescription( key="zigbee:Price", name="Meter Price", - native_unit_of_measurement=f"{coordinator.data['zigbee:PriceCurrency']}/{ENERGY_KILO_WATT_HOUR}", + native_unit_of_measurement=f"{coordinator.data['zigbee:PriceCurrency']}/{UnitOfEnergy.KILO_WATT_HOUR}", state_class=SensorStateClass.MEASUREMENT, ), ) diff --git a/homeassistant/components/renault/sensor.py b/homeassistant/components/renault/sensor.py index d2204587549..21f9dacb46b 100644 --- a/homeassistant/components/renault/sensor.py +++ b/homeassistant/components/renault/sensor.py @@ -23,10 +23,10 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ENERGY_KILO_WATT_HOUR, PERCENTAGE, TEMP_CELSIUS, TIME_MINUTES, + UnitOfEnergy, UnitOfLength, UnitOfPower, UnitOfVolume, @@ -256,7 +256,7 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription[Any], ...] = ( entity_class=RenaultSensor[KamereonVehicleBatteryStatusData], device_class=SensorDeviceClass.ENERGY, name="Battery available energy", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, state_class=SensorStateClass.MEASUREMENT, ), RenaultSensorEntityDescription( diff --git a/homeassistant/components/shelly/sensor.py b/homeassistant/components/shelly/sensor.py index 9ee8836eb88..79646ab5f95 100644 --- a/homeassistant/components/shelly/sensor.py +++ b/homeassistant/components/shelly/sensor.py @@ -18,12 +18,12 @@ from homeassistant.const import ( CONCENTRATION_PARTS_PER_MILLION, DEGREE, ELECTRIC_CURRENT_AMPERE, - ENERGY_KILO_WATT_HOUR, LIGHT_LUX, PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, TEMP_CELSIUS, UnitOfElectricPotential, + UnitOfEnergy, UnitOfPower, ) from homeassistant.core import HomeAssistant @@ -163,7 +163,7 @@ SENSORS: Final = { ("device", "energy"): BlockSensorDescription( key="device|energy", name="Energy", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, value=lambda value: round(value / 60 / 1000, 2), device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -171,7 +171,7 @@ SENSORS: Final = { ("emeter", "energy"): BlockSensorDescription( key="emeter|energy", name="Energy", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, value=lambda value: round(value / 1000, 2), device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -180,7 +180,7 @@ SENSORS: Final = { ("emeter", "energyReturned"): BlockSensorDescription( key="emeter|energyReturned", name="Energy Returned", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, value=lambda value: round(value / 1000, 2), device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -189,7 +189,7 @@ SENSORS: Final = { ("light", "energy"): BlockSensorDescription( key="light|energy", name="Energy", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, value=lambda value: round(value / 60 / 1000, 2), device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -198,7 +198,7 @@ SENSORS: Final = { ("relay", "energy"): BlockSensorDescription( key="relay|energy", name="Energy", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, value=lambda value: round(value / 60 / 1000, 2), device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -206,7 +206,7 @@ SENSORS: Final = { ("roller", "rollerEnergy"): BlockSensorDescription( key="roller|rollerEnergy", name="Energy", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, value=lambda value: round(value / 60 / 1000, 2), device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -336,7 +336,7 @@ RPC_SENSORS: Final = { key="switch", sub_key="aenergy", name="Energy", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, value=lambda status, _: round(status["total"] / 1000, 2), device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, diff --git a/homeassistant/components/sma/sensor.py b/homeassistant/components/sma/sensor.py index df56757db5b..2987d2648c2 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, UnitOfPower +from homeassistant.const import UnitOfEnergy, UnitOfPower from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -70,7 +70,7 @@ class SMAsensor(CoordinatorEntity, SensorEntity): self._config_entry_unique_id = config_entry_unique_id self._attr_device_info = device_info - if self.native_unit_of_measurement == ENERGY_KILO_WATT_HOUR: + if self.native_unit_of_measurement == UnitOfEnergy.KILO_WATT_HOUR: self._attr_state_class = SensorStateClass.TOTAL_INCREASING self._attr_device_class = SensorDeviceClass.ENERGY if self.native_unit_of_measurement == UnitOfPower.WATT: diff --git a/homeassistant/components/smappee/sensor.py b/homeassistant/components/smappee/sensor.py index 9c6e26c26b0..951aab1bde1 100644 --- a/homeassistant/components/smappee/sensor.py +++ b/homeassistant/components/smappee/sensor.py @@ -10,12 +10,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ( - ENERGY_KILO_WATT_HOUR, - ENERGY_WATT_HOUR, - UnitOfElectricPotential, - UnitOfPower, -) +from homeassistant.const import UnitOfElectricPotential, UnitOfEnergy, UnitOfPower from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -70,7 +65,7 @@ TREND_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( SmappeePollingSensorEntityDescription( key="power_today", name="Total consumption - Today", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, sensor_id="power_today", device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -78,7 +73,7 @@ TREND_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( SmappeePollingSensorEntityDescription( key="power_current_hour", name="Total consumption - Current hour", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, sensor_id="power_current_hour", device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -86,7 +81,7 @@ TREND_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( SmappeePollingSensorEntityDescription( key="power_last_5_minutes", name="Total consumption - Last 5 minutes", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, sensor_id="power_last_5_minutes", device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -94,7 +89,7 @@ TREND_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( SmappeePollingSensorEntityDescription( key="alwayson_today", name="Always on - Today", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, sensor_id="alwayson_today", device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -123,7 +118,7 @@ SOLAR_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( SmappeePollingSensorEntityDescription( key="solar_today", name="Total production - Today", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, sensor_id="solar_today", device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -131,7 +126,7 @@ SOLAR_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( SmappeePollingSensorEntityDescription( key="solar_current_hour", name="Total production - Current hour", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, sensor_id="solar_current_hour", device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, @@ -317,7 +312,7 @@ async def async_setup_entry( description=SmappeeSensorEntityDescription( key="switch", name=f"{actuator.name} - energy today", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, sensor_id=actuator_id, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, diff --git a/homeassistant/components/smart_meter_texas/sensor.py b/homeassistant/components/smart_meter_texas/sensor.py index 3ebfc643dfa..57a88f7a409 100644 --- a/homeassistant/components/smart_meter_texas/sensor.py +++ b/homeassistant/components/smart_meter_texas/sensor.py @@ -7,7 +7,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_ADDRESS, ENERGY_KILO_WATT_HOUR +from homeassistant.const import CONF_ADDRESS, UnitOfEnergy from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.restore_state import RestoreEntity @@ -45,7 +45,7 @@ class SmartMeterTexasSensor(CoordinatorEntity, RestoreEntity, SensorEntity): _attr_device_class = SensorDeviceClass.ENERGY _attr_state_class = SensorStateClass.TOTAL_INCREASING - _attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR + _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR def __init__(self, meter: Meter, coordinator: DataUpdateCoordinator) -> None: """Initialize the sensor.""" diff --git a/homeassistant/components/solaredge/const.py b/homeassistant/components/solaredge/const.py index b4536a30d99..6d95f8b6aec 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, UnitOfPower +from homeassistant.const import PERCENTAGE, UnitOfEnergy, UnitOfPower from .models import SolarEdgeSensorEntityDescription @@ -34,7 +34,7 @@ SENSOR_TYPES = [ name="Lifetime energy", icon="mdi:solar-power", state_class=SensorStateClass.TOTAL, - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( @@ -43,7 +43,7 @@ SENSOR_TYPES = [ name="Energy this year", entity_registry_enabled_default=False, icon="mdi:solar-power", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( @@ -52,7 +52,7 @@ SENSOR_TYPES = [ name="Energy this month", entity_registry_enabled_default=False, icon="mdi:solar-power", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( @@ -61,7 +61,7 @@ SENSOR_TYPES = [ name="Energy today", entity_registry_enabled_default=False, icon="mdi:solar-power", - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( @@ -143,7 +143,7 @@ SENSOR_TYPES = [ name="Imported Energy", entity_registry_enabled_default=False, state_class=SensorStateClass.TOTAL_INCREASING, - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( @@ -152,7 +152,7 @@ SENSOR_TYPES = [ name="Production Energy", entity_registry_enabled_default=False, state_class=SensorStateClass.TOTAL_INCREASING, - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( @@ -161,7 +161,7 @@ SENSOR_TYPES = [ name="Consumption Energy", entity_registry_enabled_default=False, state_class=SensorStateClass.TOTAL_INCREASING, - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( @@ -170,7 +170,7 @@ SENSOR_TYPES = [ name="SelfConsumption Energy", entity_registry_enabled_default=False, state_class=SensorStateClass.TOTAL_INCREASING, - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( @@ -179,7 +179,7 @@ SENSOR_TYPES = [ name="Exported Energy", entity_registry_enabled_default=False, state_class=SensorStateClass.TOTAL_INCREASING, - native_unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( diff --git a/homeassistant/components/solax/sensor.py b/homeassistant/components/solax/sensor.py index 919d09d9780..6803435bc36 100644 --- a/homeassistant/components/solax/sensor.py +++ b/homeassistant/components/solax/sensor.py @@ -17,10 +17,10 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ELECTRIC_CURRENT_AMPERE, - ENERGY_KILO_WATT_HOUR, PERCENTAGE, TEMP_CELSIUS, UnitOfElectricPotential, + UnitOfEnergy, UnitOfFrequency, UnitOfPower, ) @@ -46,13 +46,13 @@ SENSOR_DESCRIPTIONS: dict[tuple[Units, bool], SensorEntityDescription] = { (Units.KWH, False): SensorEntityDescription( key=f"{Units.KWH}_{False}", device_class=SensorDeviceClass.ENERGY, - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, state_class=SensorStateClass.MEASUREMENT, ), (Units.KWH, True): SensorEntityDescription( key=f"{Units.KWH}_{True}", device_class=SensorDeviceClass.ENERGY, - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, state_class=SensorStateClass.TOTAL_INCREASING, ), (Units.V, False): SensorEntityDescription( diff --git a/homeassistant/components/spider/sensor.py b/homeassistant/components/spider/sensor.py index 35b6513528f..259c0fa4974 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, UnitOfPower +from homeassistant.const import UnitOfEnergy, UnitOfPower from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -32,7 +32,7 @@ async def async_setup_entry( class SpiderPowerPlugEnergy(SensorEntity): """Representation of a Spider Power Plug (energy).""" - _attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR + _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR _attr_device_class = SensorDeviceClass.ENERGY _attr_state_class = SensorStateClass.TOTAL_INCREASING diff --git a/homeassistant/components/srp_energy/sensor.py b/homeassistant/components/srp_energy/sensor.py index 61b9938e474..c4c7ec728e0 100644 --- a/homeassistant/components/srp_energy/sensor.py +++ b/homeassistant/components/srp_energy/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 +from homeassistant.const import UnitOfEnergy from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed @@ -91,7 +91,7 @@ class SrpEntity(SensorEntity): self._name = SENSOR_NAME self.type = SENSOR_TYPE self.coordinator = coordinator - self._unit_of_measurement = ENERGY_KILO_WATT_HOUR + self._unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR self._state = None @property diff --git a/homeassistant/components/tasmota/sensor.py b/homeassistant/components/tasmota/sensor.py index 3d66a5bb2c9..bddebaab491 100644 --- a/homeassistant/components/tasmota/sensor.py +++ b/homeassistant/components/tasmota/sensor.py @@ -20,7 +20,6 @@ from homeassistant.const import ( CONCENTRATION_PARTS_PER_BILLION, CONCENTRATION_PARTS_PER_MILLION, ELECTRIC_CURRENT_AMPERE, - ENERGY_KILO_WATT_HOUR, LIGHT_LUX, PERCENTAGE, PRESSURE_HPA, @@ -34,6 +33,7 @@ from homeassistant.const import ( TEMP_KELVIN, UnitOfApparentPower, UnitOfElectricPotential, + UnitOfEnergy, UnitOfFrequency, UnitOfLength, UnitOfMass, @@ -215,7 +215,7 @@ SENSOR_UNIT_MAP = { hc.CONCENTRATION_PARTS_PER_MILLION: CONCENTRATION_PARTS_PER_MILLION, hc.ELECTRICAL_CURRENT_AMPERE: ELECTRIC_CURRENT_AMPERE, hc.ELECTRICAL_VOLT_AMPERE: UnitOfApparentPower.VOLT_AMPERE, - hc.ENERGY_KILO_WATT_HOUR: ENERGY_KILO_WATT_HOUR, + hc.ENERGY_KILO_WATT_HOUR: UnitOfEnergy.KILO_WATT_HOUR, hc.FREQUENCY_HERTZ: UnitOfFrequency.HERTZ, hc.LENGTH_CENTIMETERS: UnitOfLength.CENTIMETERS, hc.LIGHT_LUX: LIGHT_LUX, diff --git a/homeassistant/components/toon/sensor.py b/homeassistant/components/toon/sensor.py index 68ce4440279..2ac413b57a5 100644 --- a/homeassistant/components/toon/sensor.py +++ b/homeassistant/components/toon/sensor.py @@ -11,9 +11,9 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ENERGY_KILO_WATT_HOUR, PERCENTAGE, TEMP_CELSIUS, + UnitOfEnergy, UnitOfPower, UnitOfVolume, ) @@ -222,7 +222,7 @@ SENSOR_ENTITIES: tuple[ToonSensorEntityDescription, ...] = ( name="Average Daily Energy Usage", section="power_usage", measurement="day_average", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, entity_registry_enabled_default=False, cls=ToonElectricityMeterDeviceSensor, @@ -243,7 +243,7 @@ SENSOR_ENTITIES: tuple[ToonSensorEntityDescription, ...] = ( name="Energy Usage Today", section="power_usage", measurement="day_usage", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, cls=ToonElectricityMeterDeviceSensor, ), @@ -252,7 +252,7 @@ SENSOR_ENTITIES: tuple[ToonSensorEntityDescription, ...] = ( name="Electricity Meter Feed IN Tariff 1", section="power_usage", measurement="meter_high", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, cls=ToonElectricityMeterDeviceSensor, @@ -262,7 +262,7 @@ SENSOR_ENTITIES: tuple[ToonSensorEntityDescription, ...] = ( name="Electricity Meter Feed IN Tariff 2", section="power_usage", measurement="meter_low", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, cls=ToonElectricityMeterDeviceSensor, @@ -282,7 +282,7 @@ SENSOR_ENTITIES: tuple[ToonSensorEntityDescription, ...] = ( name="Electricity Meter Feed OUT Tariff 1", section="power_usage", measurement="meter_produced_high", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, cls=ToonElectricityMeterDeviceSensor, @@ -292,7 +292,7 @@ SENSOR_ENTITIES: tuple[ToonSensorEntityDescription, ...] = ( name="Electricity Meter Feed OUT Tariff 2", section="power_usage", measurement="meter_produced_low", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, cls=ToonElectricityMeterDeviceSensor, @@ -401,7 +401,7 @@ SENSOR_ENTITIES_SOLAR: tuple[ToonSensorEntityDescription, ...] = ( name="Solar Energy Produced Today", section="power_usage", measurement="day_produced_solar", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, cls=ToonSolarDeviceSensor, @@ -411,7 +411,7 @@ SENSOR_ENTITIES_SOLAR: tuple[ToonSensorEntityDescription, ...] = ( name="Energy Produced To Grid Today", section="power_usage", measurement="day_to_grid_usage", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, entity_registry_enabled_default=False, cls=ToonSolarDeviceSensor, @@ -421,7 +421,7 @@ SENSOR_ENTITIES_SOLAR: tuple[ToonSensorEntityDescription, ...] = ( name="Energy Usage From Grid Today", section="power_usage", measurement="day_from_grid_usage", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, entity_registry_enabled_default=False, cls=ToonSolarDeviceSensor, diff --git a/homeassistant/components/tplink/sensor.py b/homeassistant/components/tplink/sensor.py index ef072dd02a1..54c36740ab9 100644 --- a/homeassistant/components/tplink/sensor.py +++ b/homeassistant/components/tplink/sensor.py @@ -16,8 +16,8 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_VOLTAGE, ELECTRIC_CURRENT_AMPERE, - ENERGY_KILO_WATT_HOUR, UnitOfElectricPotential, + UnitOfEnergy, UnitOfPower, ) from homeassistant.core import HomeAssistant @@ -55,7 +55,7 @@ ENERGY_SENSORS: tuple[TPLinkSensorEntityDescription, ...] = ( ), TPLinkSensorEntityDescription( key=ATTR_TOTAL_ENERGY_KWH, - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, name="Total Consumption", @@ -64,7 +64,7 @@ ENERGY_SENSORS: tuple[TPLinkSensorEntityDescription, ...] = ( ), TPLinkSensorEntityDescription( key=ATTR_TODAY_ENERGY_KWH, - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, name="Today's Consumption", diff --git a/homeassistant/components/tuya/const.py b/homeassistant/components/tuya/const.py index abc5519a000..677ffa455e6 100644 --- a/homeassistant/components/tuya/const.py +++ b/homeassistant/components/tuya/const.py @@ -16,8 +16,6 @@ from homeassistant.const import ( CONCENTRATION_PARTS_PER_MILLION, ELECTRIC_CURRENT_AMPERE, ELECTRIC_CURRENT_MILLIAMPERE, - ENERGY_KILO_WATT_HOUR, - ENERGY_WATT_HOUR, LIGHT_LUX, PERCENTAGE, PRESSURE_BAR, @@ -34,6 +32,7 @@ from homeassistant.const import ( VOLUME_CUBIC_METERS, Platform, UnitOfElectricPotential, + UnitOfEnergy, UnitOfPower, ) @@ -441,12 +440,12 @@ UNITS = ( conversion_fn=lambda x: x / 1000, ), UnitOfMeasurement( - unit=ENERGY_WATT_HOUR, + unit=UnitOfEnergy.WATT_HOUR, aliases={"wh", "watthour"}, device_classes={SensorDeviceClass.ENERGY}, ), UnitOfMeasurement( - unit=ENERGY_KILO_WATT_HOUR, + unit=UnitOfEnergy.KILO_WATT_HOUR, aliases={"kwh", "kilowatt-hour", "kW·h"}, device_classes={SensorDeviceClass.ENERGY}, ), diff --git a/homeassistant/components/utility_meter/sensor.py b/homeassistant/components/utility_meter/sensor.py index e1f5ef052e0..04909c1b7ae 100644 --- a/homeassistant/components/utility_meter/sensor.py +++ b/homeassistant/components/utility_meter/sensor.py @@ -22,10 +22,9 @@ from homeassistant.const import ( ATTR_UNIT_OF_MEASUREMENT, CONF_NAME, CONF_UNIQUE_ID, - ENERGY_KILO_WATT_HOUR, - ENERGY_WATT_HOUR, STATE_UNAVAILABLE, STATE_UNKNOWN, + UnitOfEnergy, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import entity_platform, entity_registry as er @@ -88,8 +87,8 @@ ATTR_LAST_PERIOD = "last_period" ATTR_TARIFF = "tariff" DEVICE_CLASS_MAP = { - ENERGY_WATT_HOUR: SensorDeviceClass.ENERGY, - ENERGY_KILO_WATT_HOUR: SensorDeviceClass.ENERGY, + UnitOfEnergy.WATT_HOUR: SensorDeviceClass.ENERGY, + UnitOfEnergy.KILO_WATT_HOUR: SensorDeviceClass.ENERGY, } ICON = "mdi:counter" diff --git a/homeassistant/components/vesync/sensor.py b/homeassistant/components/vesync/sensor.py index f9736619b65..10fd9ef1442 100644 --- a/homeassistant/components/vesync/sensor.py +++ b/homeassistant/components/vesync/sensor.py @@ -18,9 +18,9 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, - ENERGY_KILO_WATT_HOUR, PERCENTAGE, UnitOfElectricPotential, + UnitOfEnergy, UnitOfPower, ) from homeassistant.core import HomeAssistant, callback @@ -115,7 +115,7 @@ SENSORS: tuple[VeSyncSensorEntityDescription, ...] = ( key="energy", name="energy use today", device_class=SensorDeviceClass.ENERGY, - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, state_class=SensorStateClass.TOTAL_INCREASING, value_fn=lambda device: device.energy_today, update_fn=update_energy, @@ -125,7 +125,7 @@ SENSORS: tuple[VeSyncSensorEntityDescription, ...] = ( key="energy-weekly", name="energy use weekly", device_class=SensorDeviceClass.ENERGY, - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, state_class=SensorStateClass.TOTAL_INCREASING, value_fn=lambda device: device.weekly_energy_total, update_fn=update_energy, @@ -135,7 +135,7 @@ SENSORS: tuple[VeSyncSensorEntityDescription, ...] = ( key="energy-monthly", name="energy use monthly", device_class=SensorDeviceClass.ENERGY, - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, state_class=SensorStateClass.TOTAL_INCREASING, value_fn=lambda device: device.monthly_energy_total, update_fn=update_energy, @@ -145,7 +145,7 @@ SENSORS: tuple[VeSyncSensorEntityDescription, ...] = ( key="energy-yearly", name="energy use yearly", device_class=SensorDeviceClass.ENERGY, - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, state_class=SensorStateClass.TOTAL_INCREASING, value_fn=lambda device: device.yearly_energy_total, update_fn=update_energy, diff --git a/homeassistant/components/wallbox/sensor.py b/homeassistant/components/wallbox/sensor.py index 9e5b17a3111..68dffdb51c1 100644 --- a/homeassistant/components/wallbox/sensor.py +++ b/homeassistant/components/wallbox/sensor.py @@ -14,8 +14,8 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ELECTRIC_CURRENT_AMPERE, - ENERGY_KILO_WATT_HOUR, PERCENTAGE, + UnitOfEnergy, UnitOfLength, UnitOfPower, ) @@ -94,7 +94,7 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = { key=CHARGER_ADDED_ENERGY_KEY, name="Added Energy", precision=2, - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), @@ -102,7 +102,7 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = { key=CHARGER_ADDED_DISCHARGED_ENERGY_KEY, name="Discharged Energy", precision=2, - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), diff --git a/homeassistant/components/wemo/sensor.py b/homeassistant/components/wemo/sensor.py index 7ebd834579e..634d4a9e41d 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, UnitOfPower +from homeassistant.const import UnitOfEnergy, UnitOfPower from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -46,7 +46,7 @@ ATTRIBUTE_SENSORS = ( name="Today Energy", device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, key="today_kwh", unique_id_suffix="todaymw", state_conversion=lambda state: round(cast(float, state), 2), diff --git a/homeassistant/components/youless/sensor.py b/homeassistant/components/youless/sensor.py index eec5a799589..ae8b0e1691b 100644 --- a/homeassistant/components/youless/sensor.py +++ b/homeassistant/components/youless/sensor.py @@ -9,12 +9,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ( - CONF_DEVICE, - ENERGY_KILO_WATT_HOUR, - UnitOfPower, - UnitOfVolume, -) +from homeassistant.const import CONF_DEVICE, UnitOfEnergy, UnitOfPower, UnitOfVolume from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -136,7 +131,7 @@ class CurrentPowerSensor(YoulessBaseSensor): class DeliveryMeterSensor(YoulessBaseSensor): """The Youless delivery meter value sensor.""" - _attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR + _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR _attr_device_class = SensorDeviceClass.ENERGY _attr_state_class = SensorStateClass.TOTAL_INCREASING @@ -162,7 +157,7 @@ class DeliveryMeterSensor(YoulessBaseSensor): class EnergyMeterSensor(YoulessBaseSensor): """The Youless low meter value sensor.""" - _attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR + _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR _attr_device_class = SensorDeviceClass.ENERGY _attr_state_class = SensorStateClass.TOTAL_INCREASING @@ -194,7 +189,7 @@ class EnergyMeterSensor(YoulessBaseSensor): class ExtraMeterSensor(YoulessBaseSensor): """The Youless extra meter value sensor (s0).""" - _attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR + _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR _attr_device_class = SensorDeviceClass.ENERGY _attr_state_class = SensorStateClass.TOTAL_INCREASING diff --git a/homeassistant/components/zwave_me/sensor.py b/homeassistant/components/zwave_me/sensor.py index 151b9bb6cda..ac2a4c30cf9 100644 --- a/homeassistant/components/zwave_me/sensor.py +++ b/homeassistant/components/zwave_me/sensor.py @@ -15,12 +15,12 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ELECTRIC_CURRENT_AMPERE, - ENERGY_KILO_WATT_HOUR, LIGHT_LUX, PERCENTAGE, PRESSURE_KPA, TEMP_CELSIUS, UnitOfElectricPotential, + UnitOfEnergy, UnitOfPower, ) from homeassistant.core import HomeAssistant, callback @@ -78,7 +78,7 @@ SENSORS_MAP: dict[str, ZWaveMeSensorEntityDescription] = { "meterElectric_kilowatt_hour": ZWaveMeSensorEntityDescription( key="meterElectric_kilowatt_hour", device_class=SensorDeviceClass.ENERGY, - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, state_class=SensorStateClass.TOTAL_INCREASING, ), "meterElectric_power_factor": ZWaveMeSensorEntityDescription(