Add entity translations to Efergy (#95291)
* Add entity translations to Efergy * Add entity translations to Efergy
This commit is contained in:
parent
b12109dcde
commit
ba244b7af7
3 changed files with 64 additions and 28 deletions
|
@ -25,14 +25,14 @@ from .const import CONF_CURRENT_VALUES, DOMAIN, LOGGER
|
|||
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||
SensorEntityDescription(
|
||||
key="instant_readings",
|
||||
name="Power Usage",
|
||||
translation_key="instant_readings",
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
native_unit_of_measurement=UnitOfPower.WATT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="energy_day",
|
||||
name="Daily Consumption",
|
||||
translation_key="energy_day",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
|
@ -40,7 +40,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||
),
|
||||
SensorEntityDescription(
|
||||
key="energy_week",
|
||||
name="Weekly Consumption",
|
||||
translation_key="energy_week",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
|
@ -48,14 +48,14 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||
),
|
||||
SensorEntityDescription(
|
||||
key="energy_month",
|
||||
name="Monthly Consumption",
|
||||
translation_key="energy_month",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="energy_year",
|
||||
name="Yearly Consumption",
|
||||
translation_key="energy_year",
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
|
@ -63,32 +63,32 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||
),
|
||||
SensorEntityDescription(
|
||||
key="budget",
|
||||
name="Energy Budget",
|
||||
translation_key="budget",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="cost_day",
|
||||
name="Daily Energy Cost",
|
||||
translation_key="cost_day",
|
||||
device_class=SensorDeviceClass.MONETARY,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="cost_week",
|
||||
name="Weekly Energy Cost",
|
||||
translation_key="cost_week",
|
||||
device_class=SensorDeviceClass.MONETARY,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="cost_month",
|
||||
name="Monthly Energy Cost",
|
||||
translation_key="cost_month",
|
||||
device_class=SensorDeviceClass.MONETARY,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="cost_year",
|
||||
name="Yearly Energy Cost",
|
||||
translation_key="cost_year",
|
||||
device_class=SensorDeviceClass.MONETARY,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
entity_registry_enabled_default=False,
|
||||
|
@ -137,6 +137,8 @@ async def async_setup_entry(
|
|||
class EfergySensor(EfergyEntity, SensorEntity):
|
||||
"""Implementation of an Efergy sensor."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
api: Efergy,
|
||||
|
|
|
@ -16,5 +16,39 @@
|
|||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"instant_readings": {
|
||||
"name": "Power usage"
|
||||
},
|
||||
"energy_day": {
|
||||
"name": "Daily consumption"
|
||||
},
|
||||
"energy_week": {
|
||||
"name": "Weekly consumption"
|
||||
},
|
||||
"energy_month": {
|
||||
"name": "Monthly consumption"
|
||||
},
|
||||
"energy_year": {
|
||||
"name": "Yearly consumption"
|
||||
},
|
||||
"budget": {
|
||||
"name": "Energy budget"
|
||||
},
|
||||
"cost_day": {
|
||||
"name": "Daily energy cost"
|
||||
},
|
||||
"cost_week": {
|
||||
"name": "Weekly energy cost"
|
||||
},
|
||||
"cost_month": {
|
||||
"name": "Monthly energy cost"
|
||||
},
|
||||
"cost_year": {
|
||||
"name": "Yearly energy cost"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,62 +35,62 @@ async def test_sensor_readings(
|
|||
entry = await setup_platform(hass, aioclient_mock, SENSOR_DOMAIN)
|
||||
ent_reg: EntityRegistry = er.async_get(hass)
|
||||
|
||||
state = hass.states.get("sensor.power_usage")
|
||||
state = hass.states.get("sensor.efergy_power_usage")
|
||||
assert state.state == "1580"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
|
||||
state = hass.states.get("sensor.energy_budget")
|
||||
state = hass.states.get("sensor.efergy_energy_budget")
|
||||
assert state.state == "ok"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) is None
|
||||
state = hass.states.get("sensor.daily_consumption")
|
||||
state = hass.states.get("sensor.efergy_daily_consumption")
|
||||
assert state.state == "38.21"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING
|
||||
state = hass.states.get("sensor.weekly_consumption")
|
||||
state = hass.states.get("sensor.efergy_weekly_consumption")
|
||||
assert state.state == "267.47"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING
|
||||
state = hass.states.get("sensor.monthly_consumption")
|
||||
state = hass.states.get("sensor.efergy_monthly_consumption")
|
||||
assert state.state == "1069.88"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING
|
||||
state = hass.states.get("sensor.yearly_consumption")
|
||||
state = hass.states.get("sensor.efergy_yearly_consumption")
|
||||
assert state.state == "13373.50"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING
|
||||
state = hass.states.get("sensor.daily_energy_cost")
|
||||
state = hass.states.get("sensor.efergy_daily_energy_cost")
|
||||
assert state.state == "5.27"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.MONETARY
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "EUR"
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING
|
||||
state = hass.states.get("sensor.weekly_energy_cost")
|
||||
state = hass.states.get("sensor.efergy_weekly_energy_cost")
|
||||
assert state.state == "36.89"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.MONETARY
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "EUR"
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING
|
||||
state = hass.states.get("sensor.monthly_energy_cost")
|
||||
state = hass.states.get("sensor.efergy_monthly_energy_cost")
|
||||
assert state.state == "147.56"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.MONETARY
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "EUR"
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING
|
||||
state = hass.states.get("sensor.yearly_energy_cost")
|
||||
state = hass.states.get("sensor.efergy_yearly_energy_cost")
|
||||
assert state.state == "1844.50"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.MONETARY
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "EUR"
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING
|
||||
entity = ent_reg.async_get("sensor.power_usage_728386")
|
||||
entity = ent_reg.async_get("sensor.efergy_power_usage_728386")
|
||||
assert entity.disabled_by is er.RegistryEntryDisabler.INTEGRATION
|
||||
ent_reg.async_update_entity(entity.entity_id, **{"disabled_by": None})
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.power_usage_728386")
|
||||
state = hass.states.get("sensor.efergy_power_usage_728386")
|
||||
assert state.state == "1628"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT
|
||||
|
@ -104,17 +104,17 @@ async def test_multi_sensor_readings(
|
|||
for description in SENSOR_TYPES:
|
||||
description.entity_registry_enabled_default = True
|
||||
await setup_platform(hass, aioclient_mock, SENSOR_DOMAIN, MULTI_SENSOR_TOKEN)
|
||||
state = hass.states.get("sensor.power_usage_728386")
|
||||
state = hass.states.get("sensor.efergy_power_usage_728386")
|
||||
assert state.state == "218"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
|
||||
state = hass.states.get("sensor.power_usage_0")
|
||||
state = hass.states.get("sensor.efergy_power_usage_0")
|
||||
assert state.state == "1808"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
|
||||
state = hass.states.get("sensor.power_usage_728387")
|
||||
state = hass.states.get("sensor.efergy_power_usage_728387")
|
||||
assert state.state == "312"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT
|
||||
|
@ -126,16 +126,16 @@ async def test_failed_update_and_reconnection(
|
|||
) -> None:
|
||||
"""Test failed update and reconnection."""
|
||||
await setup_platform(hass, aioclient_mock, SENSOR_DOMAIN)
|
||||
assert hass.states.get("sensor.power_usage").state == "1580"
|
||||
assert hass.states.get("sensor.efergy_power_usage").state == "1580"
|
||||
aioclient_mock.clear_requests()
|
||||
await mock_responses(hass, aioclient_mock, error=True)
|
||||
next_update = dt_util.utcnow() + timedelta(seconds=30)
|
||||
async_fire_time_changed(hass, next_update)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("sensor.power_usage").state == STATE_UNAVAILABLE
|
||||
assert hass.states.get("sensor.efergy_power_usage").state == STATE_UNAVAILABLE
|
||||
aioclient_mock.clear_requests()
|
||||
await mock_responses(hass, aioclient_mock)
|
||||
next_update = dt_util.utcnow() + timedelta(seconds=30)
|
||||
async_fire_time_changed(hass, next_update)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("sensor.power_usage").state == "1580"
|
||||
assert hass.states.get("sensor.efergy_power_usage").state == "1580"
|
||||
|
|
Loading…
Add table
Reference in a new issue