From 60e6e657e54bbb84152c2f7ff60430ced3e82fb2 Mon Sep 17 00:00:00 2001 From: p_magyar Date: Tue, 19 Mar 2024 19:56:23 +0100 Subject: [PATCH] fixed flake8 findings --- .pre-commit-config.yaml | 2 ++ HCDevice.py | 44 +++++++++++++++++++---------------------- HCxml2json.py | 2 +- hc-login | 9 ++------- hc2mqtt | 7 +++---- 5 files changed, 28 insertions(+), 36 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 098490f..61232a4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,6 +13,8 @@ repos: - id: black args: - --quiet + - --line-length + - '99' - repo: https://github.com/PyCQA/flake8 rev: 7.0.0 hooks: diff --git a/HCDevice.py b/HCDevice.py index 3819ebb..5d4ef86 100755 --- a/HCDevice.py +++ b/HCDevice.py @@ -95,26 +95,18 @@ class HCDevice: # Test the feature of an appliance agains a data object def test_feature(self, data): if "uid" not in data: - raise Exception( - "{self.name}. Unable to configure appliance. UID is required." - ) + raise Exception("{self.name}. Unable to configure appliance. UID is required.") if isinstance(data["uid"], int) is False: - raise Exception( - "{self.name}. Unable to configure appliance. UID must be an integer." - ) + raise Exception("{self.name}. Unable to configure appliance. UID must be an integer.") if "value" not in data: - raise Exception( - "{self.name}. Unable to configure appliance. Value is required." - ) + raise Exception("{self.name}. Unable to configure appliance. Value is required.") # Check if the uid is present for this appliance uid = str(data["uid"]) if uid not in self.features: - raise Exception( - f"{self.name}. Unable to configure appliance. UID {uid} is not valid." - ) + raise Exception(f"{self.name}. Unable to configure appliance. UID {uid} is not valid.") feature = self.features[uid] @@ -122,27 +114,32 @@ class HCDevice: print(now(), self.name, f"Processing feature {feature['name']} with uid {uid}") if "access" not in feature: raise Exception( - f"{self.name}. Unable to configure appliance. Feature {feature['name']} with uid {uid} does not have access." + f"{self.name}. Unable to configure appliance." + f"Feature {feature['name']} with uid {uid} does not have access." ) access = feature["access"].lower() if access != "readwrite" and access != "writeonly": raise Exception( - f"{self.name}. Unable to configure appliance. Feature {feature['name']} with uid {uid} has got access {feature['access']}." + f"{self.name}. Unable to configure appliance." + f"Feature {feature['name']} with uid {uid} has got access {feature['access']}." ) # check if selected list with values is allowed if "values" in feature: if isinstance(data["value"], int) is False: raise Exception( - f"Unable to configure appliance. The value {data['value']} must be an integer. Allowed values are {feature['values']}." + f"Unable to configure appliance. The value {data['value']} must be an integer." + f"Allowed values are {feature['values']}." ) - value = str( - data["value"] - ) # values are strings in the feature list, but always seem to be an integer. An integer must be provided + value = str(data["value"]) + # values are strings in the feature list, + # but always seem to be an integer. An integer must be provided if value not in feature["values"]: raise Exception( - f"{self.name}. Unable to configure appliance. Value {data['value']} is not a valid value. Allowed values are {feature['values']}." + f"{self.name}. Unable to configure appliance." + f"Value {data['value']} is not a valid value." + f"Allowed values are {feature['values']}." ) if "min" in feature: @@ -154,7 +151,9 @@ class HCDevice: or data["value"] > max ): raise Exception( - f"{self.name}. Unable to configure appliance. Value {data['value']} is not a valid value. The value must be an integer in the range {min} and {max}." + f"{self.name}. Unable to configure appliance." + f"Value {data['value']} is not a valid value." + f"The value must be an integer in the range {min} and {max}." ) return True @@ -272,10 +271,7 @@ class HCDevice: # we could validate that this matches our machine pass - elif ( - resource == "/ro/descriptionChange" - or resource == "/ro/allDescriptionChanges" - ): + elif resource == "/ro/descriptionChange" or resource == "/ro/allDescriptionChanges": # we asked for these but don't know have to parse yet pass diff --git a/HCxml2json.py b/HCxml2json.py index e415d13..25ad411 100755 --- a/HCxml2json.py +++ b/HCxml2json.py @@ -21,7 +21,7 @@ def parse_xml_list(codes, entries, enums): # not sure how to parse refCID and refDID uid = int(el.attrib["uid"], 16) - if not uid in codes: + if uid not in codes: print("UID", uid, " not known!", file=sys.stderr) data = codes[uid] diff --git a/hc-login b/hc-login index a6710f8..a47dafd 100755 --- a/hc-login +++ b/hc-login @@ -46,7 +46,6 @@ session.headers.update(headers) base_url = "https://api.home-connect.com/security/oauth/" asset_url = "https://prod.reu.rest.homeconnectegw.com/" -##############3 # # Start by fetching the old login page, which gives # us the verifier and challenge for getting the token, @@ -161,9 +160,7 @@ session.headers.update(headers) debug("--------") soup = BeautifulSoup(r.text, "html.parser") -requestVerificationToken = soup.find( - "input", {"name": "__RequestVerificationToken"} -).get("value") +requestVerificationToken = soup.find("input", {"name": "__RequestVerificationToken"}).get("value") r = session.post( preauth_url, data={ @@ -179,9 +176,7 @@ if not bool(urlparse(password_url).netloc): r = session.get(password_url, allow_redirects=False) soup = BeautifulSoup(r.text, "html.parser") -requestVerificationToken = soup.find( - "input", {"name": "__RequestVerificationToken"} -).get("value") +requestVerificationToken = soup.find("input", {"name": "__RequestVerificationToken"}).get("value") r = session.post( password_url, diff --git a/hc2mqtt b/hc2mqtt index ff7e7fd..11676d3 100755 --- a/hc2mqtt +++ b/hc2mqtt @@ -42,7 +42,8 @@ def hc2mqtt( mqtt_clientname: str, ): click.echo( - f"Hello {devices_file=} {mqtt_host=} {mqtt_prefix=} {mqtt_port=} {mqtt_username=} {mqtt_password=} " + f"Hello {devices_file=} {mqtt_host=} {mqtt_prefix=} " + f"{mqtt_port=} {mqtt_username=} {mqtt_password=} " f"{mqtt_ssl=} {mqtt_cafile=} {mqtt_certfile=} {mqtt_keyfile=} {mqtt_clientname=}" ) @@ -128,9 +129,7 @@ def client_connect(client, device, mqtt_topic): try: print(now(), device["name"], f"connecting to {host}") ws = HCSocket(host, device["key"], device.get("iv", None)) - dev[device["name"]] = HCDevice( - ws, device.get("features", None), device["name"] - ) + dev[device["name"]] = HCDevice(ws, device.get("features", None), device["name"]) # ws.debug = True ws.reconnect()