Migrate Suez Water to has entity name (#107251)

This commit is contained in:
Joost Lekkerkerker 2024-01-05 18:36:21 +01:00 committed by GitHub
parent f0b47bf00c
commit 3a94dd6578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View File

@ -18,6 +18,7 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, UnitOfVolume
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -89,21 +90,27 @@ async def async_setup_entry(
) -> None: ) -> None:
"""Set up Suez Water sensor from a config entry.""" """Set up Suez Water sensor from a config entry."""
client = hass.data[DOMAIN][entry.entry_id] client = hass.data[DOMAIN][entry.entry_id]
async_add_entities([SuezSensor(client)], True) async_add_entities([SuezSensor(client, entry.data[CONF_COUNTER_ID])], True)
class SuezSensor(SensorEntity): class SuezSensor(SensorEntity):
"""Representation of a Sensor.""" """Representation of a Sensor."""
_attr_name = "Suez Water Client" _attr_has_entity_name = True
_attr_icon = "mdi:water-pump" _attr_translation_key = "water_usage_yesterday"
_attr_native_unit_of_measurement = UnitOfVolume.LITERS _attr_native_unit_of_measurement = UnitOfVolume.LITERS
_attr_device_class = SensorDeviceClass.WATER _attr_device_class = SensorDeviceClass.WATER
def __init__(self, client: SuezClient) -> None: def __init__(self, client: SuezClient, counter_id: int) -> None:
"""Initialize the data object.""" """Initialize the data object."""
self.client = client self.client = client
self._attr_extra_state_attributes = {} self._attr_extra_state_attributes = {}
self._attr_unique_id = f"{counter_id}_water_usage_yesterday"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, str(counter_id))},
entry_type=DeviceEntryType.SERVICE,
manufacturer="Suez",
)
def _fetch_data(self) -> None: def _fetch_data(self) -> None:
"""Fetch latest data from Suez.""" """Fetch latest data from Suez."""

View File

@ -18,6 +18,13 @@
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]" "already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
} }
}, },
"entity": {
"sensor": {
"water_usage_yesterday": {
"name": "Water usage yesterday"
}
}
},
"issues": { "issues": {
"deprecated_yaml_import_issue_invalid_auth": { "deprecated_yaml_import_issue_invalid_auth": {
"title": "The Suez water YAML configuration import failed", "title": "The Suez water YAML configuration import failed",