From e1656be71c9c92808f0d4dc92964d02e6a67df76 Mon Sep 17 00:00:00 2001 From: Edward Brown Date: Mon, 1 Dec 2025 13:08:35 +0000 Subject: [PATCH] Add Control.icon field (MDI only) --- haco/constants.py | 3 +++ haco/control.py | 10 ++++++++++ haco/version | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/haco/constants.py b/haco/constants.py index c171ab3..4b22965 100644 --- a/haco/constants.py +++ b/haco/constants.py @@ -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:" diff --git a/haco/control.py b/haco/control.py index cb6ae6d..b14cdb0 100644 --- a/haco/control.py +++ b/haco/control.py @@ -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 diff --git a/haco/version b/haco/version index 6da28dd..8294c18 100644 --- a/haco/version +++ b/haco/version @@ -1 +1 @@ -0.1.1 \ No newline at end of file +0.1.2 \ No newline at end of file