[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
40
HCDevice.py
40
HCDevice.py
@@ -94,32 +94,42 @@ class HCDevice:
|
|||||||
|
|
||||||
# Based on PR submitted https://github.com/Skons/hcpy/pull/1/files#diff-f68bc58ad15ebfcb2b6ceca7c538e00790a6093c67c7c84ebcefb0c9756d3c0eR112-R139
|
# Based on PR submitted https://github.com/Skons/hcpy/pull/1/files#diff-f68bc58ad15ebfcb2b6ceca7c538e00790a6093c67c7c84ebcefb0c9756d3c0eR112-R139
|
||||||
def test_program_data(self, data):
|
def test_program_data(self, data):
|
||||||
if 'program' not in data:
|
if "program" not in data:
|
||||||
raise Exception("{self.name}. Message data invalid, no program specified.")
|
raise Exception("{self.name}. Message data invalid, no program specified.")
|
||||||
|
|
||||||
if isinstance(data['program'], str):
|
if isinstance(data["program"], str):
|
||||||
try:
|
try:
|
||||||
data['program'] = int(data['program'])
|
data["program"] = int(data["program"])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception("{self.name}. Message data invalid, UID in 'program' must be an integer.")
|
raise Exception(
|
||||||
elif isinstance(data['program'], int) is False:
|
"{self.name}. Message data invalid, UID in 'program' must be an integer."
|
||||||
raise Exception("{self.name}. Message data invalid. UID in 'program' must be an integer.")
|
)
|
||||||
|
elif isinstance(data["program"], int) is False:
|
||||||
|
raise Exception(
|
||||||
|
"{self.name}. Message data invalid. UID in 'program' must be an integer."
|
||||||
|
)
|
||||||
|
|
||||||
uid = str(data['program'])
|
uid = str(data["program"])
|
||||||
if uid not in self.features:
|
if uid not in self.features:
|
||||||
raise Exception(f"{self.name}. Unable to configure appliance. Program UID {uid} is not valid for this device.")
|
raise Exception(
|
||||||
|
f"{self.name}. Unable to configure appliance. Program UID {uid} is not valid for this device."
|
||||||
|
)
|
||||||
|
|
||||||
feature = self.features[uid]
|
feature = self.features[uid]
|
||||||
# Diswasher is Dishcare.Dishwasher.Program.{name}
|
# Diswasher is Dishcare.Dishwasher.Program.{name}
|
||||||
# Hood is Cooking.Common.Program.{name}
|
# Hood is Cooking.Common.Program.{name}
|
||||||
# May also be in the format BSH.Common.Program.Favorite.001
|
# May also be in the format BSH.Common.Program.Favorite.001
|
||||||
if ".Program." not in feature['name']:
|
if ".Program." not in feature["name"]:
|
||||||
raise Exception(f"{self.name}. Unable to configure appliance. Program UID {uid} is not a valid program.")
|
raise Exception(
|
||||||
|
f"{self.name}. Unable to configure appliance. Program UID {uid} is not a valid program."
|
||||||
|
)
|
||||||
|
|
||||||
if 'options' in data:
|
if "options" in data:
|
||||||
for option_uid in data['options']:
|
for option_uid in data["options"]:
|
||||||
if str(option_uid) not in self.features:
|
if str(option_uid) not in self.features:
|
||||||
raise Exception(f"{self.name}. Unable to configure appliance. Option UID {uid} is not valid for this device.")
|
raise Exception(
|
||||||
|
f"{self.name}. Unable to configure appliance. Option UID {uid} is not valid for this device."
|
||||||
|
)
|
||||||
|
|
||||||
# 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):
|
||||||
@@ -225,10 +235,10 @@ class HCDevice:
|
|||||||
|
|
||||||
if data is not None:
|
if data is not None:
|
||||||
if action == "POST":
|
if action == "POST":
|
||||||
if 'resource' == '/ro/values':
|
if "resource" == "/ro/values":
|
||||||
# Raises exceptions on failure
|
# Raises exceptions on failure
|
||||||
self.test_feature(data)
|
self.test_feature(data)
|
||||||
elif 'resource' == '/ro/activeProgram':
|
elif "resource" == "/ro/activeProgram":
|
||||||
# Raises exception on failure
|
# Raises exception on failure
|
||||||
self.test_program_data(data)
|
self.test_program_data(data)
|
||||||
|
|
||||||
|
|||||||
6
hc2mqtt
6
hc2mqtt
@@ -101,9 +101,9 @@ def client_connect(client, device, mqtt_topic):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
msg = json.loads(mqtt_state)
|
msg = json.loads(mqtt_state)
|
||||||
if topic == 'set' and 'uid' in msg:
|
if topic == "set" and "uid" in msg:
|
||||||
dev[device_name].get("/ro/values", 1, "POST", msg)
|
dev[device_name].get("/ro/values", 1, "POST", msg)
|
||||||
elif topic == 'activeProgram':
|
elif topic == "activeProgram":
|
||||||
dev[device_name].get("/ro/activeProgram", 1, "POST", msg)
|
dev[device_name].get("/ro/activeProgram", 1, "POST", msg)
|
||||||
else:
|
else:
|
||||||
raise Exception(f"Payload {msg} is not correctly formatted")
|
raise Exception(f"Payload {msg} is not correctly formatted")
|
||||||
@@ -116,7 +116,7 @@ def client_connect(client, device, mqtt_topic):
|
|||||||
|
|
||||||
for value in device["features"]:
|
for value in device["features"]:
|
||||||
# If the device has the ActiveProgram feature it allows programs to be started and scheduled via /ro/activeProgram
|
# If the device has the ActiveProgram feature it allows programs to be started and scheduled via /ro/activeProgram
|
||||||
if "BSH.Common.Root.ActiveProgram" == device['features'][value]['name']:
|
if "BSH.Common.Root.ActiveProgram" == device["features"][value]["name"]:
|
||||||
active_program = True
|
active_program = True
|
||||||
if (
|
if (
|
||||||
"access" in device["features"][value]
|
"access" in device["features"][value]
|
||||||
|
|||||||
Reference in New Issue
Block a user