mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 10:17:51 +00:00
Add unique id's to Vallox entities (#58459)
* Add unique id's to Vallox entities * Cache uuid properties Requested in code review. Caching None isn't a problem as the underlying implementation of get_uuid in the vallox_websocket_api library can never return None. * Simplify get_uuid type check Based on review comments. * Set _attr_unique_id in init * Import the library get_uuid under a different name There are a few options here: 1. Rename the get_uuid method with a synonym 2. Import get_uuid under a different name 3. Convert get_uuid into a property 4. Rename get_uuid in the Vallox library None of these options is that appealing. I'll start with option two, anyways.
This commit is contained in:
parent
a4208c0926
commit
5cc594682f
@ -5,9 +5,11 @@ from dataclasses import dataclass, field
|
|||||||
import ipaddress
|
import ipaddress
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, NamedTuple
|
from typing import Any, NamedTuple
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
from vallox_websocket_api import PROFILE as VALLOX_PROFILE, Vallox
|
from vallox_websocket_api import PROFILE as VALLOX_PROFILE, Vallox
|
||||||
from vallox_websocket_api.exceptions import ValloxApiException
|
from vallox_websocket_api.exceptions import ValloxApiException
|
||||||
|
from vallox_websocket_api.vallox import get_uuid as calculate_uuid
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_HOST, CONF_NAME, EVENT_HOMEASSISTANT_STARTED
|
from homeassistant.const import CONF_HOST, CONF_NAME, EVENT_HOMEASSISTANT_STARTED
|
||||||
@ -114,6 +116,13 @@ class ValloxState:
|
|||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
def get_uuid(self) -> UUID | None:
|
||||||
|
"""Return cached UUID value."""
|
||||||
|
uuid = calculate_uuid(self.metric_cache)
|
||||||
|
if not isinstance(uuid, UUID):
|
||||||
|
raise ValueError
|
||||||
|
return uuid
|
||||||
|
|
||||||
|
|
||||||
class ValloxDataUpdateCoordinator(DataUpdateCoordinator):
|
class ValloxDataUpdateCoordinator(DataUpdateCoordinator):
|
||||||
"""The DataUpdateCoordinator for Vallox."""
|
"""The DataUpdateCoordinator for Vallox."""
|
||||||
|
@ -99,6 +99,8 @@ class ValloxFan(CoordinatorEntity, FanEntity):
|
|||||||
|
|
||||||
self._attr_name = name
|
self._attr_name = name
|
||||||
|
|
||||||
|
self._attr_unique_id = str(self.coordinator.data.get_uuid())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> int:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
|
@ -52,6 +52,9 @@ class ValloxSensor(CoordinatorEntity, SensorEntity):
|
|||||||
|
|
||||||
self._attr_name = f"{name} {description.name}"
|
self._attr_name = f"{name} {description.name}"
|
||||||
|
|
||||||
|
uuid = self.coordinator.data.get_uuid()
|
||||||
|
self._attr_unique_id = f"{uuid}-{description.key}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType:
|
||||||
"""Return the value reported by the sensor."""
|
"""Return the value reported by the sensor."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user