Resolves more code review comments

This commit is contained in:
Meatballs1
2024-03-19 13:42:57 +00:00
parent e5550486e2
commit 5307f1cf40
3 changed files with 7 additions and 6 deletions

View File

@@ -122,7 +122,7 @@ class HCDevice:
# 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) == 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']}.") 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 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']: if value not in feature['values']:
@@ -131,7 +131,7 @@ class HCDevice:
if 'min' in feature: if 'min' in feature:
min = int(feature['min']) min = int(feature['min'])
max = int(feature['max']) 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}.") 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 return True
@@ -174,7 +174,7 @@ class HCDevice:
if data is not None: if data is not None:
if action == "POST": if action == "POST":
if self.test_feature(data) != True: if self.test_feature(data) is False:
return return
msg["data"] = [data] msg["data"] = [data]
else: else:

View File

@@ -363,7 +363,7 @@ Example message published to `homeconnect/coffeemaker`:
## Posting to the appliance ## 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: 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:

View File

@@ -4,6 +4,7 @@
import json import json
import sys import sys
import time import time
import ssl
from threading import Thread from threading import Thread
import click import click
@@ -67,11 +68,11 @@ def client_connect(client, device, mqtt_topic):
print(msg.topic) print(msg.topic)
mqtt_state = msg.payload.decode() mqtt_state = msg.payload.decode()
mqtt_topic = msg.topic.split('/') mqtt_topic = msg.topic.split('/')
print(now(),f"received mqtt message {mqtt_state}") print(now(), f"received mqtt message {mqtt_state}")
try: try:
msg = json.loads(mqtt_state) msg = json.loads(mqtt_state)
if 'uid' in msg: 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: else:
raise Exception(f"Payload {msg} is not correctly formatted") raise Exception(f"Payload {msg} is not correctly formatted")
except Exception as e: except Exception as e: