mqtt: use extended confighelper methods

SIgned-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2021-11-20 09:06:10 -05:00
parent 22807ee393
commit 9ebae5fd5a
1 changed files with 9 additions and 19 deletions

View File

@ -192,27 +192,17 @@ class MQTTClient(APITransport, Subscribable):
self.api_resp_topic = f"{self.instance_name}/moonraker/api/response" self.api_resp_topic = f"{self.instance_name}/moonraker/api/response"
self.klipper_status_topic = f"{self.instance_name}/klipper/status" self.klipper_status_topic = f"{self.instance_name}/klipper/status"
self.moonraker_status_topic = f"{self.instance_name}/moonraker/status" self.moonraker_status_topic = f"{self.instance_name}/moonraker/status"
status_cfg = config.get("status_objects", None) status_cfg: Dict[str, Any] = config.getdict("status_objects", {},
allow_empty_fields=True)
self.status_objs: Dict[str, Any] = {} self.status_objs: Dict[str, Any] = {}
if status_cfg is not None: for key, val in status_cfg.items():
for line in status_cfg.strip().split('\n'): if val is not None:
line = line.strip() self.status_objs[key] = [v.strip() for v in val.split(',')
if not line: if v.strip()]
continue else:
parts = line.split('=', 1) self.status_objs[key] = None
fields: Optional[List[str]] if status_cfg:
if len(parts) == 1:
fields = None
if len(parts) == 2:
fields = [f.strip() for f in parts[1].split(',')
if f.strip()]
elif len(parts) != 1:
raise config.error(
"Format error in option 'status_object', "
f"section [mqtt]:\n{status_cfg}")
self.status_objs[parts[0].strip()] = fields
logging.debug(f"MQTT: Status Objects Set: {self.status_objs}") logging.debug(f"MQTT: Status Objects Set: {self.status_objs}")
self.server.register_event_handler("server:klippy_identified", self.server.register_event_handler("server:klippy_identified",
self._handle_klippy_identified) self._handle_klippy_identified)