33from dataclasses import dataclass , field
44from typing import TYPE_CHECKING , TypeVar , Generic , Type , ClassVar
55
6+ from fmtr .tools import Constants
67from fmtr .tools .json_tools import to_json
78from haco .base import Base
89from haco .capabilities import Capability
9- from haco .constants import PREFIX_MDI
10+ from haco .constants import PREFIX_MDI , ANNOUNCE
1011from haco .obs import logger
11- from haco .utils import sanitize_name , Converters , ConvertersBool
12+ from haco .utils import sanitize_name , Converters , ConvertersBool , get_prefix
1213
1314if TYPE_CHECKING :
1415 from haco .device import Device
@@ -27,7 +28,6 @@ class Control(Base, Generic[DeviceT]):
2728 unique_id : str | None = field (default = None , init = False )
2829 availability_topic : str | None = field (default = None , init = False )
2930
30- # announce: dict | None = field(default=None, metadata=dict(exclude=True))
3131 subscriptions : dict | None = field (default = None , metadata = dict (exclude = True ), init = False )
3232
3333 def __post_init__ (self ):
@@ -49,9 +49,6 @@ def set_parent(self, device):
4949 self .unique_id = self .get_unique_id ()
5050 self .availability_topic = self .get_availability_topic ()
5151 self .subscriptions = self .get_subscriptions ()
52- #self.announce = self.get_announce()
53-
54-
5552
5653 @property
5754 def parent (self ):
@@ -111,8 +108,11 @@ async def announce(self):
111108
112109 """
113110 topic = self .announce_topic
114- data_json = to_json (self .get_announce ())
115- logger .info (f'Announcing { topic } with { data_json } ' )
111+ data = self .get_announce ()
112+ data_json = to_json (data )
113+
114+ logger .info (f'{ get_prefix (ANNOUNCE )} : { data } { Constants .ARROW_RIGHT } { topic } ' )
115+
116116 await self .device .client .publish (topic , data_json , retain = True )
117117
118118
0 commit comments