From fa06398721cf994a35c0b6053d5fcdc6ea192489 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 12 Dec 2022 10:45:12 +0100 Subject: [PATCH] Use POWER device class in solarlog (#83822) --- homeassistant/components/solarlog/const.py | 44 +++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/solarlog/const.py b/homeassistant/components/solarlog/const.py index 769064089b2..059dab3da78 100644 --- a/homeassistant/components/solarlog/const.py +++ b/homeassistant/components/solarlog/const.py @@ -11,10 +11,10 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.const import ( - ELECTRIC_POTENTIAL_VOLT, - ENERGY_KILO_WATT_HOUR, PERCENTAGE, - POWER_WATT, + UnitOfElectricPotential, + UnitOfEnergy, + UnitOfPower, ) from homeassistant.util.dt import as_local @@ -43,27 +43,29 @@ SENSOR_TYPES: tuple[SolarLogSensorEntityDescription, ...] = ( key="power_ac", name="power AC", icon="mdi:solar-power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, + device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, ), SolarLogSensorEntityDescription( key="power_dc", name="power DC", icon="mdi:solar-power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, + device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, ), SolarLogSensorEntityDescription( key="voltage_ac", name="voltage AC", - native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, + native_unit_of_measurement=UnitOfElectricPotential.VOLT, device_class=SensorDeviceClass.VOLTAGE, state_class=SensorStateClass.MEASUREMENT, ), SolarLogSensorEntityDescription( key="voltage_dc", name="voltage DC", - native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, + native_unit_of_measurement=UnitOfElectricPotential.VOLT, device_class=SensorDeviceClass.VOLTAGE, state_class=SensorStateClass.MEASUREMENT, ), @@ -71,7 +73,7 @@ SENSOR_TYPES: tuple[SolarLogSensorEntityDescription, ...] = ( key="yield_day", name="yield day", icon="mdi:solar-power", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, value=lambda value: round(value / 1000, 3), ), @@ -79,7 +81,7 @@ SENSOR_TYPES: tuple[SolarLogSensorEntityDescription, ...] = ( key="yield_yesterday", name="yield yesterday", icon="mdi:solar-power", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, value=lambda value: round(value / 1000, 3), ), @@ -87,7 +89,7 @@ SENSOR_TYPES: tuple[SolarLogSensorEntityDescription, ...] = ( key="yield_month", name="yield month", icon="mdi:solar-power", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, value=lambda value: round(value / 1000, 3), ), @@ -95,7 +97,7 @@ SENSOR_TYPES: tuple[SolarLogSensorEntityDescription, ...] = ( key="yield_year", name="yield year", icon="mdi:solar-power", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, value=lambda value: round(value / 1000, 3), ), @@ -103,7 +105,7 @@ SENSOR_TYPES: tuple[SolarLogSensorEntityDescription, ...] = ( key="yield_total", name="yield total", icon="mdi:solar-power", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL, value=lambda value: round(value / 1000, 3), @@ -111,42 +113,42 @@ SENSOR_TYPES: tuple[SolarLogSensorEntityDescription, ...] = ( SolarLogSensorEntityDescription( key="consumption_ac", name="consumption AC", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, ), SolarLogSensorEntityDescription( key="consumption_day", name="consumption day", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, value=lambda value: round(value / 1000, 3), ), SolarLogSensorEntityDescription( key="consumption_yesterday", name="consumption yesterday", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, value=lambda value: round(value / 1000, 3), ), SolarLogSensorEntityDescription( key="consumption_month", name="consumption month", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, value=lambda value: round(value / 1000, 3), ), SolarLogSensorEntityDescription( key="consumption_year", name="consumption year", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, value=lambda value: round(value / 1000, 3), ), SolarLogSensorEntityDescription( key="consumption_total", name="consumption total", - native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL, value=lambda value: round(value / 1000, 3), @@ -155,14 +157,14 @@ SENSOR_TYPES: tuple[SolarLogSensorEntityDescription, ...] = ( key="total_power", name="installed peak power", icon="mdi:solar-power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, ), SolarLogSensorEntityDescription( key="alternator_loss", name="alternator loss", icon="mdi:solar-power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, ), @@ -187,7 +189,7 @@ SENSOR_TYPES: tuple[SolarLogSensorEntityDescription, ...] = ( key="power_available", name="power available", icon="mdi:solar-power", - native_unit_of_measurement=POWER_WATT, + native_unit_of_measurement=UnitOfPower.WATT, device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, ),