From 2277c7c36f0b7aa8fbae7ad03ef033ff0411347d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:00:23 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- HCDevice.py | 40 +++++++++++++++++++++++++--------------- hc2mqtt | 6 +++--- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/HCDevice.py b/HCDevice.py index a50d9b1..80ab2db 100755 --- a/HCDevice.py +++ b/HCDevice.py @@ -94,32 +94,42 @@ class HCDevice: # Based on PR submitted https://github.com/Skons/hcpy/pull/1/files#diff-f68bc58ad15ebfcb2b6ceca7c538e00790a6093c67c7c84ebcefb0c9756d3c0eR112-R139 def test_program_data(self, data): - if 'program' not in data: + if "program" not in data: raise Exception("{self.name}. Message data invalid, no program specified.") - if isinstance(data['program'], str): + if isinstance(data["program"], str): try: - data['program'] = int(data['program']) + data["program"] = int(data["program"]) except Exception as e: - raise Exception("{self.name}. Message data invalid, UID in 'program' must be an integer.") - elif isinstance(data['program'], int) is False: - raise Exception("{self.name}. Message data invalid. UID in 'program' must be an integer.") + raise Exception( + "{self.name}. Message data invalid, UID in 'program' must be an integer." + ) + elif isinstance(data["program"], int) is False: + raise Exception( + "{self.name}. Message data invalid. UID in 'program' must be an integer." + ) - uid = str(data['program']) + uid = str(data["program"]) if uid not in self.features: - raise Exception(f"{self.name}. Unable to configure appliance. Program UID {uid} is not valid for this device.") + raise Exception( + f"{self.name}. Unable to configure appliance. Program UID {uid} is not valid for this device." + ) feature = self.features[uid] # Diswasher is Dishcare.Dishwasher.Program.{name} # Hood is Cooking.Common.Program.{name} # May also be in the format BSH.Common.Program.Favorite.001 - if ".Program." not in feature['name']: - raise Exception(f"{self.name}. Unable to configure appliance. Program UID {uid} is not a valid program.") + if ".Program." not in feature["name"]: + raise Exception( + f"{self.name}. Unable to configure appliance. Program UID {uid} is not a valid program." + ) - if 'options' in data: - for option_uid in data['options']: + if "options" in data: + for option_uid in data["options"]: if str(option_uid) not in self.features: - raise Exception(f"{self.name}. Unable to configure appliance. Option UID {uid} is not valid for this device.") + raise Exception( + f"{self.name}. Unable to configure appliance. Option UID {uid} is not valid for this device." + ) # Test the feature of an appliance agains a data object def test_feature(self, data): @@ -225,10 +235,10 @@ class HCDevice: if data is not None: if action == "POST": - if 'resource' == '/ro/values': + if "resource" == "/ro/values": # Raises exceptions on failure self.test_feature(data) - elif 'resource' == '/ro/activeProgram': + elif "resource" == "/ro/activeProgram": # Raises exception on failure self.test_program_data(data) diff --git a/hc2mqtt b/hc2mqtt index b3ea7d3..7d5b1ae 100755 --- a/hc2mqtt +++ b/hc2mqtt @@ -101,9 +101,9 @@ def client_connect(client, device, mqtt_topic): try: msg = json.loads(mqtt_state) - if topic == 'set' and 'uid' in msg: + if topic == "set" and "uid" in msg: dev[device_name].get("/ro/values", 1, "POST", msg) - elif topic == 'activeProgram': + elif topic == "activeProgram": dev[device_name].get("/ro/activeProgram", 1, "POST", msg) else: raise Exception(f"Payload {msg} is not correctly formatted") @@ -116,7 +116,7 @@ def client_connect(client, device, mqtt_topic): for value in device["features"]: # If the device has the ActiveProgram feature it allows programs to be started and scheduled via /ro/activeProgram - if "BSH.Common.Root.ActiveProgram" == device['features'][value]['name']: + if "BSH.Common.Root.ActiveProgram" == device["features"][value]["name"]: active_program = True if ( "access" in device["features"][value]