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
|
from datetime import timedelta
|
||||||
import logging
|
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 (
|
from homeassistant.const import (
|
||||||
DEVICE_CLASS_ENERGY,
|
DEVICE_CLASS_ENERGY,
|
||||||
DEVICE_CLASS_POWER,
|
DEVICE_CLASS_POWER,
|
||||||
|
@ -147,35 +151,45 @@ SENSOR_TYPES = [
|
||||||
json_key="Purchased",
|
json_key="Purchased",
|
||||||
name="Imported Power",
|
name="Imported Power",
|
||||||
entity_registry_enabled_default=False,
|
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(
|
SolarEdgeSensorEntityDescription(
|
||||||
key="production_power",
|
key="production_power",
|
||||||
json_key="Production",
|
json_key="Production",
|
||||||
name="Production Power",
|
name="Production Power",
|
||||||
entity_registry_enabled_default=False,
|
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(
|
SolarEdgeSensorEntityDescription(
|
||||||
key="consumption_power",
|
key="consumption_power",
|
||||||
json_key="Consumption",
|
json_key="Consumption",
|
||||||
name="Consumption Power",
|
name="Consumption Power",
|
||||||
entity_registry_enabled_default=False,
|
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(
|
SolarEdgeSensorEntityDescription(
|
||||||
key="selfconsumption_power",
|
key="selfconsumption_power",
|
||||||
json_key="SelfConsumption",
|
json_key="SelfConsumption",
|
||||||
name="SelfConsumption Power",
|
name="SelfConsumption Power",
|
||||||
entity_registry_enabled_default=False,
|
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(
|
SolarEdgeSensorEntityDescription(
|
||||||
key="feedin_power",
|
key="feedin_power",
|
||||||
json_key="FeedIn",
|
json_key="FeedIn",
|
||||||
name="Exported Power",
|
name="Exported Power",
|
||||||
entity_registry_enabled_default=False,
|
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(
|
SolarEdgeSensorEntityDescription(
|
||||||
key="storage_level",
|
key="storage_level",
|
||||||
|
|
|
@ -128,6 +128,13 @@ class SolarEdgeSensorEntity(CoordinatorEntity, SensorEntity):
|
||||||
|
|
||||||
self._attr_name = f"{platform_name} ({description.name})"
|
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):
|
class SolarEdgeOverviewSensor(SolarEdgeSensorEntity):
|
||||||
"""Representation of an SolarEdge Monitoring API overview sensor."""
|
"""Representation of an SolarEdge Monitoring API overview sensor."""
|
||||||
|
@ -151,6 +158,13 @@ class SolarEdgeDetailsSensor(SolarEdgeSensorEntity):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self.data_service.data
|
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):
|
class SolarEdgeInventorySensor(SolarEdgeSensorEntity):
|
||||||
"""Representation of an SolarEdge Monitoring API inventory sensor."""
|
"""Representation of an SolarEdge Monitoring API inventory sensor."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue