Support JSON arrays in input data
This commit is contained in:
11
HCDevice.py
11
HCDevice.py
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user