mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-24 20:23:35 +00:00
0d119e63d0
* 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
73 lines
2.0 KiB
Python
73 lines
2.0 KiB
Python
import inspect
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
from kasa.smart.smartchilddevice import SmartChildDevice
|
|
from kasa.smartprotocol import _ChildProtocolWrapper
|
|
|
|
from .conftest import strip_smart
|
|
|
|
|
|
@strip_smart
|
|
def test_childdevice_init(dev, dummy_protocol, mocker):
|
|
"""Test that child devices get initialized and use protocol wrapper."""
|
|
assert len(dev.children) > 0
|
|
assert dev.is_strip
|
|
|
|
first = dev.children[0]
|
|
assert isinstance(first.protocol, _ChildProtocolWrapper)
|
|
|
|
assert first._info["category"] == "plug.powerstrip.sub-plug"
|
|
assert "position" in first._info
|
|
|
|
|
|
@strip_smart
|
|
async def test_childdevice_update(dev, dummy_protocol, mocker):
|
|
"""Test that parent update updates children."""
|
|
child_info = dev._last_update["child_info"]
|
|
child_list = child_info["child_device_list"]
|
|
|
|
assert len(dev.children) == child_info["sum"]
|
|
first = dev.children[0]
|
|
|
|
await dev.update()
|
|
|
|
assert dev._last_update != first._last_update
|
|
assert child_list[0] == first._last_update
|
|
|
|
|
|
@strip_smart
|
|
@pytest.mark.skipif(
|
|
sys.version_info < (3, 11),
|
|
reason="exceptiongroup requires python3.11+",
|
|
)
|
|
async def test_childdevice_properties(dev: SmartChildDevice):
|
|
"""Check that accessing childdevice properties do not raise exceptions."""
|
|
assert len(dev.children) > 0
|
|
|
|
first = dev.children[0]
|
|
assert first.is_strip_socket
|
|
|
|
# children do not have children
|
|
assert not first.children
|
|
|
|
def _test_property_getters():
|
|
"""Try accessing all properties and return a list of encountered exceptions."""
|
|
exceptions = []
|
|
properties = inspect.getmembers(
|
|
first.__class__, lambda o: isinstance(o, property)
|
|
)
|
|
for prop in properties:
|
|
name, _ = prop
|
|
try:
|
|
_ = getattr(first, name)
|
|
except Exception as ex:
|
|
exceptions.append(ex)
|
|
|
|
return exceptions
|
|
|
|
exceptions = list(_test_property_getters())
|
|
if exceptions:
|
|
raise ExceptionGroup("Accessing child properties caused exceptions", exceptions)
|