Skip to content

Commit

Permalink
Check for errors also in the command payload (#173)
Browse files Browse the repository at this point in the history
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"}}}
  • Loading branch information
rytilahti authored Jun 3, 2019
1 parent 60add6f commit a475233
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pyHS100/smartdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,18 @@ def _query_helper(self,

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
Expand Down

0 comments on commit a475233

Please sign in to comment.