fixed flake8 findings
This commit is contained in:
@@ -13,6 +13,8 @@ repos:
|
||||
- id: black
|
||||
args:
|
||||
- --quiet
|
||||
- --line-length
|
||||
- '99'
|
||||
- repo: https://github.com/PyCQA/flake8
|
||||
rev: 7.0.0
|
||||
hooks:
|
||||
|
||||
44
HCDevice.py
44
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
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
9
hc-login
9
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,
|
||||
|
||||
7
hc2mqtt
7
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()
|
||||
|
||||
Reference in New Issue
Block a user