Merge pull request #62 from Meatballs1/description_changes

Process description changes
This commit is contained in:
pmagyar
2024-05-01 20:28:00 +02:00
committed by GitHub

View File

@@ -59,6 +59,7 @@ def now():
class HCDevice:
def __init__(self, ws, device):
self.ws = ws
self.features_lock = threading.Lock()
self.features = device.get("features")
self.name = device.get("name")
self.session_id = None
@@ -84,11 +85,12 @@ class HCDevice:
name = uid
status = None
with self.features_lock:
if uid in self.features:
status = self.features[uid]
if status:
if "name" in status:
name = status["name"]
if "values" in status and value_str in status["values"]:
value = status["values"][value_str]
@@ -110,6 +112,7 @@ class HCDevice:
# devices.json stores UID as string
uid = str(data["program"])
with self.features_lock:
if uid not in self.features:
raise ValueError(
f"Unable to configure appliance. Program UID {uid} is not valid"
@@ -120,11 +123,14 @@ class HCDevice:
# Diswasher is Dishcare.Dishwasher.Program.{name}
# Hood is Cooking.Common.Program.{name}
# May also be in the format BSH.Common.Program.Favorite.001
if "name" in feature:
if ".Program." not in feature["name"]:
raise ValueError(
f"Unable to configure appliance. Program UID {uid} is not a valid"
f" program - {feature['name']}."
)
else:
self.print(f"Unknown Program UID {uid}")
if "options" in data:
for option in data["options"]:
@@ -149,6 +155,7 @@ class HCDevice:
# Check if the uid is present for this appliance
uid = str(data["uid"])
with self.features_lock:
if uid not in self.features:
raise Exception(f"Unable to configure appliance. UID {uid} is not valid.")
@@ -166,7 +173,8 @@ class HCDevice:
if access != "readwrite" and access != "writeonly":
raise Exception(
"Unable to configure appliance. "
f"Feature {feature['name']} with uid {uid} has got access {feature['access']}."
f"Feature {feature['name']} with uid {uid} "
f"has got access {feature['access']}."
)
# check if selected list with values is allowed
@@ -305,6 +313,7 @@ class HCDevice:
# self.get("/ro/allDescriptionChanges")
self.get("/ro/allMandatoryValues")
self.get("/ro/values")
self.get("/ro/allDescriptionChanges")
def handle_message(self, buf):
msg = json.loads(buf)
@@ -349,8 +358,25 @@ class HCDevice:
values = msg["data"][0]
elif resource == "/ro/descriptionChange" or resource == "/ro/allDescriptionChanges":
# we asked for these but don't know have to parse yet
pass
if "data" in msg and len(msg["data"]) > 0:
with self.features_lock:
for change in msg["data"]:
uid = str(change["uid"])
if uid in self.features:
if "access" in change:
access = change["access"]
self.features[uid]["access"] = access
self.print(f"Access change for {uid} to {access}")
if "available" in change:
self.features[uid]["available"] = change["available"]
if "min" in change:
self.features[uid]["min"] = change["min"]
if "max" in change:
self.features[uid]["max"] = change["max"]
else:
# We wont have name for this item, so have to be careful
# when resolving elsewhere
self.features[uid] = change
elif resource == "/ni/info":
if "data" in msg and len(msg["data"]) > 0: