Add Solar Edge entity device and state class (#55902)
This commit is contained in:
parent
41e14c4871
commit
0111b28a67
2 changed files with 34 additions and 6 deletions
|
@ -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",
|
||||
|
|
|
@ -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."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue