Refactor devices into subpackages and deprecate old names (#716)

* Refactor devices into subpackages and deprecate old names

* Tweak and add tests

* Fix linting

* Remove duplicate implementations affecting project coverage

* Update post review

* Add device base class attributes and rename subclasses

* Rename Module to BaseModule

* Remove has_emeter_history

* Fix missing _time in init

* Update post review

* Fix test_readmeexamples

* Fix erroneously duped files

* Clean up iot and smart imports

* Update post latest review

* Tweak Device docstring
This commit is contained in:
Steven B
2024-02-04 15:20:08 +00:00
committed by GitHub
parent 6afd05be59
commit 0d119e63d0
49 changed files with 1046 additions and 606 deletions

View File

@@ -1,27 +1,28 @@
import pytest
from kasa import DeviceType, SmartLightStrip
from kasa import DeviceType
from kasa.exceptions import SmartDeviceException
from kasa.iot import IotLightStrip
from .conftest import lightstrip
@lightstrip
async def test_lightstrip_length(dev: SmartLightStrip):
async def test_lightstrip_length(dev: IotLightStrip):
assert dev.is_light_strip
assert dev.device_type == DeviceType.LightStrip
assert dev.length == dev.sys_info["length"]
@lightstrip
async def test_lightstrip_effect(dev: SmartLightStrip):
async def test_lightstrip_effect(dev: IotLightStrip):
assert isinstance(dev.effect, dict)
for k in ["brightness", "custom", "enable", "id", "name"]:
assert k in dev.effect
@lightstrip
async def test_effects_lightstrip_set_effect(dev: SmartLightStrip):
async def test_effects_lightstrip_set_effect(dev: IotLightStrip):
with pytest.raises(SmartDeviceException):
await dev.set_effect("Not real")
@@ -33,9 +34,9 @@ async def test_effects_lightstrip_set_effect(dev: SmartLightStrip):
@lightstrip
@pytest.mark.parametrize("brightness", [100, 50])
async def test_effects_lightstrip_set_effect_brightness(
dev: SmartLightStrip, brightness, mocker
dev: IotLightStrip, brightness, mocker
):
query_helper = mocker.patch("kasa.SmartLightStrip._query_helper")
query_helper = mocker.patch("kasa.iot.IotLightStrip._query_helper")
# test that default brightness works (100 for candy cane)
if brightness == 100:
@@ -51,9 +52,9 @@ async def test_effects_lightstrip_set_effect_brightness(
@lightstrip
@pytest.mark.parametrize("transition", [500, 1000])
async def test_effects_lightstrip_set_effect_transition(
dev: SmartLightStrip, transition, mocker
dev: IotLightStrip, transition, mocker
):
query_helper = mocker.patch("kasa.SmartLightStrip._query_helper")
query_helper = mocker.patch("kasa.iot.IotLightStrip._query_helper")
# test that default (500 for candy cane) transition works
if transition == 500:
@@ -67,6 +68,6 @@ async def test_effects_lightstrip_set_effect_transition(
@lightstrip
async def test_effects_lightstrip_has_effects(dev: SmartLightStrip):
async def test_effects_lightstrip_has_effects(dev: IotLightStrip):
assert dev.has_effects is True
assert dev.effect_list