fixed flake8 findings
This commit is contained in:
@@ -13,6 +13,8 @@ repos:
|
|||||||
- id: black
|
- id: black
|
||||||
args:
|
args:
|
||||||
- --quiet
|
- --quiet
|
||||||
|
- --line-length
|
||||||
|
- '99'
|
||||||
- repo: https://github.com/PyCQA/flake8
|
- repo: https://github.com/PyCQA/flake8
|
||||||
rev: 7.0.0
|
rev: 7.0.0
|
||||||
hooks:
|
hooks:
|
||||||
|
|||||||
44
HCDevice.py
44
HCDevice.py
@@ -95,26 +95,18 @@ class HCDevice:
|
|||||||
# Test the feature of an appliance agains a data object
|
# Test the feature of an appliance agains a data object
|
||||||
def test_feature(self, data):
|
def test_feature(self, data):
|
||||||
if "uid" not in data:
|
if "uid" not in data:
|
||||||
raise Exception(
|
raise Exception("{self.name}. Unable to configure appliance. UID is required.")
|
||||||
"{self.name}. Unable to configure appliance. UID is required."
|
|
||||||
)
|
|
||||||
|
|
||||||
if isinstance(data["uid"], int) is False:
|
if isinstance(data["uid"], int) is False:
|
||||||
raise Exception(
|
raise Exception("{self.name}. Unable to configure appliance. UID must be an integer.")
|
||||||
"{self.name}. Unable to configure appliance. UID must be an integer."
|
|
||||||
)
|
|
||||||
|
|
||||||
if "value" not in data:
|
if "value" not in data:
|
||||||
raise Exception(
|
raise Exception("{self.name}. Unable to configure appliance. Value is required.")
|
||||||
"{self.name}. Unable to configure appliance. Value is required."
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check if the uid is present for this appliance
|
# Check if the uid is present for this appliance
|
||||||
uid = str(data["uid"])
|
uid = str(data["uid"])
|
||||||
if uid not in self.features:
|
if uid not in self.features:
|
||||||
raise Exception(
|
raise Exception(f"{self.name}. Unable to configure appliance. UID {uid} is not valid.")
|
||||||
f"{self.name}. Unable to configure appliance. UID {uid} is not valid."
|
|
||||||
)
|
|
||||||
|
|
||||||
feature = self.features[uid]
|
feature = self.features[uid]
|
||||||
|
|
||||||
@@ -122,27 +114,32 @@ class HCDevice:
|
|||||||
print(now(), self.name, f"Processing feature {feature['name']} with uid {uid}")
|
print(now(), self.name, f"Processing feature {feature['name']} with uid {uid}")
|
||||||
if "access" not in feature:
|
if "access" not in feature:
|
||||||
raise Exception(
|
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()
|
access = feature["access"].lower()
|
||||||
if access != "readwrite" and access != "writeonly":
|
if access != "readwrite" and access != "writeonly":
|
||||||
raise Exception(
|
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
|
# check if selected list with values is allowed
|
||||||
if "values" in feature:
|
if "values" in feature:
|
||||||
if isinstance(data["value"], int) is False:
|
if isinstance(data["value"], int) is False:
|
||||||
raise Exception(
|
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(
|
value = str(data["value"])
|
||||||
data["value"]
|
# values are strings in the feature list,
|
||||||
) # values are strings in the feature list, but always seem to be an integer. An integer must be provided
|
# but always seem to be an integer. An integer must be provided
|
||||||
if value not in feature["values"]:
|
if value not in feature["values"]:
|
||||||
raise Exception(
|
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:
|
if "min" in feature:
|
||||||
@@ -154,7 +151,9 @@ class HCDevice:
|
|||||||
or data["value"] > max
|
or data["value"] > max
|
||||||
):
|
):
|
||||||
raise Exception(
|
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
|
return True
|
||||||
@@ -272,10 +271,7 @@ class HCDevice:
|
|||||||
# we could validate that this matches our machine
|
# we could validate that this matches our machine
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif (
|
elif resource == "/ro/descriptionChange" or resource == "/ro/allDescriptionChanges":
|
||||||
resource == "/ro/descriptionChange"
|
|
||||||
or resource == "/ro/allDescriptionChanges"
|
|
||||||
):
|
|
||||||
# we asked for these but don't know have to parse yet
|
# we asked for these but don't know have to parse yet
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ def parse_xml_list(codes, entries, enums):
|
|||||||
# not sure how to parse refCID and refDID
|
# not sure how to parse refCID and refDID
|
||||||
uid = int(el.attrib["uid"], 16)
|
uid = int(el.attrib["uid"], 16)
|
||||||
|
|
||||||
if not uid in codes:
|
if uid not in codes:
|
||||||
print("UID", uid, " not known!", file=sys.stderr)
|
print("UID", uid, " not known!", file=sys.stderr)
|
||||||
|
|
||||||
data = codes[uid]
|
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/"
|
base_url = "https://api.home-connect.com/security/oauth/"
|
||||||
asset_url = "https://prod.reu.rest.homeconnectegw.com/"
|
asset_url = "https://prod.reu.rest.homeconnectegw.com/"
|
||||||
|
|
||||||
##############3
|
|
||||||
#
|
#
|
||||||
# Start by fetching the old login page, which gives
|
# Start by fetching the old login page, which gives
|
||||||
# us the verifier and challenge for getting the token,
|
# us the verifier and challenge for getting the token,
|
||||||
@@ -161,9 +160,7 @@ session.headers.update(headers)
|
|||||||
debug("--------")
|
debug("--------")
|
||||||
|
|
||||||
soup = BeautifulSoup(r.text, "html.parser")
|
soup = BeautifulSoup(r.text, "html.parser")
|
||||||
requestVerificationToken = soup.find(
|
requestVerificationToken = soup.find("input", {"name": "__RequestVerificationToken"}).get("value")
|
||||||
"input", {"name": "__RequestVerificationToken"}
|
|
||||||
).get("value")
|
|
||||||
r = session.post(
|
r = session.post(
|
||||||
preauth_url,
|
preauth_url,
|
||||||
data={
|
data={
|
||||||
@@ -179,9 +176,7 @@ if not bool(urlparse(password_url).netloc):
|
|||||||
|
|
||||||
r = session.get(password_url, allow_redirects=False)
|
r = session.get(password_url, allow_redirects=False)
|
||||||
soup = BeautifulSoup(r.text, "html.parser")
|
soup = BeautifulSoup(r.text, "html.parser")
|
||||||
requestVerificationToken = soup.find(
|
requestVerificationToken = soup.find("input", {"name": "__RequestVerificationToken"}).get("value")
|
||||||
"input", {"name": "__RequestVerificationToken"}
|
|
||||||
).get("value")
|
|
||||||
|
|
||||||
r = session.post(
|
r = session.post(
|
||||||
password_url,
|
password_url,
|
||||||
|
|||||||
7
hc2mqtt
7
hc2mqtt
@@ -42,7 +42,8 @@ def hc2mqtt(
|
|||||||
mqtt_clientname: str,
|
mqtt_clientname: str,
|
||||||
):
|
):
|
||||||
click.echo(
|
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=}"
|
f"{mqtt_ssl=} {mqtt_cafile=} {mqtt_certfile=} {mqtt_keyfile=} {mqtt_clientname=}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -128,9 +129,7 @@ def client_connect(client, device, mqtt_topic):
|
|||||||
try:
|
try:
|
||||||
print(now(), device["name"], f"connecting to {host}")
|
print(now(), device["name"], f"connecting to {host}")
|
||||||
ws = HCSocket(host, device["key"], device.get("iv", None))
|
ws = HCSocket(host, device["key"], device.get("iv", None))
|
||||||
dev[device["name"]] = HCDevice(
|
dev[device["name"]] = HCDevice(ws, device.get("features", None), device["name"])
|
||||||
ws, device.get("features", None), device["name"]
|
|
||||||
)
|
|
||||||
|
|
||||||
# ws.debug = True
|
# ws.debug = True
|
||||||
ws.reconnect()
|
ws.reconnect()
|
||||||
|
|||||||
Reference in New Issue
Block a user