Add Enphase Encharge aggregate sensors (#98276)
* Add Encharge aggregate sensors * Update dependency
This commit is contained in:
parent
58194a5eb4
commit
8912b19cf4
5 changed files with 89 additions and 3 deletions
|
@ -6,7 +6,7 @@
|
||||||
"documentation": "https://www.home-assistant.io/integrations/enphase_envoy",
|
"documentation": "https://www.home-assistant.io/integrations/enphase_envoy",
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
"loggers": ["pyenphase"],
|
"loggers": ["pyenphase"],
|
||||||
"requirements": ["pyenphase==1.4.0"],
|
"requirements": ["pyenphase==1.5.2"],
|
||||||
"zeroconf": [
|
"zeroconf": [
|
||||||
{
|
{
|
||||||
"type": "_enphase-envoy._tcp.local."
|
"type": "_enphase-envoy._tcp.local."
|
||||||
|
|
|
@ -8,6 +8,7 @@ import logging
|
||||||
|
|
||||||
from pyenphase import (
|
from pyenphase import (
|
||||||
EnvoyEncharge,
|
EnvoyEncharge,
|
||||||
|
EnvoyEnchargeAggregate,
|
||||||
EnvoyEnchargePower,
|
EnvoyEnchargePower,
|
||||||
EnvoyEnpower,
|
EnvoyEnpower,
|
||||||
EnvoyInverter,
|
EnvoyInverter,
|
||||||
|
@ -288,6 +289,58 @@ ENPOWER_SENSORS = (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class EnvoyEnchargeAggregateRequiredKeysMixin:
|
||||||
|
"""Mixin for required keys."""
|
||||||
|
|
||||||
|
value_fn: Callable[[EnvoyEnchargeAggregate], int]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class EnvoyEnchargeAggregateSensorEntityDescription(
|
||||||
|
SensorEntityDescription, EnvoyEnchargeAggregateRequiredKeysMixin
|
||||||
|
):
|
||||||
|
"""Describes an Envoy Encharge sensor entity."""
|
||||||
|
|
||||||
|
|
||||||
|
ENCHARGE_AGGREGATE_SENSORS = (
|
||||||
|
EnvoyEnchargeAggregateSensorEntityDescription(
|
||||||
|
key="battery_level",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
device_class=SensorDeviceClass.BATTERY,
|
||||||
|
value_fn=lambda encharge: encharge.state_of_charge,
|
||||||
|
),
|
||||||
|
EnvoyEnchargeAggregateSensorEntityDescription(
|
||||||
|
key="reserve_soc",
|
||||||
|
translation_key="reserve_soc",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
device_class=SensorDeviceClass.BATTERY,
|
||||||
|
value_fn=lambda encharge: encharge.reserve_state_of_charge,
|
||||||
|
),
|
||||||
|
EnvoyEnchargeAggregateSensorEntityDescription(
|
||||||
|
key="available_energy",
|
||||||
|
translation_key="available_energy",
|
||||||
|
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
||||||
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
|
value_fn=lambda encharge: encharge.available_energy,
|
||||||
|
),
|
||||||
|
EnvoyEnchargeAggregateSensorEntityDescription(
|
||||||
|
key="reserve_energy",
|
||||||
|
translation_key="reserve_energy",
|
||||||
|
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
||||||
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
|
value_fn=lambda encharge: encharge.backup_reserve,
|
||||||
|
),
|
||||||
|
EnvoyEnchargeAggregateSensorEntityDescription(
|
||||||
|
key="max_capacity",
|
||||||
|
translation_key="max_capacity",
|
||||||
|
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
||||||
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
|
value_fn=lambda encharge: encharge.max_available_capacity,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
|
@ -329,6 +382,11 @@ async def async_setup_entry(
|
||||||
for description in ENCHARGE_POWER_SENSORS
|
for description in ENCHARGE_POWER_SENSORS
|
||||||
for encharge in envoy_data.encharge_power
|
for encharge in envoy_data.encharge_power
|
||||||
)
|
)
|
||||||
|
if envoy_data.encharge_aggregate:
|
||||||
|
entities.extend(
|
||||||
|
EnvoyEnchargeAggregateEntity(coordinator, description)
|
||||||
|
for description in ENCHARGE_AGGREGATE_SENSORS
|
||||||
|
)
|
||||||
if envoy_data.enpower:
|
if envoy_data.enpower:
|
||||||
entities.extend(
|
entities.extend(
|
||||||
EnvoyEnpowerEntity(coordinator, description)
|
EnvoyEnpowerEntity(coordinator, description)
|
||||||
|
@ -482,6 +540,19 @@ class EnvoyEnchargePowerEntity(EnvoyEnchargeEntity):
|
||||||
return self.entity_description.value_fn(encharge_power[self._serial_number])
|
return self.entity_description.value_fn(encharge_power[self._serial_number])
|
||||||
|
|
||||||
|
|
||||||
|
class EnvoyEnchargeAggregateEntity(EnvoySystemSensorEntity):
|
||||||
|
"""Envoy Encharge Aggregate sensor entity."""
|
||||||
|
|
||||||
|
entity_description: EnvoyEnchargeAggregateSensorEntityDescription
|
||||||
|
|
||||||
|
@property
|
||||||
|
def native_value(self) -> int:
|
||||||
|
"""Return the state of the aggregate sensors."""
|
||||||
|
encharge_aggregate = self.data.encharge_aggregate
|
||||||
|
assert encharge_aggregate is not None
|
||||||
|
return self.entity_description.value_fn(encharge_aggregate)
|
||||||
|
|
||||||
|
|
||||||
class EnvoyEnpowerEntity(EnvoySensorBaseEntity):
|
class EnvoyEnpowerEntity(EnvoySensorBaseEntity):
|
||||||
"""Envoy Enpower sensor entity."""
|
"""Envoy Enpower sensor entity."""
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,21 @@
|
||||||
},
|
},
|
||||||
"lifetime_consumption": {
|
"lifetime_consumption": {
|
||||||
"name": "Lifetime energy consumption"
|
"name": "Lifetime energy consumption"
|
||||||
|
},
|
||||||
|
"reserve_soc": {
|
||||||
|
"name": "Reserve battery level"
|
||||||
|
},
|
||||||
|
"available_energy": {
|
||||||
|
"name": "Available battery energy"
|
||||||
|
},
|
||||||
|
"reserve_energy": {
|
||||||
|
"name": "Reserve battery energy"
|
||||||
|
},
|
||||||
|
"max_capacity": {
|
||||||
|
"name": "Battery capacity"
|
||||||
|
},
|
||||||
|
"configured_reserve_soc": {
|
||||||
|
"name": "Configured reserve battery level"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"switch": {
|
"switch": {
|
||||||
|
|
|
@ -1665,7 +1665,7 @@ pyedimax==0.2.1
|
||||||
pyefergy==22.1.1
|
pyefergy==22.1.1
|
||||||
|
|
||||||
# homeassistant.components.enphase_envoy
|
# homeassistant.components.enphase_envoy
|
||||||
pyenphase==1.4.0
|
pyenphase==1.5.2
|
||||||
|
|
||||||
# homeassistant.components.envisalink
|
# homeassistant.components.envisalink
|
||||||
pyenvisalink==4.6
|
pyenvisalink==4.6
|
||||||
|
|
|
@ -1229,7 +1229,7 @@ pyeconet==0.1.20
|
||||||
pyefergy==22.1.1
|
pyefergy==22.1.1
|
||||||
|
|
||||||
# homeassistant.components.enphase_envoy
|
# homeassistant.components.enphase_envoy
|
||||||
pyenphase==1.4.0
|
pyenphase==1.5.2
|
||||||
|
|
||||||
# homeassistant.components.everlights
|
# homeassistant.components.everlights
|
||||||
pyeverlights==0.1.0
|
pyeverlights==0.1.0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue