From 5307f1cf4062afc4d9dd9fd345abc2ac645be87a Mon Sep 17 00:00:00 2001 From: Meatballs1 Date: Tue, 19 Mar 2024 13:42:57 +0000 Subject: [PATCH] Resolves more code review comments --- HCDevice.py | 6 +++--- README.md | 2 +- hc2mqtt | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/HCDevice.py b/HCDevice.py index c412c9a..eb2c520 100755 --- a/HCDevice.py +++ b/HCDevice.py @@ -122,7 +122,7 @@ class HCDevice: # check if selected list with values is allowed if 'values' in feature: - if isinstance(data['value'], int) == False: + 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']}.") 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']: @@ -131,7 +131,7 @@ class HCDevice: if 'min' in feature: min = int(feature['min']) max = int(feature['max']) - if isinstance(data['value'], int) == False or data['value'] < min or data['value'] > max: + if isinstance(data['value'], int) is False or data['value'] < min 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}.") return True @@ -174,7 +174,7 @@ class HCDevice: if data is not None: if action == "POST": - if self.test_feature(data) != True: + if self.test_feature(data) is False: return msg["data"] = [data] else: diff --git a/README.md b/README.md index 364504c..e76919f 100644 --- a/README.md +++ b/README.md @@ -363,7 +363,7 @@ Example message published to `homeconnect/coffeemaker`: ## Posting to the appliance -Whereas the reading of de status is very beta, this is very very alpha. There is some basic error handling, but don't expect that everything will work. +Whereas the reading of the status is very beta, this is very very alpha. There is some basic error handling, but don't expect that everything will work. In your config file you can find items that contain `readWrite` or `writeOnly`, some of them contain values so you know what to provide, ie: diff --git a/hc2mqtt b/hc2mqtt index c6f4d81..d6c1d4d 100755 --- a/hc2mqtt +++ b/hc2mqtt @@ -4,6 +4,7 @@ import json import sys import time +import ssl from threading import Thread import click @@ -67,11 +68,11 @@ def client_connect(client, device, mqtt_topic): print(msg.topic) mqtt_state = msg.payload.decode() mqtt_topic = msg.topic.split('/') - print(now(),f"received mqtt message {mqtt_state}") + print(now(), f"received mqtt message {mqtt_state}") try: msg = json.loads(mqtt_state) if 'uid' in msg: - dev[mqtt_topic[-2]].get("/ro/values",1,"POST",msg) + dev[mqtt_topic[-2]].get("/ro/values", 1, "POST", msg) else: raise Exception(f"Payload {msg} is not correctly formatted") except Exception as e: