Support JSON arrays in input data

This commit is contained in:
Meatballs1
2024-03-20 18:16:26 +00:00
parent 6bf8b540ed
commit 0151d95e7b

View File

@@ -93,7 +93,8 @@ class HCDevice:
return result return result
# Based on PR submitted https://github.com/Skons/hcpy/pull/1 # Based on PR submitted https://github.com/Skons/hcpy/pull/1
def test_program_data(self, data): def test_program_data(self, data_array):
for data in data_array:
if "program" not in data: if "program" not in data:
raise TypeError("Message data invalid, no program specified.") raise TypeError("Message data invalid, no program specified.")
@@ -127,7 +128,8 @@ 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_array):
for data in data_array:
if "uid" not in data: if "uid" not in data:
raise Exception("Unable to configure appliance. UID is required.") raise Exception("Unable to configure appliance. UID is required.")
@@ -229,6 +231,9 @@ class HCDevice:
} }
if data is not None: if data is not None:
if isinstance(data, list) is False:
data = [data]
if action == "POST": if action == "POST":
if resource == "/ro/values": if resource == "/ro/values":
# Raises exceptions on failure # Raises exceptions on failure
@@ -237,7 +242,7 @@ class HCDevice:
# Raises exception on failure # Raises exception on failure
self.test_program_data(data) self.test_program_data(data)
msg["data"] = [data] msg["data"] = data
try: try:
self.ws.send(msg) self.ws.send(msg)