Move SmartBulb into SmartDevice (#874)

This commit is contained in:
Steven B
2024-04-29 18:19:44 +01:00
committed by GitHub
parent cb11b36511
commit d3544b4989
11 changed files with 229 additions and 233 deletions

View File

@@ -1,7 +1,5 @@
from __future__ import annotations
from itertools import chain
import pytest
from kasa import (
@@ -11,7 +9,7 @@ from kasa import (
Discover,
)
from kasa.iot import IotBulb, IotDimmer, IotLightStrip, IotPlug, IotStrip, IotWallSwitch
from kasa.smart import SmartBulb, SmartDevice
from kasa.smart import SmartDevice
from .fakeprotocol_iot import FakeIotProtocol
from .fakeprotocol_smart import FakeSmartProtocol
@@ -319,19 +317,7 @@ check_categories()
def device_for_fixture_name(model, protocol):
if "SMART" in protocol:
for d in chain(
PLUGS_SMART,
SWITCHES_SMART,
STRIPS_SMART,
HUBS_SMART,
SENSORS_SMART,
THERMOSTATS_SMART,
):
if d in model:
return SmartDevice
for d in chain(BULBS_SMART, DIMMERS_SMART):
if d in model:
return SmartBulb
return SmartDevice
else:
for d in STRIPS_IOT:
if d in model:

View File

@@ -7,9 +7,9 @@ from voluptuous import (
Schema,
)
from kasa import Bulb, BulbPreset, DeviceType, KasaException
from kasa.iot import IotBulb
from kasa.smart import SmartBulb
from kasa import Bulb, BulbPreset, Device, DeviceType, KasaException
from kasa.iot import IotBulb, IotDimmer
from kasa.smart import SmartDevice
from .conftest import (
bulb,
@@ -30,7 +30,7 @@ from .test_iotdevice import SYSINFO_SCHEMA
@bulb
async def test_bulb_sysinfo(dev: Bulb):
async def test_bulb_sysinfo(dev: Device):
assert dev.sys_info is not None
SYSINFO_SCHEMA_BULB(dev.sys_info)
@@ -43,7 +43,7 @@ async def test_bulb_sysinfo(dev: Bulb):
@bulb
async def test_state_attributes(dev: Bulb):
async def test_state_attributes(dev: Device):
assert "Cloud connection" in dev.state_information
assert isinstance(dev.state_information["Cloud connection"], bool)
@@ -64,7 +64,8 @@ async def test_get_light_state(dev: IotBulb):
@color_bulb
@turn_on
async def test_hsv(dev: Bulb, turn_on):
async def test_hsv(dev: Device, turn_on):
assert isinstance(dev, Bulb)
await handle_turn_on(dev, turn_on)
assert dev.is_color
@@ -114,7 +115,8 @@ async def test_invalid_hsv(dev: Bulb, turn_on):
@color_bulb
@pytest.mark.skip("requires color feature")
async def test_color_state_information(dev: Bulb):
async def test_color_state_information(dev: Device):
assert isinstance(dev, Bulb)
assert "HSV" in dev.state_information
assert dev.state_information["HSV"] == dev.hsv
@@ -131,14 +133,16 @@ async def test_hsv_on_non_color(dev: Bulb):
@variable_temp
@pytest.mark.skip("requires colortemp module")
async def test_variable_temp_state_information(dev: Bulb):
async def test_variable_temp_state_information(dev: Device):
assert isinstance(dev, Bulb)
assert "Color temperature" in dev.state_information
assert dev.state_information["Color temperature"] == dev.color_temp
@variable_temp
@turn_on
async def test_try_set_colortemp(dev: Bulb, turn_on):
async def test_try_set_colortemp(dev: Device, turn_on):
assert isinstance(dev, Bulb)
await handle_turn_on(dev, turn_on)
await dev.set_color_temp(2700)
await dev.update()
@@ -162,7 +166,7 @@ async def test_unknown_temp_range(dev: IotBulb, monkeypatch, caplog):
@variable_temp_smart
async def test_smart_temp_range(dev: SmartBulb):
async def test_smart_temp_range(dev: SmartDevice):
assert dev.valid_temperature_range
@@ -188,7 +192,8 @@ async def test_non_variable_temp(dev: Bulb):
@dimmable
@turn_on
async def test_dimmable_brightness(dev: Bulb, turn_on):
async def test_dimmable_brightness(dev: Device, turn_on):
assert isinstance(dev, (Bulb, IotDimmer))
await handle_turn_on(dev, turn_on)
assert dev.is_dimmable

View File

@@ -61,7 +61,16 @@ async def test_childdevice_properties(dev: SmartChildDevice):
# Skip emeter and time properties
# TODO: needs API cleanup, emeter* should probably be removed in favor
# of access through features/modules, handling of time* needs decision.
if name.startswith("emeter_") or name.startswith("time"):
if (
name.startswith("emeter_")
or name.startswith("time")
or name.startswith("fan")
or name.startswith("color")
or name.startswith("brightness")
or name.startswith("valid_temperature_range")
or name.startswith("hsv")
or name.startswith("effect")
):
continue
try:
_ = getattr(first, name)

View File

@@ -11,7 +11,7 @@ from pytest_mock import MockerFixture
from kasa import KasaException
from kasa.exceptions import SmartErrorCode
from kasa.smart import SmartBulb, SmartDevice
from kasa.smart import SmartDevice
from .conftest import (
bulb_smart,
@@ -122,7 +122,7 @@ async def test_update_module_queries(dev: SmartDevice, mocker: MockerFixture):
@bulb_smart
async def test_smartdevice_brightness(dev: SmartBulb):
async def test_smartdevice_brightness(dev: SmartDevice):
"""Test brightness setter and getter."""
assert isinstance(dev, SmartDevice)
assert "brightness" in dev._components