Commit Graph

11 Commits

Author SHA1 Message Date
J. Nick Koston
c865d3f02c
Fix unsafe __del__ in TPLinkSmartHomeProtocol (#300)
* Fix unsafe __del__ in TPLinkSmartHomeProtocol

Fixes
```
Exception ignored in: <function TPLinkSmartHomeProtocol.__del__ at 0x1096d0670>
Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/venv/lib/python3.9/site-packages/kasa/protocol.py", line 159, in __del__
    self.writer.close()
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/streams.py", line 353, in close
    return self._transport.close()
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 700, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 748, in call_soon
    self._check_thread()
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 785, in _check_thread
    raise RuntimeError(
RuntimeError: Non-thread-safe operation invoked on an event loop other than the current one
```

* comment

* comment

* comment
2022-01-30 23:00:00 +01:00
Teemu R
bcb9fe18ab
Improve typing for protocol class (#289) 2022-01-14 23:08:25 +01:00
J. Nick Koston
33bc38b57f
Fix lock being unexpectedly reset on close (#218)
* Implement a backoff for legacy devices

* do not clear self.query_lock at close()

* revert backoff
2021-09-26 19:38:33 +02:00
Teemu R
3cf549e32e
Add host information to protocol debug logs (#219) 2021-09-26 19:16:12 +02:00
J. Nick Koston
76c1264dc9
Avoid calling pformat unless debug logging is enabled (#217)
* Avoid calling pformat unless debug logging is enabled

* add logging test

* isort

* check for debug logging

* formatting
2021-09-26 16:50:58 +02:00
J. Nick Koston
e31cc6662c
Keep connection open and lock to prevent duplicate requests (#213)
* Keep connection open and lock to prevent duplicate requests

* option to not update children

* tweaks

* typing

* tweaks

* run tests in the same event loop

* memorize model

* Update kasa/protocol.py

Co-authored-by: Teemu R. <tpr@iki.fi>

* Update kasa/protocol.py

Co-authored-by: Teemu R. <tpr@iki.fi>

* Update kasa/protocol.py

Co-authored-by: Teemu R. <tpr@iki.fi>

* Update kasa/protocol.py

Co-authored-by: Teemu R. <tpr@iki.fi>

* dry

* tweaks

* warn when the event loop gets switched out from under us

* raise on unable to connect multiple times

* fix patch target

* tweaks

* isrot

* reconnect test

* prune

* fix mocking

* fix mocking

* fix test under python 3.7

* fix test under python 3.7

* less patching

* isort

* use mocker to patch

* disable on old python since mocking doesnt work

* avoid disconnect/reconnect cycles

* isort

* Fix hue validation

* Fix latitude_i/longitude_i units

Co-authored-by: Teemu R. <tpr@iki.fi>
2021-09-24 23:25:43 +02:00
J. Nick Koston
b3c8f9769c
Avoid temp array during encrypt and decrypt (#204)
* Avoid temp array during encrypt

* black

* Update kasa/protocol.py

Co-authored-by: Teemu R. <tpr@iki.fi>

* Update kasa/protocol.py

* update decrypt as well

Co-authored-by: Teemu R. <tpr@iki.fi>
2021-09-23 18:11:16 +02:00
Teemu R
9dc0cbaece
Add retries to protocol queries (#65)
* Add retries to query(), defaults to 3 + add tests

* Catch also json decoding errors for retries

* add missing exceptions file, fix old protocol tests
2020-05-27 20:02:09 +03:00
Teemu R
644a10a0d1
General cleanups all around (janitoring) (#63)
* Move tests to device-type specific test files to make improvements more approachable

* protocol: remove the port parameter from query, as there are no other known ports, fix docstrings

* Revise docstrings, remove superfluous information and remove unused methods ({set,get_icon} and set_time)

* cli: indent device output to make it more easily readable when having multiple devices

* remove adjust flake8 ignores (we have no setup.py anymore)

* pyproject: include cli tool to coverage, add config for interrogate (docstring coverage)

* bulb: raise exception on color_temp error cases instead of returning zero values

* improve bulb tests, simplify conftest

* strip: rename plugs property to children and move it to smartdevice
2020-05-27 16:55:18 +02:00
Teemu R
3fe578cf26
async++, small powerstrip improvements (#46)
* async++, small powerstrip improvements

* use asyncclick instead of click, allows defining the commands with async def to avoid manual eventloop/asyncio.run handling
* improve powerstrip support:
  * new powerstrip api: turn_{on,off}_by_{name,index} methods
  * cli: fix on/off for powerstrip using the new apis
* add missing update()s for cli's hsv, led, temperature (fixes #43)
* prettyprint the received payloads when debug mode in use
* cli: debug mode can be activated now with '-d'

* update requirements_test.txt

* remove outdated click-datetime, replace click with asyncclick

* debug is a flag

* make smartstripplug to inherit the sysinfo from its parent, allows for simple access of general plug properties

* proper bound checking for index accesses, allow controlling the plug at index 0

* remove the mess of turn_{on,off}_by_{name,index}, get_plug_by_{name,index} are enough.

* adapt cli to use that
* allow changing the alias per index

* use f-strings consistently everywhere in the cli

* add tests for get_plug_by_{index,name}
2020-04-21 20:46:13 +02:00
Teemu R
3ef5086ffb mass rename to (python-)kasa (#1) 2019-12-18 09:11:18 +01:00