Perform initial update only using the sysinfo query (#199)

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.
This commit is contained in:
Teemu R
2021-09-19 23:43:17 +02:00
committed by GitHub
parent f8e7258b93
commit b088596205
3 changed files with 40 additions and 8 deletions

View File

@@ -35,7 +35,7 @@ STRIPS = {"HS107", "HS300", "KP303", "KP400"}
DIMMERS = {"HS220"}
DIMMABLE = {*BULBS, *DIMMERS}
WITH_EMETER = {"HS110", "HS300", *BULBS, *STRIPS}
WITH_EMETER = {"HS110", "HS300", *BULBS}
ALL_DEVICES = BULBS.union(PLUGS).union(STRIPS).union(DIMMERS)

View File

@@ -5,7 +5,7 @@ import pytest # type: ignore # https://github.com/pytest-dev/pytest/issues/3342
from kasa import SmartDeviceException
from .conftest import handle_turn_on, pytestmark, turn_on
from .conftest import handle_turn_on, has_emeter, no_emeter, pytestmark, turn_on
from .newfakes import PLUG_SCHEMA, TZ_SCHEMA, FakeTransportProtocol
@@ -17,7 +17,24 @@ async def test_invalid_connection(dev):
with patch.object(FakeTransportProtocol, "query", side_effect=SmartDeviceException):
with pytest.raises(SmartDeviceException):
await dev.update()
dev.is_on
@has_emeter
async def test_initial_update_emeter(dev, mocker):
"""Test that the initial update performs second query if emeter is available."""
dev._last_update = None
spy = mocker.spy(dev.protocol, "query")
await dev.update()
assert spy.call_count == 2
@no_emeter
async def test_initial_update_no_emeter(dev, mocker):
"""Test that the initial update performs second query if emeter is available."""
dev._last_update = None
spy = mocker.spy(dev.protocol, "query")
await dev.update()
assert spy.call_count == 1
async def test_query_helper(dev):