* Drop python 3.7 support
* CI: drop 3.7 and add 3.11
* Remove skipifs that were required for <3.8
* Use pypy-3.8 for CI, re-enable pypy for windows to see if it works now
* Bump readthedocs to use py3.8
* Remove py3.7 failure comment
* Mark mocked fixtures as such
* Use consistent filenames including the swver
* Remove executable bit
* Remove duplicate KL130(US)
* Remove unnecessary mocks where we have real ones available
* Fix filenames in tests
* Make hue, saturation and color_temp optional for smartbulbpresets
* Adjust bulb preset attributes for effect mode
* Don't send None values on save_preset
* Add tests for save_preset payloads
* Basic fix for issue: https://github.com/python-kasa/python-kasa/issues/373
Change usage module get_daystat and get_monthat to return dictionaries of date index: time values as spec'd instead of raw usage data. Output matches emeter module get_daystat and get_monthstat
* Fixed some formatting and lint warnings to comply with black/flake8
Use the new _convert function in emeter for all conversions rather than the one in smartdevice.py
Removed unused function _emeter_convert_emeter_data from smartdevice.py
* Added a first pass test module for testing the new usage conversion function
* Changes based on PR feedback
Tidied up some doc string comments
Added a check for explicit values from conversion function
* Rebase on top of current master, fix docstrings
---------
Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
* Add KP125 test fixture and support note.
Signed-off-by: James Alseth <james@jalseth.me>
* mark KP125 having an emeter
Co-authored-by: Teemu R <tpr@iki.fi>
* Avoid retrying open_connection on unrecoverable errors
- We can retry so hard that we block the event loop
Fixes
```
2022-04-16 22:18:51 WARNING (MainThread) [asyncio] Executing <Task finished name=Task-3576 coro=<open_connection() done, defined at /opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/streams.py:25> exception=ConnectionRefusedError(61, "Connect call failed (192.168.107.200, 9999)") created at /opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py:460> took 1.001 seconds
```
* comment
* Ensure state is restored when turning back on
Fixes https://github.com/home-assistant/core/issues/69039
* Update kasa/tests/test_bulb.py
Co-authored-by: Teemu R. <tpr@iki.fi>
Co-authored-by: Teemu R. <tpr@iki.fi>
* Added motion and light sensor for KS220M
* Added fixture file for ks220m
* Remove dump_devinfo and add the extra queries to devtools/dump_devinfo
* Test KS220M as a dimmer
* Add empty modules to baseproto to make the tests pass
Co-authored-by: mrbetta <bettale@gmail.com>
Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
* 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>
* Cleanup discovery & add tests
* discovered_devices_raw is not anymore available, as that can be accessed directly from the device objects
* test most of the discovery code paths
* some minor cleanups to test handling
* update discovery docs
* Move category check to be after the definitions
* skip a couple of tests requiring asyncmock not available on py37
* Remove return_raw usage from cli.discover
* bulb: allow set_hsv without v, add fallback ct range
* add ColorTempRange and HSV named tuples
* add a fallback color temp range if unknown, log a warning
* set_hsv: the value is now optional
* Fix tests, change fallback range to 2700-5000
* test_cli: provide return values to patched objects to avoid warning about non-awaited calls
* test_cli: restore alias after testing
* smartstrip: remove internal update() calls for turn_{on,off}, set_led
* Make sure power is always a float
* Fix discovery tests
* Make tests runnable on real devices
* Add a note about running tests on a real device
* test_strip: run update against the parent device
Some devices are known to fail when trying to query non-supported modules like emeter information.
This commit makes the initial update() only request the sysinfo, followed up by a second query
if emeter is supported by the device.
* Add real kasa KL430(UN) device dump
* Adjust hue&sat max values
* light strips, as bulbs, have only power for emeter
Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
* Add EP10(US) 1.0 1.0.2 fixture
* Add EP10 fixture to conftest PLUGS list.
* Add EP10 to the list of supported plugs in README
* Revert "Add EP10 to the list of supported plugs in README"
This reverts commit e8bf6551c3.
* Preliminary support for light strips
* Add color temperature range and cleanup, thanks to @darkoppressor
* Use lightstrip instead of {led,light}strip consistently everywhere
* The cli flag is now --lightstrip
* add apidocs
* Add fixture file for KL430
Signed-off-by: Kevin Wells <darkoppressor@gmail.com>
* Add discovery support, expose effect and length of the strip
* use set_light_state instead of transition_light_state
* Add tests for lightstrip
* add doctests
* Add KL430 to supported devices in README
Co-authored-by: Kevin Wells <darkoppressor@gmail.com>
* Add ignore_default to lights to allow setting to specific light state, force bulb on when changing the settings, allow defining brightness for set_color_temp, add a couple of new API methods
* Fix and simplify transition_light_state to make tests pass
* Add doctests to SmartBulb
* Add SmartDevice doctests, cleanup README.md
* add doctests for smartplug and smartstrip
* add discover doctests
* Fix bulb mock
* add smartdimmer doctests
* add sphinx-generated docs, cleanup readme a bit
* remove sphinx-click as it does not work with asyncclick
* in preparation for rtd hooking, move doc deps to be separate from dev deps
* pytestmark needs to be applied separately for each and every file, this fixes the tests
* use pathlib for resolving relative paths
* Skip discovery doctest on python3.7
The code is just fine, but some reason the mocking behaves differently between 3.7 and 3.8.
The latter seems to accept a discrete object for asyncio.run where the former expects a coroutine..
* Adds a transition param to set_brightness(), turn_on(), and turn_off() that specifies the duration in milliseconds that the dimmer switch will take to transition to the new state.
* Fixes bug where set_brightness(0) was allowed even though the dimmer does not support it. Now brightness values of 0 are coerced to 1 to be consistent with bulbs (which do support brightness values of 0).
* 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
* Optimize I/O access
A single update() will now fetch information from all interesting modules,
including the current device state and the emeter information.
In practice, this will allow dropping the number of I/O reqs per homeassistant update cycle to 1,
which is paramount at least for bulbs which are very picky about sequential accesses.
This can be further extend to other modules/methods, if needed.
Currently fetched data:
* sysinfo
* realtime, today's and this months emeter stats
New properties:
* emeter_realtime: return the most recent emeter information, update()-version of get_emeter_realtime()
* emeter_today: returning today's energy consumption
* emeter_this_month: same for this month
Other changes:
* Accessing @requires_update properties will cause SmartDeviceException if the device has not ever been update()d
* Fix __repr__ for devices that haven't been updated
* Smartbulb uses now the state data from get_sysinfo instead of separately querying the bulb service
* SmartStrip's state_information no longer lists onsince for separate plugs
* The above mentioned properties are now printed out by cli
* Simplify is_on handling for bulbs
* remove implicit updates, return device responses for actions, update README.md instructions. fixes#61
* discover dimmers properly
* fix circular import, hopefully
* add is_color to SmartDevice API
* allow changing the dimming without implicitly turning the device on
* Add tests for device type handling for discovery data, make sure new fixtures are added to categories inside conftest
* Convert to use poetry and pyproject.toml, update README
* add some resources for contributors
* minor adjustments
* ci: separate tests from linting, run using poetry
* add pytest-mock to dev requirements
* combine running tests and reporting to codecov
* generate both xml and html coverage reports
* add codecov to dev dependencies
* moves on_since property to smartdevice class, as it is not plug only
* returns None if the value is not available (some bulbs), or if the device is off
* 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}
* Add tests to the cli tool
* add pytest-mock
* do not ignore cli.py for coverage
* read requirements_test.txt instead of redefining reqs in tox.ini
* Add upload to codecov, first try!
* fix name of the result file
* no need to manually publish to azure devops..
* Move dimmer support to its own class
SmartDimmer extends SmartPlug with brightness settings.
This will make the API of SmartPlug less confusing and will
make it simpler to downstream users to act with dimmers.
Fixes#33
* Lint & make tests pass
* Fix rebase after cache and emeter cleanups, hopefully everything went smoothly..
* oopsie, has_emeter was mistakenly included in smartplug
The cache was useful trick when the property accesses caused I/O,
which is unnecessary now as dev.update() does explicitly cache results until its called again.
* All child device handling is moved out from the main smartdevice class, which simplifies the code.
* This will also cleanup the constructors as only the subdevices require the ID and the parent reference.
* SmartStripPlug offers SmartPlug like interface, but does not allow separate updates
* Trying to update() on the children will cause a warning.
* do not update inside __repr__
* Convert discovery to asyncio
* Use asyncio.DatagramProtocol
* Cleanup parameters, no more positional arguments
Closes#7
* Remove sync interface
* This requires #13 to be merged. Closes#12.
* Converts cli to use asyncio.run() where needed.
* The children from smartstrips is being initialized during the first update call.
* Convert on and off commands to use asyncio.run
* conftest: do the initial update automatically for the device, cleans up tests a bit
* return subdevices alias for strip plugs, remove sync from docstrings
* Make tests pass using pytest-asyncio
* Simplify tests and use pytest-asyncio.
* Removed the emeter tests for child devices, as this information do not seem to exist (based on the dummy sysinfo data). Can be added again if needed.
* Remove sync from docstrings.
* Fix incorrect type hint
* Add type hints and some docstrings to discovery