Add Control.icon field (MDI only)
Some checks are pending
Version and Deploy / build (push) Waiting to run

This commit is contained in:
Edward Brown 2025-12-01 13:08:35 +00:00
parent a681aa897f
commit e1656be71c
3 changed files with 14 additions and 1 deletions

View file

@ -1,3 +1,5 @@
from __future__ import annotations
from fmtr.tools import env, Path, net
from haco.paths import paths
@ -10,3 +12,4 @@ CLIENT_ID = f'{HOSTNAME}-{MAC.hex}'
TOPIC_ROOT = Path(paths.name) / env.CHANNEL
TOPIC_CLIENT = TOPIC_ROOT / CLIENT_ID
TOPIC_AVAIL = TOPIC_CLIENT / STATUS
PREFIX_MDI = "mdi:"

View file

@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, TypeVar, Generic, Type, ClassVar
from fmtr.tools.json_tools import to_json
from haco.base import Base
from haco.capabilities import Capability
from haco.constants import PREFIX_MDI
from haco.obs import logger
from haco.utils import sanitize_name, Converters, ConvertersBool
@ -14,11 +15,13 @@ if TYPE_CHECKING:
DeviceT = TypeVar("DeviceT", bound="Device")
@dataclass(kw_only=True)
class Control(Base, Generic[DeviceT]):
converters: ClassVar[Type[Converters]] = ConvertersBool
name: str
icon: str | None = None
device: DeviceT = field(default=None, init=False)
capabilities: None | list[Capability] = field(default=None, metadata=dict(exclude=True))
unique_id: str | None = field(default=None, init=False)
@ -30,6 +33,13 @@ class Control(Base, Generic[DeviceT]):
def __post_init__(self):
self.capabilities = self.get_capabilities()
if not self.icon:
return
if not self.icon.startswith(PREFIX_MDI):
self.icon = f"{PREFIX_MDI}{self.icon}"
def set_parent(self, device):
self.device = device

View file

@ -1 +1 @@
0.1.1
0.1.2