Add entity translations for Enphase Envoy (#97876)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Joost Lekkerkerker 2023-08-06 02:32:35 +02:00 committed by GitHub
parent 02e546e3ef
commit 3bed32f16e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 16 deletions

View file

@ -51,6 +51,7 @@ class EnvoyInverterSensorEntityDescription(
INVERTER_SENSORS = ( INVERTER_SENSORS = (
EnvoyInverterSensorEntityDescription( EnvoyInverterSensorEntityDescription(
key=INVERTERS_KEY, key=INVERTERS_KEY,
name=None,
native_unit_of_measurement=UnitOfPower.WATT, native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
@ -58,7 +59,7 @@ INVERTER_SENSORS = (
), ),
EnvoyInverterSensorEntityDescription( EnvoyInverterSensorEntityDescription(
key=LAST_REPORTED_KEY, key=LAST_REPORTED_KEY,
name="Last Reported", translation_key=LAST_REPORTED_KEY,
device_class=SensorDeviceClass.TIMESTAMP, device_class=SensorDeviceClass.TIMESTAMP,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
value_fn=lambda inverter: dt_util.utc_from_timestamp(inverter.last_report_date), value_fn=lambda inverter: dt_util.utc_from_timestamp(inverter.last_report_date),
@ -83,7 +84,7 @@ class EnvoyProductionSensorEntityDescription(
PRODUCTION_SENSORS = ( PRODUCTION_SENSORS = (
EnvoyProductionSensorEntityDescription( EnvoyProductionSensorEntityDescription(
key="production", key="production",
name="Current Power Production", translation_key="current_power_production",
native_unit_of_measurement=UnitOfPower.WATT, native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
@ -93,7 +94,7 @@ PRODUCTION_SENSORS = (
), ),
EnvoyProductionSensorEntityDescription( EnvoyProductionSensorEntityDescription(
key="daily_production", key="daily_production",
name="Today's Energy Production", translation_key="daily_production",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
@ -103,7 +104,7 @@ PRODUCTION_SENSORS = (
), ),
EnvoyProductionSensorEntityDescription( EnvoyProductionSensorEntityDescription(
key="seven_days_production", key="seven_days_production",
name="Last Seven Days Energy Production", translation_key="seven_days_production",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
@ -112,7 +113,7 @@ PRODUCTION_SENSORS = (
), ),
EnvoyProductionSensorEntityDescription( EnvoyProductionSensorEntityDescription(
key="lifetime_production", key="lifetime_production",
name="Lifetime Energy Production", translation_key="lifetime_production",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
@ -140,7 +141,7 @@ class EnvoyConsumptionSensorEntityDescription(
CONSUMPTION_SENSORS = ( CONSUMPTION_SENSORS = (
EnvoyConsumptionSensorEntityDescription( EnvoyConsumptionSensorEntityDescription(
key="consumption", key="consumption",
name="Current Power Consumption", translation_key="current_power_consumption",
native_unit_of_measurement=UnitOfPower.WATT, native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
@ -150,7 +151,7 @@ CONSUMPTION_SENSORS = (
), ),
EnvoyConsumptionSensorEntityDescription( EnvoyConsumptionSensorEntityDescription(
key="daily_consumption", key="daily_consumption",
name="Today's Energy Consumption", translation_key="daily_consumption",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
@ -160,7 +161,7 @@ CONSUMPTION_SENSORS = (
), ),
EnvoyConsumptionSensorEntityDescription( EnvoyConsumptionSensorEntityDescription(
key="seven_days_consumption", key="seven_days_consumption",
name="Last Seven Days Energy Consumption", translation_key="seven_days_consumption",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
@ -169,7 +170,7 @@ CONSUMPTION_SENSORS = (
), ),
EnvoyConsumptionSensorEntityDescription( EnvoyConsumptionSensorEntityDescription(
key="lifetime_consumption", key="lifetime_consumption",
name="Lifetime Energy Consumption", translation_key="lifetime_consumption",
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
@ -216,6 +217,7 @@ class EnvoyEntity(CoordinatorEntity[EnphaseUpdateCoordinator], SensorEntity):
"""Envoy inverter entity.""" """Envoy inverter entity."""
_attr_icon = ICON _attr_icon = ICON
_attr_has_entity_name = True
def __init__( def __init__(
self, self,
@ -227,7 +229,6 @@ class EnvoyEntity(CoordinatorEntity[EnphaseUpdateCoordinator], SensorEntity):
envoy_name = coordinator.name envoy_name = coordinator.name
envoy_serial_num = coordinator.envoy.serial_number envoy_serial_num = coordinator.envoy.serial_number
assert envoy_serial_num is not None assert envoy_serial_num is not None
self._attr_name = f"{envoy_name} {description.name}"
self._attr_unique_id = f"{envoy_serial_num}_{description.key}" self._attr_unique_id = f"{envoy_serial_num}_{description.key}"
self._attr_device_info = DeviceInfo( self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, envoy_serial_num)}, identifiers={(DOMAIN, envoy_serial_num)},
@ -271,6 +272,7 @@ class EnvoyInverterEntity(CoordinatorEntity[EnphaseUpdateCoordinator], SensorEnt
"""Envoy inverter entity.""" """Envoy inverter entity."""
_attr_icon = ICON _attr_icon = ICON
_attr_has_entity_name = True
entity_description: EnvoyInverterSensorEntityDescription entity_description: EnvoyInverterSensorEntityDescription
def __init__( def __init__(
@ -281,20 +283,16 @@ class EnvoyInverterEntity(CoordinatorEntity[EnphaseUpdateCoordinator], SensorEnt
) -> None: ) -> None:
"""Initialize Envoy inverter entity.""" """Initialize Envoy inverter entity."""
self.entity_description = description self.entity_description = description
envoy_name = coordinator.name
self._serial_number = serial_number self._serial_number = serial_number
name = description.name
key = description.key key = description.key
if key == INVERTERS_KEY: if key == INVERTERS_KEY:
# Originally there was only one inverter sensor, so we don't want to # Originally there was only one inverter sensor, so we don't want to
# break existing installations by changing the name or unique_id. # break existing installations by changing the unique_id.
self._attr_name = f"{envoy_name} Inverter {serial_number}"
self._attr_unique_id = serial_number self._attr_unique_id = serial_number
else: else:
# Additional sensors have a name and unique_id that includes the # Additional sensors have a unique_id that includes the
# sensor key. # sensor key.
self._attr_name = f"{envoy_name} Inverter {serial_number} {name}"
self._attr_unique_id = f"{serial_number}_{key}" self._attr_unique_id = f"{serial_number}_{key}"
envoy_serial_num = coordinator.envoy.serial_number envoy_serial_num = coordinator.envoy.serial_number

View file

@ -20,5 +20,36 @@
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]", "already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]" "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
} }
},
"entity": {
"sensor": {
"last_reported": {
"name": "Last reported"
},
"current_power_production": {
"name": "Current power production"
},
"daily_production": {
"name": "Energy production today"
},
"seven_days_production": {
"name": "Energy production last seven days"
},
"lifetime_production": {
"name": "Lifetime energy production"
},
"current_power_consumption": {
"name": "Current power consumption"
},
"daily_consumption": {
"name": "Energy consumption today"
},
"seven_days_consumption": {
"name": "Energy consumption last seven days"
},
"lifetime_consumption": {
"name": "Lifetime energy consumption"
}
}
} }
} }