From 9afcc3da8ef24c304c9a71e519f78dcc49df08a6 Mon Sep 17 00:00:00 2001 From: Dis90 Date: Sat, 20 Jul 2024 23:34:47 +0300 Subject: [PATCH] New feature: selecting program --- HCDevice.py | 3 +++ hc2mqtt.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/HCDevice.py b/HCDevice.py index 2665f05..abe18b6 100755 --- a/HCDevice.py +++ b/HCDevice.py @@ -266,6 +266,9 @@ class HCDevice: elif resource == "/ro/activeProgram": # Raises exception on failure self.test_program_data(data) + elif resource == "/ro/selectedProgram": + # Raises exception on failure + self.test_program_data(data) msg["data"] = data diff --git a/hc2mqtt.py b/hc2mqtt.py index 9d9a82a..5cce59d 100755 --- a/hc2mqtt.py +++ b/hc2mqtt.py @@ -64,6 +64,12 @@ def hc2mqtt( mqtt_active_program_topic = f"{mqtt_prefix}{device['name']}/activeProgram" print(now(), device["name"], f"program topic: {mqtt_active_program_topic}") client.subscribe(mqtt_active_program_topic) + # If the device has the SelectedProgram feature it allows programs to be selected + # via /ro/selectedProgram + if "BSH.Common.Root.SelectedProgram" == device["features"][value]["name"]: + mqtt_selected_program_topic = f"{mqtt_prefix}{device['name']}/selectedProgram" + print(now(), device["name"], f"program topic: {mqtt_selected_program_topic}") + client.subscribe(mqtt_selected_program_topic) else: print(now(), f"ERROR MQTT connection failed: {rc}") @@ -91,6 +97,8 @@ def hc2mqtt( resource = "/ro/values" elif topic == "activeProgram": resource = "/ro/activeProgram" + elif topic == "selectedProgram": + resource = "/ro/selectedProgram" else: raise Exception(f"Payload topic {topic} is unknown.")