diff --git a/homeassistant/components/solaredge/const.py b/homeassistant/components/solaredge/const.py index 6e353ffe339..916a01de9e9 100644 --- a/homeassistant/components/solaredge/const.py +++ b/homeassistant/components/solaredge/const.py @@ -2,18 +2,8 @@ from datetime import timedelta import logging -from homeassistant.components.sensor import ( - STATE_CLASS_MEASUREMENT, - STATE_CLASS_TOTAL, - STATE_CLASS_TOTAL_INCREASING, -) -from homeassistant.const import ( - DEVICE_CLASS_ENERGY, - DEVICE_CLASS_POWER, - ENERGY_WATT_HOUR, - PERCENTAGE, - POWER_WATT, -) +from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass +from homeassistant.const import ENERGY_WATT_HOUR, PERCENTAGE, POWER_WATT from .models import SolarEdgeSensorEntityDescription @@ -43,9 +33,9 @@ SENSOR_TYPES = [ json_key="lifeTimeData", name="Lifetime energy", icon="mdi:solar-power", - state_class=STATE_CLASS_TOTAL, + state_class=SensorStateClass.TOTAL, native_unit_of_measurement=ENERGY_WATT_HOUR, - device_class=DEVICE_CLASS_ENERGY, + device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( key="energy_this_year", @@ -54,7 +44,7 @@ SENSOR_TYPES = [ entity_registry_enabled_default=False, icon="mdi:solar-power", native_unit_of_measurement=ENERGY_WATT_HOUR, - device_class=DEVICE_CLASS_ENERGY, + device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( key="energy_this_month", @@ -63,7 +53,7 @@ SENSOR_TYPES = [ entity_registry_enabled_default=False, icon="mdi:solar-power", native_unit_of_measurement=ENERGY_WATT_HOUR, - device_class=DEVICE_CLASS_ENERGY, + device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( key="energy_today", @@ -72,16 +62,16 @@ SENSOR_TYPES = [ entity_registry_enabled_default=False, icon="mdi:solar-power", native_unit_of_measurement=ENERGY_WATT_HOUR, - device_class=DEVICE_CLASS_ENERGY, + device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( key="current_power", json_key="currentPower", name="Current Power", icon="mdi:solar-power", - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=POWER_WATT, - device_class=DEVICE_CLASS_POWER, + device_class=SensorDeviceClass.POWER, ), SolarEdgeSensorEntityDescription( key="site_details", @@ -151,52 +141,52 @@ SENSOR_TYPES = [ json_key="Purchased", name="Imported Energy", entity_registry_enabled_default=False, - state_class=STATE_CLASS_TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL_INCREASING, native_unit_of_measurement=ENERGY_WATT_HOUR, - device_class=DEVICE_CLASS_ENERGY, + device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( key="production_energy", json_key="Production", name="Production Energy", entity_registry_enabled_default=False, - state_class=STATE_CLASS_TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL_INCREASING, native_unit_of_measurement=ENERGY_WATT_HOUR, - device_class=DEVICE_CLASS_ENERGY, + device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( key="consumption_energy", json_key="Consumption", name="Consumption Energy", entity_registry_enabled_default=False, - state_class=STATE_CLASS_TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL_INCREASING, native_unit_of_measurement=ENERGY_WATT_HOUR, - device_class=DEVICE_CLASS_ENERGY, + device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( key="selfconsumption_energy", json_key="SelfConsumption", name="SelfConsumption Energy", entity_registry_enabled_default=False, - state_class=STATE_CLASS_TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL_INCREASING, native_unit_of_measurement=ENERGY_WATT_HOUR, - device_class=DEVICE_CLASS_ENERGY, + device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( key="feedin_energy", json_key="FeedIn", name="Exported Energy", entity_registry_enabled_default=False, - state_class=STATE_CLASS_TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL_INCREASING, native_unit_of_measurement=ENERGY_WATT_HOUR, - device_class=DEVICE_CLASS_ENERGY, + device_class=SensorDeviceClass.ENERGY, ), SolarEdgeSensorEntityDescription( key="storage_level", json_key="STORAGE", name="Storage Level", entity_registry_enabled_default=False, - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=PERCENTAGE, ), ] diff --git a/homeassistant/components/solaredge/sensor.py b/homeassistant/components/solaredge/sensor.py index a151a50a9c8..a769a043442 100644 --- a/homeassistant/components/solaredge/sensor.py +++ b/homeassistant/components/solaredge/sensor.py @@ -5,9 +5,8 @@ from typing import Any from solaredge import Solaredge -from homeassistant.components.sensor import SensorEntity +from homeassistant.components.sensor import SensorDeviceClass, SensorEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import DEVICE_CLASS_BATTERY, DEVICE_CLASS_POWER from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -203,7 +202,7 @@ class SolarEdgeEnergyDetailsSensor(SolarEdgeSensorEntity): class SolarEdgePowerFlowSensor(SolarEdgeSensorEntity): """Representation of an SolarEdge Monitoring API power flow sensor.""" - _attr_device_class = DEVICE_CLASS_POWER + _attr_device_class = SensorDeviceClass.POWER def __init__( self, @@ -230,7 +229,7 @@ class SolarEdgePowerFlowSensor(SolarEdgeSensorEntity): class SolarEdgeStorageLevelSensor(SolarEdgeSensorEntity): """Representation of an SolarEdge Monitoring API storage level sensor.""" - _attr_device_class = DEVICE_CLASS_BATTERY + _attr_device_class = SensorDeviceClass.BATTERY @property def native_value(self) -> str | None: