From 0111b28a67a23c4e341ec363cf94407f4cab52af Mon Sep 17 00:00:00 2001 From: terminet85 Date: Wed, 27 Oct 2021 16:42:56 +0200 Subject: [PATCH] Add Solar Edge entity device and state class (#55902) --- homeassistant/components/solaredge/const.py | 26 +++++++++++++++----- homeassistant/components/solaredge/sensor.py | 14 +++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/solaredge/const.py b/homeassistant/components/solaredge/const.py index 644f1861c05..d97c191a36b 100644 --- a/homeassistant/components/solaredge/const.py +++ b/homeassistant/components/solaredge/const.py @@ -2,7 +2,11 @@ from datetime import timedelta import logging -from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL +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, @@ -147,35 +151,45 @@ SENSOR_TYPES = [ json_key="Purchased", name="Imported Power", entity_registry_enabled_default=False, - icon="mdi:flash", + state_class=STATE_CLASS_TOTAL_INCREASING, + native_unit_of_measurement=ENERGY_WATT_HOUR, + device_class=DEVICE_CLASS_ENERGY, ), SolarEdgeSensorEntityDescription( key="production_power", json_key="Production", name="Production Power", entity_registry_enabled_default=False, - icon="mdi:flash", + state_class=STATE_CLASS_TOTAL_INCREASING, + native_unit_of_measurement=ENERGY_WATT_HOUR, + device_class=DEVICE_CLASS_ENERGY, ), SolarEdgeSensorEntityDescription( key="consumption_power", json_key="Consumption", name="Consumption Power", entity_registry_enabled_default=False, - icon="mdi:flash", + state_class=STATE_CLASS_TOTAL_INCREASING, + native_unit_of_measurement=ENERGY_WATT_HOUR, + device_class=DEVICE_CLASS_ENERGY, ), SolarEdgeSensorEntityDescription( key="selfconsumption_power", json_key="SelfConsumption", name="SelfConsumption Power", entity_registry_enabled_default=False, - icon="mdi:flash", + state_class=STATE_CLASS_TOTAL_INCREASING, + native_unit_of_measurement=ENERGY_WATT_HOUR, + device_class=DEVICE_CLASS_ENERGY, ), SolarEdgeSensorEntityDescription( key="feedin_power", json_key="FeedIn", name="Exported Power", entity_registry_enabled_default=False, - icon="mdi:flash", + state_class=STATE_CLASS_TOTAL_INCREASING, + native_unit_of_measurement=ENERGY_WATT_HOUR, + device_class=DEVICE_CLASS_ENERGY, ), SolarEdgeSensorEntityDescription( key="storage_level", diff --git a/homeassistant/components/solaredge/sensor.py b/homeassistant/components/solaredge/sensor.py index 23aa269cf36..e6c3fc3571a 100644 --- a/homeassistant/components/solaredge/sensor.py +++ b/homeassistant/components/solaredge/sensor.py @@ -128,6 +128,13 @@ class SolarEdgeSensorEntity(CoordinatorEntity, SensorEntity): self._attr_name = f"{platform_name} ({description.name})" + @property + def unique_id(self) -> str | None: + """Return a unique ID.""" + if not self.data_service.site_id: + return None + return f"{self.data_service.site_id}_{self.entity_description.key}" + class SolarEdgeOverviewSensor(SolarEdgeSensorEntity): """Representation of an SolarEdge Monitoring API overview sensor.""" @@ -151,6 +158,13 @@ class SolarEdgeDetailsSensor(SolarEdgeSensorEntity): """Return the state of the sensor.""" return self.data_service.data + @property + def unique_id(self) -> str | None: + """Return a unique ID.""" + if not self.data_service.site_id: + return None + return f"{self.data_service.site_id}" + class SolarEdgeInventorySensor(SolarEdgeSensorEntity): """Representation of an SolarEdge Monitoring API inventory sensor."""