Add entity translations to Rainforest eagle (#96031)

* Add entity translations to Rainforest eagle

* Add entity translations to Rainforest Eagle
pull/96358/head
Joost Lekkerkerker 2023-07-11 20:24:33 +02:00 committed by GitHub
parent efcaad1179
commit fe44827e3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 9 deletions

View File

@ -21,22 +21,21 @@ from .data import EagleDataCoordinator
SENSORS = (
SensorEntityDescription(
key="zigbee:InstantaneousDemand",
# We can drop the "Eagle-200" part of the name in HA 2021.12
name="Eagle-200 Meter Power Demand",
translation_key="power_demand",
native_unit_of_measurement=UnitOfPower.KILO_WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="zigbee:CurrentSummationDelivered",
name="Eagle-200 Total Meter Energy Delivered",
translation_key="total_energy_delivered",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="zigbee:CurrentSummationReceived",
name="Eagle-200 Total Meter Energy Received",
translation_key="total_energy_received",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
@ -57,7 +56,7 @@ async def async_setup_entry(
coordinator,
SensorEntityDescription(
key="zigbee:Price",
name="Meter Price",
translation_key="meter_price",
native_unit_of_measurement=f"{coordinator.data['zigbee:PriceCurrency']}/{UnitOfEnergy.KILO_WATT_HOUR}",
state_class=SensorStateClass.MEASUREMENT,
),
@ -70,6 +69,8 @@ async def async_setup_entry(
class EagleSensor(CoordinatorEntity[EagleDataCoordinator], SensorEntity):
"""Implementation of the Rainforest Eagle sensor."""
_attr_has_entity_name = True
def __init__(self, coordinator, entity_description):
"""Initialize the sensor."""
super().__init__(coordinator)

View File

@ -17,5 +17,21 @@
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
}
},
"entity": {
"sensor": {
"power_demand": {
"name": "Meter power demand"
},
"total_energy_delivered": {
"name": "Total meter energy delivered"
},
"total_energy_received": {
"name": "Total meter energy received"
},
"meter_price": {
"name": "Meter price"
}
}
}
}

View File

@ -32,7 +32,7 @@ async def test_sensors_200(hass: HomeAssistant, setup_rainforest_200) -> None:
assert len(hass.states.async_all()) == 4
price = hass.states.get("sensor.meter_price")
price = hass.states.get("sensor.eagle_200_meter_price")
assert price is not None
assert price.state == "0.053990"
assert price.attributes["unit_of_measurement"] == "USD/kWh"
@ -42,17 +42,17 @@ async def test_sensors_100(hass: HomeAssistant, setup_rainforest_100) -> None:
"""Test the sensors."""
assert len(hass.states.async_all()) == 3
demand = hass.states.get("sensor.eagle_200_meter_power_demand")
demand = hass.states.get("sensor.eagle_100_meter_power_demand")
assert demand is not None
assert demand.state == "1.152000"
assert demand.attributes["unit_of_measurement"] == "kW"
delivered = hass.states.get("sensor.eagle_200_total_meter_energy_delivered")
delivered = hass.states.get("sensor.eagle_100_total_meter_energy_delivered")
assert delivered is not None
assert delivered.state == "45251.285000"
assert delivered.attributes["unit_of_measurement"] == "kWh"
received = hass.states.get("sensor.eagle_200_total_meter_energy_received")
received = hass.states.get("sensor.eagle_100_total_meter_energy_received")
assert received is not None
assert received.state == "232.232000"
assert received.attributes["unit_of_measurement"] == "kWh"