python-kasa icon indicating copy to clipboard operation
python-kasa copied to clipboard

HS107 reports `state` not `relay_state` throwing a `KeyError`

Open bdruth opened this issue 3 years ago • 1 comments

  File "/opt/homebrew/lib/python3.9/site-packages/kasa/smartplug.py", line 54, in is_on
    return bool(sys_info["relay_state"])
KeyError: 'relay_state'
❯ kasa --type plug --host 192.168.x.x sysinfo
== System info ==
{'alias': 'TP-LINK_Smart Plug_XXXX',
 'child_num': 2,
 'children': [{'alias': 'Window 1',
               'id': 'XXXX',
               'next_action': {'type': -1},
               'on_time': 10422,
               'state': 1},
              {'alias': 'Window 2',
               'id': 'XXXX',
               'next_action': {'type': -1},
               'on_time': 10421,
               'state': 1}],
 'deviceId': 'XXXX',
 'err_code': 0,
 'feature': 'TIM',
 'hwId': 'XXXX',
 'hw_ver': '1.0',
 'latitude_i': 0,
 'led_off': 0,
 'longitude_i': 0,
 'mac': '98:DA:C4:XX:XX:XX',
 'mic_type': 'IOT.SMARTPLUGSWITCH',
 'model': 'HS107(US)',
 'oemId': 'XXXX',
 'rssi': -50,
 'status': 'new',
 'sw_ver': '1.0.10 Build 200622 Rel.142540',
 'updating': 0}

If I have a moment, I'll see if I can sort a PR for this, but in the meantime, wanted to get it reported. No idea if this is from new firmware or not, I just started using python-kasa.

Cheers & great work on this!

bdruth avatar Jun 25 '22 21:06 bdruth

You are getting the error as you are using the wrong device type, if you use --type strip the error should disappear :-) The cli tool defaults to automatic detection for a reason, but maybe the device type could be made visible in the status output for those who prefer to avoid autodetection?

rytilahti avatar Jun 26 '22 21:06 rytilahti