mirror of
https://github.com/Andre0512/hon.git
synced 2025-05-21 02:15:06 -04:00
Rebuild to single data coordinator
This commit is contained in:
parent
8f1fc627e6
commit
a6c2c3e992
16 changed files with 148 additions and 203 deletions
28
custom_components/hon/util.py
Normal file
28
custom_components/hon/util.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
import logging
|
||||
from contextlib import suppress
|
||||
|
||||
from .typedefs import HonEntityDescription, HonOptionEntityDescription, T
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def unique_entities(
|
||||
base_entities: tuple[T, ...],
|
||||
new_entities: tuple[T, ...],
|
||||
) -> tuple[T, ...]:
|
||||
result = list(base_entities)
|
||||
existing_entities = [entity.key for entity in base_entities]
|
||||
entity: HonEntityDescription
|
||||
for entity in new_entities:
|
||||
if entity.key not in existing_entities:
|
||||
result.append(entity)
|
||||
return tuple(result)
|
||||
|
||||
|
||||
def get_readable(
|
||||
description: HonOptionEntityDescription, value: float | str
|
||||
) -> float | str:
|
||||
if description.option_list is not None:
|
||||
with suppress(ValueError):
|
||||
return description.option_list.get(int(value), value)
|
||||
return value
|
Loading…
Add table
Add a link
Reference in a new issue