Code Monkey home page Code Monkey logo

pyhs100's People

Contributors

amelchio avatar annikajayuk avatar bmoregeo avatar dberlin avatar dieselrabbit avatar gadgetreactor avatar gollo avatar jimboca avatar jschisurf avatar khenriks avatar kirichkov avatar kochinc avatar kwazel avatar mlebrun avatar mweinelt avatar newam avatar pete1450 avatar peterjgrainger avatar rytilahti avatar salbertson avatar scop avatar smaggard avatar tempse avatar titilambert avatar trainman419 avatar tripzero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyhs100's Issues

SyntaxError: invalid syntax

I receive this error when I try to run a example!
smartdevice.py", line 43
ip_address: str,
SyntaxError: invalid syntax

and
pytest = 3 errors

Getting python errors?

Hi guys, not sure if this is down to my inexperience or whatever but I've had a previous library of pyHS100 working fine, and decided to download a zip of a more recent version today.

I've effectively replaced the psHS100 folder, but in my code I now get an error originating from psHS100.py

File "pyHS100.py", line 65
    raise SmartDeviceException('Communication error') from ex
                                                         ^
SyntaxError: invalid syntax

Any ideas? I've reverted back to the previous library I was using assuming there are syntax errors in the current version of the library...

Update README and prepare 0.3 release

This task is a proposal to start working towards a new release. I would propose we will make it 0.3 considering that this breaks the API and is the first release to drop python2 support from the code-base. A preliminary list of changes follows.


API break:

  • Python2 support has been dropped.
  • pyHS100/pyHS100.py has been splitted to smartdevice.py, smartplug.py and smartbulb.py, no one should have ever accessed these directly though.
  • SmartPlugException is no more, SmartDeviceException is used by both SmartPlug and SmartBulb
  • Discovery has been moved from TPLinkSmartHomeProtocol into its own class for easier 3rd party use.

Other changes:

  • CLI tool supports device discovery and is usable without specifying device type or IP for testing
  • CLI tool supports changing bulb-specific settings
  • Library support & unit tests are extended to cover more devices.
    • Supported plugs: HS100, HS105, HS110
    • Supported switches: HS200
    • Supported bulbs: LB100, LB110, LB120, LB130

Exception timed out / protocol.py, line 99, in discover

Hello,
i've got an exception by calling the discover.py
See attached screenshot.
After the "socket.timeout: timed out" line it showes the results...

Sry for my short request, this is my first Issue submit in GitHub. :)

grafik

Project Management

Hi,

