mirror of
https://github.com/home-assistant/core.git
synced 2026-04-27 05:48:01 +00:00
tibber refactor
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
This commit is contained in:
@@ -132,6 +132,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: TibberConfigEntry) -> bo
|
||||
await data_api_coordinator.async_config_entry_first_refresh()
|
||||
await data_coordinator.async_config_entry_first_refresh()
|
||||
await data_coordinator.update_listeners(dt_util.utcnow())
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
return True
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ def _build_home_data(home: TibberHome) -> TibberHomeData:
|
||||
|
||||
|
||||
class TibberDataCoordinator(DataUpdateCoordinator[dict[str, TibberHomeData]]):
|
||||
"""Handle Tibber data, insert statistics, and expose per-home data for sensors."""
|
||||
"""Handle Tibber data and insert statistics."""
|
||||
|
||||
config_entry: TibberConfigEntry
|
||||
|
||||
|
||||
@@ -32,8 +32,12 @@ class TibberCoordinatorEntity(CoordinatorEntity[TibberDataCoordinator]):
|
||||
super().__init__(coordinator)
|
||||
self._tibber_home = tibber_home
|
||||
self._home_name: str = tibber_home.name or tibber_home.home_id
|
||||
self._model: str | None = None
|
||||
self._device_name: str = self._home_name
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, self._tibber_home.home_id)},
|
||||
name=self._device_name,
|
||||
model="Tibber Pulse",
|
||||
)
|
||||
|
||||
def _get_home_data(self) -> TibberHomeData | None:
|
||||
"""Return cached home data from the coordinator."""
|
||||
@@ -42,15 +46,6 @@ class TibberCoordinatorEntity(CoordinatorEntity[TibberDataCoordinator]):
|
||||
return None
|
||||
return data.get(self._tibber_home.home_id)
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information."""
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._tibber_home.home_id)},
|
||||
name=self._device_name,
|
||||
model=self._model,
|
||||
)
|
||||
|
||||
|
||||
class TibberRTCoordinatorEntity(CoordinatorEntity[TibberRtDataCoordinator]):
|
||||
"""Representation of a Tibber sensor for real time consumption."""
|
||||
@@ -68,10 +63,15 @@ class TibberRTCoordinatorEntity(CoordinatorEntity[TibberRtDataCoordinator]):
|
||||
super().__init__(coordinator)
|
||||
self._tibber_home = tibber_home
|
||||
self._home_name: str = tibber_home.name or tibber_home.home_id
|
||||
self._model: str = "Tibber Pulse"
|
||||
self._device_name: str = f"{self._model} {self._home_name}"
|
||||
model: str = "Tibber Pulse"
|
||||
self._device_name: str = f"{model} {self._home_name}"
|
||||
self.entity_description = description
|
||||
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, self._tibber_home.home_id)},
|
||||
name=self._device_name,
|
||||
model=model,
|
||||
)
|
||||
self._attr_native_value = initial_state
|
||||
self._attr_last_reset: datetime | None = None
|
||||
self._attr_unique_id = f"{self._tibber_home.home_id}_rt_{description.key}"
|
||||
@@ -79,15 +79,6 @@ class TibberRTCoordinatorEntity(CoordinatorEntity[TibberRtDataCoordinator]):
|
||||
if description.key in ("accumulatedCost", "accumulatedReward"):
|
||||
self._attr_native_unit_of_measurement = tibber_home.currency
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information."""
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._tibber_home.home_id)},
|
||||
name=self._device_name,
|
||||
model=self._model,
|
||||
)
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
|
||||
@@ -745,8 +745,6 @@ class TibberSensor(TibberCoordinatorEntity, SensorEntity):
|
||||
tibber_home: TibberHome,
|
||||
coordinator: TibberDataCoordinator,
|
||||
entity_description: SensorEntityDescription,
|
||||
*,
|
||||
model: str | None = None,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator=coordinator, tibber_home=tibber_home)
|
||||
@@ -760,8 +758,6 @@ class TibberSensor(TibberCoordinatorEntity, SensorEntity):
|
||||
f"{self._tibber_home.home_id}_{self.entity_description.key}"
|
||||
)
|
||||
self._device_name = self._home_name
|
||||
if model is not None:
|
||||
self._model = model
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user