Check for errors also in the command payload (#173)

For example, trying to set unsupported color temperature will cause such response.
This gets ignored at the moment completely, so there is no indication at all why the command caused no effect on the device.

> (93) {"smartlife.iot.smartbulb.lightingservice": {"transition_light_state": {"color_temp": 6000}}}
< (125) {"smartlife.iot.smartbulb.lightingservice":{"transition_light_state":{"err_code":-10000,"err_msg":"Invalid input argument"}}}
This commit is contained in:
Teemu R 2019-06-03 09:58:03 -04:00 committed by GitHub
parent 60add6fa66
commit a475233464
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -125,13 +125,18 @@ class SmartDevice(object):
result = response[target]
if "err_code" in result and result["err_code"] != 0:
raise SmartDeviceException("Error on {}.{}: {}"
raise SmartDeviceException("Error on {} {}: {}"
.format(target, cmd, result))
if cmd not in result:
raise SmartDeviceException("No command in response: {}"
.format(response))
result = result[cmd]
if "err_code" in result and result["err_code"] != 0:
raise SmartDeviceException("Error on {} {}: {}"
.format(target, cmd, result))
del result["err_code"]
return result