mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Add entity translations to SRP Energy (#99011)
This commit is contained in:
parent
73cfe659ea
commit
91bc65be9c
@ -11,6 +11,3 @@ CONF_IS_TOU = "is_tou"
|
||||
|
||||
PHOENIX_TIME_ZONE = "America/Phoenix"
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=1440)
|
||||
|
||||
SENSOR_NAME = "Energy Usage"
|
||||
SENSOR_TYPE = "usage"
|
||||
|
@ -9,11 +9,12 @@ from homeassistant.components.sensor import (
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import UnitOfEnergy
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import SRPEnergyDataUpdateCoordinator
|
||||
from .const import DEFAULT_NAME, DOMAIN, SENSOR_NAME
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
@ -29,10 +30,11 @@ class SrpEntity(CoordinatorEntity[SRPEnergyDataUpdateCoordinator], SensorEntity)
|
||||
"""Implementation of a Srp Energy Usage sensor."""
|
||||
|
||||
_attr_attribution = "Powered by SRP Energy"
|
||||
_attr_icon = "mdi:flash"
|
||||
_attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
|
||||
_attr_device_class = SensorDeviceClass.ENERGY
|
||||
_attr_state_class = SensorStateClass.TOTAL_INCREASING
|
||||
_attr_has_entity_name = True
|
||||
_attr_translation_key = "energy_usage"
|
||||
|
||||
def __init__(
|
||||
self, coordinator: SRPEnergyDataUpdateCoordinator, config_entry: ConfigEntry
|
||||
@ -40,7 +42,11 @@ class SrpEntity(CoordinatorEntity[SRPEnergyDataUpdateCoordinator], SensorEntity)
|
||||
"""Initialize the SrpEntity class."""
|
||||
super().__init__(coordinator)
|
||||
self._attr_unique_id = f"{config_entry.entry_id}_total_usage"
|
||||
self._attr_name = f"{DEFAULT_NAME} {SENSOR_NAME}"
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, config_entry.entry_id)},
|
||||
name="SRP Energy",
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
)
|
||||
|
||||
@property
|
||||
def native_value(self) -> float:
|
||||
|
@ -19,5 +19,12 @@
|
||||
"abort": {
|
||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"energy_usage": {
|
||||
"name": "Energy usage"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_ICON,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
UnitOfEnergy,
|
||||
)
|
||||
@ -29,7 +28,7 @@ async def test_loading_sensors(hass: HomeAssistant, init_integration) -> None:
|
||||
|
||||
async def test_srp_entity(hass: HomeAssistant, init_integration) -> None:
|
||||
"""Test the SrpEntity."""
|
||||
usage_state = hass.states.get("sensor.home_energy_usage")
|
||||
usage_state = hass.states.get("sensor.srp_energy_energy_usage")
|
||||
assert usage_state.state == "150.8"
|
||||
|
||||
# Validate attributions
|
||||
@ -43,7 +42,6 @@ async def test_srp_entity(hass: HomeAssistant, init_integration) -> None:
|
||||
)
|
||||
|
||||
assert usage_state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY
|
||||
assert usage_state.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
|
||||
|
||||
async def test_srp_entity_update_failed(
|
||||
|
Loading…
x
Reference in New Issue
Block a user