here we are. Stuck for months now :(

I think it's advisable to fork as to not halt progress any further. There are a few pull requests in the pipeline, and the mess from the SmartBulb merge still has to be cleaned up.

I myself do not own a HS100, my parents do though , so testing is difficult for me.

Maybe @rytilahti or @kirichkov may want to chime in?

Porting pyHS100 to MicroPyton

Hi,

I'm trying to port part of the library pyHS100 to micropython, the idea is to be able to run it on an embedded wifi IOT device as a mobile on/off switch (for a start).

Any idea if should this be a fork ?

N

Adding to the API

I just wanted to let ya know I am adding the following to the API. I will submit a PR when I am done.
system:
setting device id*
setting hardware id*
setting location*
setting time zone
setting time
rebooting*
testing uboot*
checking config*
resetting device to factory defaults*

firmware:
setting firmware download url*
getting firmware list
downloading firmware*
installing firmware*

wifi:
scanning access points*
connecting to access point*

cloud:
getting cloud information
setting cloud server url
connecting to cloud server
unregistering device from the cloud

meter:
getting meter voltage gain and current gain
setting meter voltage gain and current gain
meter calibration

schedule:
getting schedule
getting next scheduled action
editing a schedule item
deleting schedule item
delete schedule for a device

countdown - action to perform one time after a given period of time:
adding countdown
editing countdown
deleting countdown
deleting all countdowns

anti-theft - actions to perform when mode is set to away:
get anti-theft list
new anti-theft
edit anti-theft
delete anti-theft
delete all anti-theft

*DONE

I also wanted to inform you that I have made a GUI front end with events that can be assigned to do different things when various states change.

Software can be downloaded here: http:\www.eventghost.org
And the plugin that goes into the software can be had here: http://www.eventghost.net/forum/viewtopic.php?f=2&t=9648&p=46019#p46019

just in case you wanted to check it out.

HS105 Testing

First let me thank all to have contributed. Installed via pip. I am testing some HS105's and deciding whether to try to incorporate instead of a LOT of Insteon devices. I have two units on the same subnet and have done some testing from both the local subnet and on a different subnet. I see errors on both, but from a basic level I can turn them on and off! I thought the errors were related to no lat/lon, but that is not the case as you can see below. Curious what might be the cause of the traceback errors and whether I should or should not be able to run from a remote subnet all the commands?

Thanks,
Mark

Here are the results from the local subnet:
Only works when on the local subnet...Testing a HS105
Running arp -n | grep 50:c7:bf | cut -d' ' -f1
10.50.10.134
10.50.10.184
Running pyhs100 discover
Discovering devices for 5 seconds
Found device: {'ip': '10.50.10.184',
'port': 9999,
'sys_info': {'emeter': {'get_realtime': {'err_code': -1,
'err_msg': 'module not support'}},
'system': {'get_sysinfo': {'active_mode': 'none',
'alias': 'Test Unit',
'dev_name': 'Smart Wi-Fi Plug '
'Mini',
'deviceId': '8006F7570EE99A00308CFFFF27C81B591875827E',
'err_code': 0,
'feature': 'TIM',
'fwId': '00000000000000000000000000000000',
'hwId': 'E5D7E6089B060EF662783C23AE110522',
'hw_ver': '1.0',
'icon_hash': '',
'latitude_i': 306248,
'led_off': 0,
'longitude_i': -975717,
'mac': '50:C7:BF:5F:DC:03',
'model': 'HS105(US)',
'oemId': '003E098AF0D44D4BAB796B3F6A7A830E',
'on_time': 0,
'relay_state': 0,
'rssi': -44,
'sw_ver': '1.2.1 Build 170406 '
'Rel.135348',
'type': 'IOT.SMARTPLUGSWITCH',
'updating': 0}}}}
Running pyhs100 --ip 10.50.10.184 sysinfo
== System info ==
{'active_mode': 'none',
'alias': 'Test Unit',
'dev_name': 'Smart Wi-Fi Plug Mini',
'deviceId': '8006F7570EE99A00308CFFFF27C81B591875827E',
'feature': 'TIM',
'fwId': '00000000000000000000000000000000',
'hwId': 'E5D7E6089B060EF662783C23AE110522',
'hw_ver': '1.0',
'icon_hash': '',
'latitude_i': 306248,
'led_off': 0,
'longitude_i': -975717,
'mac': '50:C7:BF:5F:DC:03',
'model': 'HS105(US)',
'oemId': '003E098AF0D44D4BAB796B3F6A7A830E',
'on_time': 0,
'relay_state': 0,
'rssi': -45,
'sw_ver': '1.2.1 Build 170406 Rel.135348',
'type': 'IOT.SMARTPLUGSWITCH',
'updating': 0}
Running pyhs100 --ip 10.50.10.184 on
Turning on..
Running pyhs100 --ip 10.50.10.184 off
Turning off..
Running pyhs100 --ip 10.50.10.184 state
== Test Unit - HS105(US) ==
Device state: OFF
LED state: True
Time: 2017-06-25 19:51:15
On since: 2017-06-25 19:51:41.059299
Hardware: 1.0
Software: 1.2.1 Build 170406 Rel.135348
MAC (rssi): 50:C7:BF:5F:DC:03 (-45)
Traceback (most recent call last):
File "/usr/local/bin/pyhs100", line 11, in
sys.exit(cli())
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/pyHS100/cli.py", line 70, in state
click.echo("Location: %s" % plug.location)
File "/usr/local/lib/python3.4/dist-packages/pyHS100/pyHS100.py", line 251, in location
return {"latitude": info["latitude"],
KeyError: 'latitude'
Running pyhs100 --ip 10.50.10.184 emeter NOTE: HS105's do not have emeter
== Emeter ==
Device has no emeter
Running pyhs100 --ip 10.50.10.184 led
LED state: True

And from a remote subnet the same commands to the same device.
Only works when on the local subnet...Testing a HS105
Running arp -n | grep 50:c7:bf | cut -d' ' -f1
Running pyhs100 discover
Discovering devices for 5 seconds
Running pyhs100 --ip 10.50.10.184 sysinfo
== System info ==
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 71, in _query_helper
request={target: {cmd: arg}}
File "/usr/local/lib/python3.5/dist-packages/pyHS100/protocol.py", line 58, in query
chunk = sock.recv(4096)
socket.timeout: timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/bin/pyhs100", line 11, in
sys.exit(cli())
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/pyHS100/cli.py", line 51, in sysinfo
click.echo(pformat(plug.sys_info))
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 91, in sys_info
return self.get_sysinfo()
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 101, in get_sysinfo
return self._query_helper("system", "get_sysinfo")
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 74, in _query_helper
raise_from(SmartPlugException(), ex)
File "/usr/local/lib/python3.5/dist-packages/future/utils/init.py", line 398, in raise_from
exec(execstr, myglobals, mylocals)
File "", line 1, in
pyHS100.pyHS100.SmartPlugException
Running pyhs100 --ip 10.50.10.184 on
Turning on..
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 71, in _query_helper
request={target: {cmd: arg}}
File "/usr/local/lib/python3.5/dist-packages/pyHS100/protocol.py", line 58, in query
chunk = sock.recv(4096)
socket.timeout: timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/bin/pyhs100", line 11, in
sys.exit(cli())
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/pyHS100/cli.py", line 119, in on
plug.turn_on()
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 724, in turn_on
self._query_helper("system", "set_relay_state", {"state": 1})
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 74, in _query_helper
raise_from(SmartPlugException(), ex)
File "/usr/local/lib/python3.5/dist-packages/future/utils/init.py", line 398, in raise_from
exec(execstr, myglobals, mylocals)
File "", line 1, in
pyHS100.pyHS100.SmartPlugException
Running pyhs100 --ip 10.50.10.184 off
Turning off..
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 71, in _query_helper
request={target: {cmd: arg}}
File "/usr/local/lib/python3.5/dist-packages/pyHS100/protocol.py", line 58, in query
chunk = sock.recv(4096)
socket.timeout: timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/bin/pyhs100", line 11, in
sys.exit(cli())
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/pyHS100/cli.py", line 127, in off
plug.turn_off()
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 732, in turn_off
self._query_helper("system", "set_relay_state", {"state": 0})
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 74, in _query_helper
raise_from(SmartPlugException(), ex)
File "/usr/local/lib/python3.5/dist-packages/future/utils/init.py", line 398, in raise_from
exec(execstr, myglobals, mylocals)
File "", line 1, in
pyHS100.pyHS100.SmartPlugException
Running pyhs100 --ip 10.50.10.184 state
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 71, in _query_helper
request={target: {cmd: arg}}
File "/usr/local/lib/python3.5/dist-packages/pyHS100/protocol.py", line 58, in query
chunk = sock.recv(4096)
socket.timeout: timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/bin/pyhs100", line 11, in
sys.exit(cli())
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/pyHS100/cli.py", line 59, in state
click.echo(click.style("== %s - %s ==" % (plug.alias, plug.model),
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 136, in alias
return self.sys_info['alias']
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 91, in sys_info
return self.get_sysinfo()
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 101, in get_sysinfo
return self._query_helper("system", "get_sysinfo")
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 74, in _query_helper
raise_from(SmartPlugException(), ex)
File "/usr/local/lib/python3.5/dist-packages/future/utils/init.py", line 398, in raise_from
exec(execstr, myglobals, mylocals)
File "", line 1, in
pyHS100.pyHS100.SmartPlugException
Running pyhs100 --ip 10.50.10.184 emeter NOTE: HS105's do not have emeter
== Emeter ==
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 71, in _query_helper
request={target: {cmd: arg}}
File "/usr/local/lib/python3.5/dist-packages/pyHS100/protocol.py", line 58, in query
chunk = sock.recv(4096)
socket.timeout: timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/bin/pyhs100", line 11, in
sys.exit(cli())
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/pyHS100/cli.py", line 84, in emeter
if not plug.has_emeter:
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 742, in has_emeter
return SmartPlug.FEATURE_ENERGY_METER in self.features
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 752, in features
features = self.sys_info['feature'].split(':')
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 91, in sys_info
return self.get_sysinfo()
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 101, in get_sysinfo
return self._query_helper("system", "get_sysinfo")
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 74, in _query_helper
raise_from(SmartPlugException(), ex)
File "/usr/local/lib/python3.5/dist-packages/future/utils/init.py", line 398, in raise_from
exec(execstr, myglobals, mylocals)
File "", line 1, in
pyHS100.pyHS100.SmartPlugException
Running pyhs100 --ip 10.50.10.184 led
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 71, in _query_helper
request={target: {cmd: arg}}
File "/usr/local/lib/python3.5/dist-packages/pyHS100/protocol.py", line 58, in query
chunk = sock.recv(4096)
socket.timeout: timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/bin/pyhs100", line 11, in
sys.exit(cli())
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/pyHS100/cli.py", line 111, in led
click.echo("LED state: %s" % plug.led)
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 769, in led
return bool(1 - self.sys_info["led_off"])
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 91, in sys_info
return self.get_sysinfo()
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 101, in get_sysinfo
return self._query_helper("system", "get_sysinfo")
File "/usr/local/lib/python3.5/dist-packages/pyHS100/pyHS100.py", line 74, in _query_helper
raise_from(SmartPlugException(), ex)
File "/usr/local/lib/python3.5/dist-packages/future/utils/init.py", line 398, in raise_from
exec(execstr, myglobals, mylocals)
File "", line 1, in
pyHS100.pyHS100.SmartPlugException

Issue receiving state of switch

I updated home assistant last night to .34 and it pulled down the latest pyHS100. My hs200 wall switches are now able to be controlled which is great! However, turning a hs100/hs110/hs200 on from home assistant turns the light on, but after a second, home assistant toggle flips to off. The light switch physically still stays on though. Reloading the ha interface shows the switch as off. I can tap to toggle it on and the switch physically stays on. If I tap it again to turn it off, it will turn off the switch. It appears as if it is unable to poll the device to receive its state after the last update.

HS105 support

I've recently picked up an HS105 and I'd like to get it set up with HomeAssistant.

I tried adding it to my config following https://home-assistant.io/components/switch.tplink/ , but it hangs at INFO:homeassistant.components.switch:Setting up switch.tplink

Given https://community.home-assistant.io/t/compatibility-with-tp-link-smart-plugs/7005/3 , it sounds like there's probably some incompatibility with the HS105 .

I'm quite familiar with linux and python, but new in this area. What can I do to help debug?

Discover devices in the network

I recently wrote a script to find devices and then use the library to control a WiFi plug. I think it would be easy if the library can include a device search in the network, so that users can find the device IP addresses.

HS105 "module not support" + timeout

python 3.6, OSX Sierra (er, MacOS Sierra), pyHS100 0.2.3, which should support the HS105 per #18 and #30:

$ pip3 show pyHS100
Name: pyHS100
Version: 0.2.3

$ python3 examples/discover.py
DEBUG:pyHS100.protocol:Sending discovery to 255.255.255.255:9999
DEBUG:pyHS100.protocol:Waiting 5 seconds for responses...
ERROR:pyHS100.protocol:Got exception timed out
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pyHS100/protocol.py", line 99, in discover
    data, addr = sock.recvfrom(4096)
socket.timeout: timed out
Found device!
{'ip': '192.168.0.221',
 'port': 9999,
 'sys_info': {'emeter': {'err_code': -1, 'err_msg': 'module not support'},
              'system': {'get_sysinfo': {'active_mode': 'schedule',
                                         'alias': 'TV lamp',
                                         'dev_name': 'Smart Wi-Fi Plug Mini',
                                         'deviceId': '800630A6D01BE4Axxxxx',
                                         'err_code': 0,
                                         'feature': 'TIM',
                                         'fwId': '00000000000000000000000000000000',
                                         'hwId': 'E5D7E6089B060EFxxxxxx',
                                         'hw_ver': '1.0',
                                         'icon_hash': '',
                                         'latitude_i': 45xxx,
                                         'led_off': 0,
                                         'longitude_i': -122xxx,
                                         'mac': '50:C7:BF:xxxxx',
                                         'model': 'HS105(US)',
                                         'oemId': '003E098AF0D44D4BAB7xxxxxxxx',
                                         'on_time': 0,
                                         'relay_state': 0,
                                         'rssi': -61,
                                         'sw_ver': '1.0.6 Build 160722 '
                                                   'Rel.081616',
                                         'type': 'IOT.SMARTPLUGSWITCH',
                                         'updating': 0}}}}

$ python3 examples/cli.py 192.168.0.221
DEBUG:pyHS100.protocol:> (31) {"system": {"get_sysinfo": {}}}
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pyHS100/pyHS100.py", line 99, in _query_helper
    request={target: {cmd: arg}}
  File "/usr/local/lib/python3.6/site-packages/pyHS100/protocol.py", line 59, in query
    sock.shutdown(socket.SHUT_RDWR)
OSError: [Errno 57] Socket is not connected

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "examples/cli.py", line 15, in <module>
    logging.info("Identify: %s", hs.identify())
  File "/usr/local/lib/python3.6/site-packages/pyHS100/pyHS100.py", line 317, in identify
    info = self.sys_info
  File "/usr/local/lib/python3.6/site-packages/pyHS100/pyHS100.py", line 119, in sys_info
    return self.get_sysinfo()
  File "/usr/local/lib/python3.6/site-packages/pyHS100/pyHS100.py", line 171, in get_sysinfo
    return self._query_helper("system", "get_sysinfo")
  File "/usr/local/lib/python3.6/site-packages/pyHS100/pyHS100.py", line 102, in _query_helper
    raise SmartPlugException(ex) from ex
pyHS100.pyHS100.SmartPlugException: [Errno 57] Socket is not connected

$ telnet 192.168.0.221 9999
Trying 192.168.0.221...
Connected to 192.168.0.221.
Escape character is '^]'.

Running problems Win 7 Idle 2.7.3

Hi!

I have already installed python2.7 idle with setuptools, python-future-master, python-geoip-master
What do you think, how can I fix this problems?

I had this problems in first test:
Uploading github.jpg…

License mismatch

The LICENSE file states this is licensed under GPLv3 but the setup.py refers to MIT.

Trouble Connecting to Socket

I'm having trouble connecting to the HS100 device with pyHS100.

I'm using homeassistant, and here's the error I get when I start it up:

Traceback (most recent call last):
  File "~/.virtualenvs/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 150, in _async_setup_platform
    entity_platform.add_entities, discovery_info
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/futures.py", line 361, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
    future.result()
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "~/.virtualenvs/homeassistant/lib/python3.5/site-packages/homeassistant/components/switch/tplink.py", line 41, in setup_platform
    add_devices([SmartPlugSwitch(SmartPlug(host), name)], True)
  File "~/Code/homeassistant/deps/pyHS100/pyHS100.py", line 73, in __init__
    self.initialize()
  File "~/Code/homeassistant/deps/pyHS100/pyHS100.py", line 83, in initialize
    self.sys_info = self.get_sysinfo()
  File "~/Code/homeassistant/deps/pyHS100/pyHS100.py", line 161, in get_sysinfo
    return self._query_helper("system", "get_sysinfo")
  File "~/Code/homeassistant/deps/pyHS100/pyHS100.py", line 100, in _query_helper
    request={target: {cmd: arg}}
  File "~/Code/homeassistant/deps/pyHS100/pyHS100.py", line 560, in query
    sock.shutdown(socket.SHUT_RDWR)
OSError: [Errno 57] Socket is not connected

I tried interacting directly with pyHS100, and I still cannot connect. But I get a slightly different error:

>>> from pyHS100 import *
>>> p=SmartPlug('10.0.1.33')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/Code/homeassistant/deps/pyHS100/pyHS100.py", line 73, in __init__
    self.initialize()
  File "~/Code/homeassistant/deps/pyHS100/pyHS100.py", line 83, in initialize
    self.sys_info = self.get_sysinfo()
  File "~/Code/homeassistant/deps/pyHS100/pyHS100.py", line 161, in get_sysinfo
    return self._query_helper("system", "get_sysinfo")
  File "~/Code/homeassistant/deps/pyHS100/pyHS100.py", line 100, in _query_helper
    request={target: {cmd: arg}}
  File "~/Code/homeassistant/deps/pyHS100/pyHS100.py", line 548, in query
    sock.connect((host, port))
TimeoutError: [Errno 60] Operation timed out

I found this script, and I've used it to verify I can actually connect to the device (but I guess not with a socket?):

$ hs100 10.0.1.13 9999 status
found 0 associations
found 1 connections:
     1: flags=82<CONNECTED,PREFERRED>
  outif en2
  src 10.0.1.9 port 56448
  dst 10.0.1.13 port 9999
  rank info not available
  TCP aux info available

Connection to 10.0.1.13 port 9999 [tcp/distinct] succeeded!
{"system":{"get_sysinfo":{"err_code":0,"sw_ver":"1.1.1 Build 160725 Rel.163650","hw_ver":"1.0","type":"IOT.SMARTPLUGSWITCH","model":"HS100(US)","mac":"...","deviceId":"...","hwId":"...","fwId":"...","oemId":"...","alias":"...","dev_name":"Wi-Fi Smart Plug","icon_hash":"","relay_state":0,"on_time":0,"active_mode":"none","feature":"TIM","updating":0,"rssi":-50,"led_off":0,"latitude":0,"longitude":0}}}

Any help would be appreciated!

when plug hasn't had lat/long setup, exception is thrown

When lat/long have not been set up, sysinfo shows latitude_i and longitude_i set to 0, and there is
no entry for latitude or longitude

Traceback (most recent call last):
  File "/usr/local/bin/pyhs100", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pyHS100/cli.py", line 70, in state
    click.echo("Location:     %s" % plug.location)
  File "/usr/local/lib/python2.7/dist-packages/pyHS100/pyHS100.py", line 251, in location
    return {"latitude": info["latitude"],
KeyError: u'latitude'

Trying to get state with pyhs100 on LB100 fails.

Additionally I tried on/off but those didn't do anything and there was no response.

This is the error output:

$ pyhs100 --ip 172.16.1.132 state
== Bedroom Light - LB100(US) ==
Traceback (most recent call last):
  File "/usr/local/bin/pyhs100", line 9, in <module>
    load_entry_point('pyHS100==0.2.4.2', 'console_scripts', 'pyhs100')()
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/pyHS100-0.2.4.2-py3.5.egg/pyHS100/cli.py", line 67, in state
    click.echo(click.style("Device state: %s" % plug.state,
  File "/usr/local/lib/python3.5/dist-packages/pyHS100-0.2.4.2-py3.5.egg/pyHS100/smartplug.py", line 55, in state
    relay_state = self.sys_info['relay_state']
KeyError: 'relay_state'

Home Assistant Integration?

Has anyone tried to integrate this with Home Assistant? If so, can you please post your configuration file?

brightness is 100% when dark bulb set to on in scene

Here is the use case.

turn the bulb off, maybe like this:
scene:

  • name: livingroom dark
    entities:
    light.lb1201
    state: off

then, turn the bulb on, maybe like this:

  • name: livingroom motion
    entities:
    light.lb1201
    state: on
    brightness: 5

notice that the light turns on, but brightness is full
then call the livingroom.motion scene again without turning off the light
notice that the light is now at brightness: 5

the behavior suggests that turning on a bulb that is in a state of 'off' does not consider the requested brightness setting.

however, here is another possible cause. after doing some testing this morning, i think the power state of the LB120 at turn on is influenced by how the bulb has been configured in KASA. For instance, i had one bulb that was configured to turn on based upon last power setting and another that was configured to turn own based upon a preset. this is still very much a hunch and i would suggest that it deserves further investigation. the two bulbs behave differently when turned on from scenes that have brightness settings. the bulb set to open using preset always came on bright. after i changed it to come on from last power setting, that it what is does now when i turn it on from hass scenes. it will always turn on using the brightness from the last scene in which the bulb was on.

homeassistant version 0.51.2
ubuntu 16.x
LB120 bulbs

happy to provide log content. just not sure how to get what you would find useful
hope this helps

This module would also support the HS200 wall switch if you would include it in models.

I modified the latest code locally on my home assistant server and it worked perfectly with a hs200 wall switch. It works exactly as an HS100 switch

def _identify_model(self):
"""Query sysinfo and determine model"""
sys_info = self.get_info()

    if sys_info["system"]["get_sysinfo"]["model"][:5] == 'HS100':
        model = 100
    elif sys_info["system"]["get_sysinfo"]["model"][:5] == 'HS200':
        model = 100
    elif sys_info["system"]["get_sysinfo"]["model"][:5] == 'HS110':
        model = 110

    return model

New firmware breaks the energy meter

As per this post it appears there’s a firmware 2.0 for the switches and it returns different keys for the emeter.

The keys appear to now include also the SI unit they return:

{‘total_wh’: 2, ‘voltage_mv’: 240645, ‘current_ma’: 22, ‘power_mw’: 0}

Version bump

The version in setup.py should be bumped (0.2.1?) so that software that depends on it can get the updated version.

Continous Integration

We should set up some continous integration, like

  • pylint
  • flake8
  • Hound-CI

It will help keep the code clean and make for a more consistent and easy review.

Change to description

The description currently states that this is only for switches which at this point i think that it controls all devices. but also in the README.md is states there are no bulb specific commands.

I know this would be hard to consider but instead of pyHS100 for the name something like pyTPLink or pyTPLinkAPI may be more suitable.

just a suggestion. because this has grown beyond controlling just the switches.

HS100 UK Version does not respond to switch off

When setting the slider to on for any of the TP Link switches it switches to ON. After a while the slider moves automatically to off and the switch remains open.
Trying again has no effect to the state of the switch - it remains open.

Terminal (OS X) sends the following:
17-04-06 00:17:33 WARNING (<concurrent.futures.thread.ThreadPoolExecutor object at 0x103c15be0>_9) [homeassistant.components.switch.tplink] Could not read state for Main Reading Light: [Errno 57] Socket is not connected

python AttributeError: 'module' object has no attribute 'inet_pton'

Windows 10 py 2.7

Worked around this issue by running below from cmd, then in pyHS100.py I added import win_inet_pton, at top of code body on line 23.

pip install win_inet_pton

you may want to get this install going via pip, and mark win_inet_pton as a dependency for windows machines... It isnt necessary on mac os \ linux

Set timezone functionality

In reviewing the code I came across

@time.setter
    def time(self, ts):
    raise NotImplementedError("Fails with err_code == 0 with HS110.")

and the associated notes that it does not appear to be functioning properly.

It does not surprise me that the time, itself, can't be set, after watching how aggressively an HS-110 tries to find an NTP server, cycling through around a dozen different host names.

On the other hand, I "guessed" that index 6 was the proper timezone to use at my location and it did accept the change, both in terms of changing the timezone returned, as well as the time offset.

I don't have a list of the zones, which would be, shall we say, "helpful" in putting together a timezone setter. If this is enough of a desire, I can try to determine what the options are, hopefully without bricking my HS-110...

I don't know the relative priority for this, as not all users are adverse to using the TP-Link phone app to configure their devices. At least for me, it's one less thing I have to worry about, especially given the recent revelations about Uber's iPhone app and TP-Link's history of backdoors.

Error importing to Python on Raspberry Pi

I am trying to implement pyHS100 on a Raspberry Pi 3. Python throws an "invalid syntax" error at the line "from phHS100 import SmartPlug::

**Traceback (most recent call last):
File "test.py", line 4, in
from pyHS100 import SmartPlug
File "/home/pi/Programs/test/pyHS100/pyHS100/init.py", line 16, in
from .smartdevice import SmartDevice
File "/home/pi/Programs/test/pyHS100/pyHS100/smartdevice.py", line 65
raise SmartDeviceException('Communication error') from ex
^
SyntaxError: invalid syntax

Any help with this will be MOST appreciated!

Thank you!

Socket timeout/Communication error for LB110

Hi,
I'm getting a socket timeout error when trying to get the state of my LB110 through python. When using "pyhs100 discover" on the command line I'm able to see and get info from the LB110 but not through python.

Traceback (most recent call last):
File "d:/Documents/Coding/Python/PyLight/main.py", line 9, in
print("Current bulb state: " + bulb.state)
File "C:\Users\jonvt\AppData\Local\Programs\Python\Python35\lib\site-packages\pyhs100-0.2.4.2-py3.5.egg\pyHS100\smartbulb.py", line 238, in state
light_state = self.get_light_state()
File "C:\Users\jonvt\AppData\Local\Programs\Python\Python35\lib\site-packages\pyhs100-0.2.4.2-py3.5.egg\pyHS100\smartbulb.py", line 116, in get_light_state
"get_light_state")
File "C:\Users\jonvt\AppData\Local\Programs\Python\Python35\lib\site-packages\pyhs100-0.2.4.2-py3.5.egg\pyHS100\smartbulb.py", line 64, in _query_helper
request={target: {cmd: arg}}
File "C:\Users\jonvt\AppData\Local\Programs\Python\Python35\lib\site-packages\pyhs100-0.2.4.2-py3.5.egg\pyHS100\protocol.py", line 44, in query
sock.connect((host, port))
socket.timeout: timed out

D:\Documents\Coding\Python\PyLight>python d:/Documents/Coding/Python/PyLight/main.py
Traceback (most recent call last):
File "C:\Users\jonvt\AppData\Local\Programs\Python\Python35\lib\site-packages\pyhs100-0.2.4.2-py3.5.egg\pyHS100\pyHS100.py", line 62, in _query_helper
request={target: {cmd: arg}}
File "C:\Users\jonvt\AppData\Local\Programs\Python\Python35\lib\site-packages\pyhs100-0.2.4.2-py3.5.egg\pyHS100\protocol.py", line 44, in query
sock.connect((host, port))
socket.timeout: timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "d:/Documents/Coding/Python/PyLight/main.py", line 9, in
print("Current bulb state: " + bulb.state)
File "C:\Users\jonvt\AppData\Local\Programs\Python\Python35\lib\site-packages\pyhs100-0.2.4.2-py3.5.egg\pyHS100\smartbulb.py", line 238, in state
light_state = self.get_light_state()
File "C:\Users\jonvt\AppData\Local\Programs\Python\Python35\lib\site-packages\pyhs100-0.2.4.2-py3.5.egg\pyHS100\smartbulb.py", line 116, in get_light_state
"get_light_state")
File "C:\Users\jonvt\AppData\Local\Programs\Python\Python35\lib\site-packages\pyhs100-0.2.4.2-py3.5.egg\pyHS100\pyHS100.py", line 65, in _query_helper
raise SmartDeviceException('Communication error') from ex
pyHS100.types.SmartDeviceException: Communication error

Failing to work with a HS100

Hi,

Im quite poor with python, so my abilities to debug it are quite limited, but getting an issue talking to a HS100 plug, and it appears the plug doesnt reply to some of the commands the protocol is sending:

$ python3 -m cli.py 10.10.20.121
DEBUG:pyHS100.protocol:> (31) {"system": {"get_sysinfo": {}}}
DEBUG:pyHS100.protocol:< (0) 
Traceback (most recent call last):
  File "/root/.homeassistant/deps/pyHS100/pyHS100.py", line 99, in _query_helper
    request={target: {cmd: arg}}
  File "/root/.homeassistant/deps/pyHS100/protocol.py", line 65, in query
    return json.loads(response)
  File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 174, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.5/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/root/pyHS100/examples/cli.py", line 15, in <module>
    logging.info("Identify: %s", hs.identify())
  File "/root/.homeassistant/deps/pyHS100/pyHS100.py", line 317, in identify
    info = self.sys_info
  File "/root/.homeassistant/deps/pyHS100/pyHS100.py", line 119, in sys_info
    return self.get_sysinfo()
  File "/root/.homeassistant/deps/pyHS100/pyHS100.py", line 171, in get_sysinfo
    return self._query_helper("system", "get_sysinfo")
  File "/root/.homeassistant/deps/pyHS100/pyHS100.py", line 102, in _query_helper
    raise SmartPlugException(ex) from ex
pyHS100.pyHS100.SmartPlugException: Expecting value: line 1 column 1 (char 0)

The plug itself is up to date (or at least, kasa claims that it is) and im using the 0.2.3 pyHS100 version

Usinig the nodejs library, which hasnt been updated in a while, the plug does appear to respond correctly to the same command (including this only cause it may help?):

{ sw_ver: '1.0.10 Build 161012 Rel.165510',
  hw_ver: '2.0',
  type: 'IOT.SMARTPLUGSWITCH',
  model: 'HS100(AU)',
  mac: '50:C7:BF:39:87:C5',
  dev_name: 'Smart Wi-Fi Plug',
  alias: 'Plug02',
  relay_state: 1,
  on_time: 272,
  active_mode: 'none',
  feature: 'TIM',
  updating: 0,
  icon_hash: '',
  rssi: -44,
  led_off: 0,
  longitude_i: 1510659,
  latitude_i: -337919,
  hwId: 'D3CB232A2C936C37AE441A16BD2CBE64',
  fwId: '00000000000000000000000000000000',
  deviceId: '80062E7347A7D01037A56CED093D21D318236703',
  oemId: '2768475E8EC1F98BD216C2BF981B2DD1',
  err_code: 0 }

HS110: Connection Refused every few weeks

I'm using a HS110 via Home-Assistant and every few weeks there seems to be a process on the device dying, so it becomes unqueryable, uncontrollable.

Is this a known issue? Is there a solution?

16-10-19 16:53:00 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
  File "/home/martin/home-assistant/env/lib/python3.5/site-packages/homeassistant/core.py", line 1224, in job_handler
    func(*args)
  File "/home/martin/home-assistant/env/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 229, in _update_entity_states
    entity.update_ha_state(True)
  File "/home/martin/home-assistant/env/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 170, in update_ha_state
    self.async_update_ha_state(force_refresh), self.hass.loop
  File "/usr/lib64/python3.5/concurrent/futures/_base.py", line 405, in result
    return self.__get_result()
  File "/usr/lib64/python3.5/concurrent/futures/_base.py", line 357, in __get_result
    raise self._exception
  File "/usr/lib64/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/home/martin/home-assistant/env/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 197, in async_update_ha_state
    state = STATE_UNKNOWN if self.state is None else str(self.state)
  File "/home/martin/home-assistant/env/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 275, in state
    return STATE_ON if self.is_on else STATE_OFF
  File "/home/martin/home-assistant/env/lib/python3.5/site-packages/homeassistant/components/switch/tplink.py", line 54, in is_on
    return self.smartplug.state == 'ON'
  File "/home/martin/.homeassistant/deps/pyHS100/pyHS100.py", line 32, in state
    response = self.hs100_status()
  File "/home/martin/.homeassistant/deps/pyHS100/pyHS100.py", line 79, in hs100_status
    s.connect((self.ip, self.port))
ConnectionRefusedError: [Errno 111] Connection refused

Is it possibly hammering the service until it gives up? The access to the state property is not being throttled, see https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/switch/tplink.py#L51-L54.

LB100 changes in API

Ok so this is what I have thus far.

mic_mac instead of mac
fwId is not supported
time get_time not supported
time get_timezone not supported

I will update this if I find anything else not working. I have a couple of people using the GUI and Event front end I made up for this. So getting real-world information on what works and what doesn't should help. Ideally we will need to go down the line of all of the various model numbers. I am not sure which models are available in the US I am going to have a look see. They aren't very expensive so if they are all available I will go ahead and purchase them. I can provide the following if it will help. VPN access via a dedicated router. and / VM's with almost any OS of your choosing. If the OS supports device redirection then you can use that as well. You would have to let me know how many cores and how much ram you would want for the VM. And I also have a Macintosh I can dust off and get some form of a remote desktop running on it. Let me know if this will help.

types.py clashes with Python standard lib 'types'

Please consider renaming the types.py to device_types.py or similar, as it causes an import error in the click package when running cli.py:

   ImportError: cannot import name 'MappingProxyType'

Reason: Python searches for 'MappingProxyType' in types.py instead of the Python standard library 'types'.

Query State failed on HS100

Hi,
I've run the utility with my smart plug and got this exception on query state.
In order to make discovery working, I've changed target field in TPLinkSmartHomeProtocol.discover to my custom wlan0 broadcast network value.

== My Smart Plug - HS100(EU) ==
Device state: ON
LED state: True
On since: 2017-06-16 09:35:45.934023
== Generic information ==
Time: 1970-01-14 23:19:24
Hardware: 1.0
Software: 1.0.8 Build 151101 Rel.24452
Traceback (most recent call last):
File "/usr/local/bin/pyhs100", line 9, in
load_entry_point('pyHS100==0.2.4.2', 'console_scripts', 'pyhs100')()
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/pyHS100-0.2.4.2-py3.4.egg/pyHS100/cli.py", line 80, in state
click.echo("MAC (rssi): %s (%s)" % (dev.mac, dev.rssi))
File "/usr/local/lib/python3.4/dist-packages/pyHS100-0.2.4.2-py3.4.egg/pyHS100/pyHS100.py", line 302, in rssi
return self.sys_info["rssi"]
KeyError: 'rssi'

I am suspecting that I am doing something wrong, because it seems nobody encountered this issue before.

Traceback in decoding

Title might not be accurate, but with a recent HS100 V2, the component seems to be failing with the error.

The device is function with the app.

Attach screenshot and packet capture.

>>> from pyHS100 import SmartPlug
>>> from pprint import pformat as pf
>>> plug = SmartPlug("192.168.10.27")
>>> print("Alias, type and supported features: %s" % (plug.identify(),))
Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/pyHS100/pyHS100.py", line 99, in _query_helper
    request={target: {cmd: arg}}
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/pyHS100/protocol.py", line 65, in query
    return json.loads(response)
  File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

capture3

HS100.pcap.zip

Regards
Rob

Discover mode not available/documented in library mode

I cannot find any references or managed to use the discover mode when using pyHS100 as library in python 2.7.9.

I can import SmartPlug and SmartBulb but not Discover-classes. If possible, please provide an example in the read me. Looking for how to extract the IP-address and device names from all devices on the network to use directly in my python scripts.

Thank you!
Mikael

KeyError: u'latitude'

Hi,

when running pyhs100 --ip 192.168.0.6 state on Rasberbey Pi I'm getting the below error,

seems like parsing issue?

Nadav

pi@raspberrypi:~ $ sudo pyhs100 --ip 192.168.0.6 state
== Livingroom Light - HS105(US) ==
Device state: ON
LED state: True
Time: 2017-07-22 22:11:07
On since: 2017-07-23 01:53:54.183459
Hardware: 1.0
Software: 1.2.1 Build 170406 Rel.135348
MAC (rssi): 50:C7:BF:7D:56:54 (-22)
Traceback (most recent call last):
File "/usr/local/bin/pyhs100", line 9, in
load_entry_point('pyHS100==0.2.4.2', 'console_scripts', 'pyhs100')()
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pyHS100/cli.py", line 70, in state
click.echo("Location: %s" % plug.location)
File "/usr/local/lib/python2.7/dist-packages/pyHS100/pyHS100.py", line 251, in location
return {"latitude": info["latitude"],
KeyError: u'latitude'

Unclosed socket on macOS

I get many warnings like the following when I turn on debugging on macOS:

/Users/homeassistant/.homeassistant/deps/pyHS100/pyHS100.py:71: ResourceWarning: unclosed <socket.socket fd=14, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('10.0.1.5', 55327), raddr=('10.0.1.13', 9999)>
  request={target: {cmd: arg}}

They disappear if I change the shutdown like suggested in this comment, i.e. close even if the shutdown fails.

LB100 Command Line Test Errors

Trying to figure out if I'm missing something or if its a problem with the module. Any time I run the command line test against a light I get the error trace below. Any thoughts?

./pyhs100 --ip 192.168.1.93
== Couch Lamp - LB100(US) ==
Traceback (most recent call last):
File "./pyhs100", line 11, in
load_entry_point('pyHS100==0.2.4.1', 'console_scripts', 'pyhs100')()
File "/srv/homeassistant/lib/python3.4/site-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/srv/homeassistant/lib/python3.4/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/srv/homeassistant/lib/python3.4/site-packages/click/core.py", line 1043, in invoke
return Command.invoke(self, ctx)
File "/srv/homeassistant/lib/python3.4/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/srv/homeassistant/lib/python3.4/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/srv/homeassistant/lib/python3.4/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/srv/homeassistant/lib/python3.4/site-packages/pyHS100/cli.py", line 34, in cli
ctx.invoke(state)
File "/srv/homeassistant/lib/python3.4/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/srv/homeassistant/lib/python3.4/site-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/srv/homeassistant/lib/python3.4/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/srv/homeassistant/lib/python3.4/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/srv/homeassistant/lib/python3.4/site-packages/pyHS100/cli.py", line 62, in state
click.echo(click.style("Device state: %s" % plug.state,
File "/srv/homeassistant/lib/python3.4/site-packages/pyHS100/pyHS100.py", line 668, in state
relay_state = self.sys_info['relay_state']
KeyError: 'relay_state'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.