From 731c70a0e71a3c75c13827d8b674d6e2b4e95dc7 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 10 Dec 2021 14:52:54 +0100 Subject: [PATCH] Use new enums in forecast_solar (#61443) Co-authored-by: epenet --- .../components/forecast_solar/const.py | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/forecast_solar/const.py b/homeassistant/components/forecast_solar/const.py index 97caba531e6..63d5bd10084 100644 --- a/homeassistant/components/forecast_solar/const.py +++ b/homeassistant/components/forecast_solar/const.py @@ -3,14 +3,8 @@ from __future__ import annotations from datetime import timedelta -from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT -from homeassistant.const import ( - DEVICE_CLASS_ENERGY, - DEVICE_CLASS_POWER, - DEVICE_CLASS_TIMESTAMP, - ENERGY_KILO_WATT_HOUR, - POWER_WATT, -) +from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass +from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT from .models import ForecastSolarSensorEntityDescription @@ -26,32 +20,32 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = ( key="energy_production_today", name="Estimated Energy Production - Today", state=lambda estimate: estimate.energy_production_today / 1000, - device_class=DEVICE_CLASS_ENERGY, + device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, ), ForecastSolarSensorEntityDescription( key="energy_production_tomorrow", name="Estimated Energy Production - Tomorrow", state=lambda estimate: estimate.energy_production_tomorrow / 1000, - device_class=DEVICE_CLASS_ENERGY, + device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, ), ForecastSolarSensorEntityDescription( key="power_highest_peak_time_today", name="Highest Power Peak Time - Today", - device_class=DEVICE_CLASS_TIMESTAMP, + device_class=SensorDeviceClass.TIMESTAMP, ), ForecastSolarSensorEntityDescription( key="power_highest_peak_time_tomorrow", name="Highest Power Peak Time - Tomorrow", - device_class=DEVICE_CLASS_TIMESTAMP, + device_class=SensorDeviceClass.TIMESTAMP, ), ForecastSolarSensorEntityDescription( key="power_production_now", name="Estimated Power Production - Now", - device_class=DEVICE_CLASS_POWER, + device_class=SensorDeviceClass.POWER, state=lambda estimate: estimate.power_production_now, - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=POWER_WATT, ), ForecastSolarSensorEntityDescription( @@ -60,7 +54,7 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = ( estimate.now() + timedelta(hours=1) ), name="Estimated Power Production - Next Hour", - device_class=DEVICE_CLASS_POWER, + device_class=SensorDeviceClass.POWER, entity_registry_enabled_default=False, native_unit_of_measurement=POWER_WATT, ), @@ -70,7 +64,7 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = ( estimate.now() + timedelta(hours=12) ), name="Estimated Power Production - Next 12 Hours", - device_class=DEVICE_CLASS_POWER, + device_class=SensorDeviceClass.POWER, entity_registry_enabled_default=False, native_unit_of_measurement=POWER_WATT, ), @@ -80,7 +74,7 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = ( estimate.now() + timedelta(hours=24) ), name="Estimated Power Production - Next 24 Hours", - device_class=DEVICE_CLASS_POWER, + device_class=SensorDeviceClass.POWER, entity_registry_enabled_default=False, native_unit_of_measurement=POWER_WATT, ), @@ -88,14 +82,14 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = ( key="energy_current_hour", name="Estimated Energy Production - This Hour", state=lambda estimate: estimate.energy_current_hour / 1000, - device_class=DEVICE_CLASS_ENERGY, + device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, ), ForecastSolarSensorEntityDescription( key="energy_next_hour", state=lambda estimate: estimate.sum_energy_production(1) / 1000, name="Estimated Energy Production - Next Hour", - device_class=DEVICE_CLASS_ENERGY, + device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, ), )