diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0a05343d9..c99d152d9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,13 +10,13 @@ repos: - id: check-ast - repo: https://github.com/asottile/pyupgrade - rev: v2.31.0 + rev: v2.31.1 hooks: - id: pyupgrade args: ['--py37-plus'] - repo: https://github.com/python/black - rev: 22.1.0 + rev: 22.3.0 hooks: - id: black @@ -33,7 +33,7 @@ repos: additional_dependencies: [toml] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.931 + rev: v0.942 hooks: - id: mypy additional_dependencies: [types-click] diff --git a/CHANGELOG.md b/CHANGELOG.md index c94510725..89058f1f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,24 @@ # Changelog -## [0.4.2](https://github.com/python-kasa/python-kasa/tree/0.4.2) (2022-03-21) +## [0.4.3](https://github.com/python-kasa/python-kasa/tree/0.4.3) (2022-04-05) + +[Full Changelog](https://github.com/python-kasa/python-kasa/compare/0.4.2...0.4.3) + +**Fixed bugs:** + +- Divide by zero when HS300 powerstrip is discovered [\#292](https://github.com/python-kasa/python-kasa/issues/292) +- Ensure bulb state is restored when turning back on [\#330](https://github.com/python-kasa/python-kasa/pull/330) (@bdraco) + +**Closed issues:** + +- KL420L5 controls [\#327](https://github.com/python-kasa/python-kasa/issues/327) + +**Merged pull requests:** + +- Update pre-commit hooks to fix black in CI [\#331](https://github.com/python-kasa/python-kasa/pull/331) (@rytilahti) +- Fix test\_deprecated\_type stalling [\#325](https://github.com/python-kasa/python-kasa/pull/325) (@bdraco) -This is the last release prior restructuring the code to enable easier extendability by moving towards more modular architecture. -The most prominent change in this release is the support for effects on light strips. +## [0.4.2](https://github.com/python-kasa/python-kasa/tree/0.4.2) (2022-03-21) [Full Changelog](https://github.com/python-kasa/python-kasa/compare/0.4.1...0.4.2) @@ -33,6 +48,7 @@ The most prominent change in this release is the support for effects on light st **Merged pull requests:** +- Release 0.4.2 [\#321](https://github.com/python-kasa/python-kasa/pull/321) (@rytilahti) - Add pyupgrade to CI runs [\#314](https://github.com/python-kasa/python-kasa/pull/314) (@rytilahti) - Depend on asyncclick \>= 8 [\#312](https://github.com/python-kasa/python-kasa/pull/312) (@rytilahti) - Guard emeter accesses to avoid keyerrors [\#304](https://github.com/python-kasa/python-kasa/pull/304) (@rytilahti) diff --git a/kasa/smartbulb.py b/kasa/smartbulb.py index e5dcfbe90..c2d095395 100644 --- a/kasa/smartbulb.py +++ b/kasa/smartbulb.py @@ -34,6 +34,9 @@ class HSV(NamedTuple): r"KL430": ColorTempRange(2500, 9000), } + +NON_COLOR_MODE_FLAGS = {"transition_period", "on_off"} + _LOGGER = logging.getLogger(__name__) @@ -211,8 +214,14 @@ async def set_light_state(self, state: Dict, *, transition: int = None) -> Dict: if "on_off" not in state: state["on_off"] = 1 - # This is necessary to allow turning on into a specific state - state["ignore_default"] = 1 + # If we are turning on without any color mode flags, + # we do not want to set ignore_default to ensure + # we restore the previous state. + if state["on_off"] and NON_COLOR_MODE_FLAGS.issuperset(state): + state["ignore_default"] = 0 + else: + # This is necessary to allow turning on into a specific state + state["ignore_default"] = 1 light_state = await self._query_helper( self.LIGHT_SERVICE, self.SET_LIGHT_METHOD, state diff --git a/kasa/tests/test_bulb.py b/kasa/tests/test_bulb.py index ea8a28cb8..032154424 100644 --- a/kasa/tests/test_bulb.py +++ b/kasa/tests/test_bulb.py @@ -232,3 +232,16 @@ async def test_non_dimmable(dev): assert dev.brightness == 0 with pytest.raises(SmartDeviceException): await dev.set_brightness(100) + + +@bulb +async def test_ignore_default_not_set_without_color_mode_change_turn_on(dev, mocker): + query_helper = mocker.patch("kasa.SmartBulb._query_helper") + # When turning back without settings, ignore default to restore the state + await dev.turn_on() + args, kwargs = query_helper.call_args_list[0] + assert args[2] == {"on_off": 1, "ignore_default": 0} + + await dev.turn_off() + args, kwargs = query_helper.call_args_list[1] + assert args[2] == {"on_off": 0, "ignore_default": 1} diff --git a/kasa/tests/test_cli.py b/kasa/tests/test_cli.py index 499b85520..ae4fa1759 100644 --- a/kasa/tests/test_cli.py +++ b/kasa/tests/test_cli.py @@ -111,13 +111,14 @@ def _generate_type_class_pairs(): @pytest.mark.parametrize("type_class", _generate_type_class_pairs()) -async def test_deprecated_type(dev, type_class): +async def test_deprecated_type(dev, type_class, mocker): """Make sure that using deprecated types yields a warning.""" type, cls = type_class if type == "dimmer": return runner = CliRunner() - res = await runner.invoke(cli, ["--host", "127.0.0.2", f"--{type}"]) + with mocker.patch("kasa.SmartDevice.update"): + res = await runner.invoke(cli, ["--host", "127.0.0.2", f"--{type}"]) assert "Using --bulb, --plug, --strip, and --lightstrip is deprecated" in res.output diff --git a/pyproject.toml b/pyproject.toml index 04adb76f8..9d7e084af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "python-kasa" -version = "0.4.2" +version = "0.4.3" description = "Python API for TP-Link Kasa Smarthome devices" license = "GPL-3.0-or-later" authors = ["Your Name "]