From ebd370da74636c0b768449a90329456ddccae084 Mon Sep 17 00:00:00 2001 From: "Steven B." <51370195+sdb9696@users.noreply.github.com> Date: Wed, 29 Jan 2025 18:49:38 +0000 Subject: [PATCH] Add module.device to the public api (#1478) --- kasa/module.py | 5 +++++ tests/iot/test_iotdevice.py | 4 ++-- tests/smart/modules/test_fan.py | 2 +- tests/smart/test_smartdevice.py | 6 +++--- tests/test_common_modules.py | 8 ++++---- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/kasa/module.py b/kasa/module.py index 8fdff7c3..8ca259fc 100644 --- a/kasa/module.py +++ b/kasa/module.py @@ -182,6 +182,11 @@ class Module(ABC): self._module = module self._module_features: dict[str, Feature] = {} + @property + def device(self) -> Device: + """Return the device exposing the module.""" + return self._device + @property def _all_features(self) -> dict[str, Feature]: """Get the features for this module and any sub modules.""" diff --git a/tests/iot/test_iotdevice.py b/tests/iot/test_iotdevice.py index 0b822859..16dac35f 100644 --- a/tests/iot/test_iotdevice.py +++ b/tests/iot/test_iotdevice.py @@ -277,12 +277,12 @@ async def test_get_modules(): # Modules on device module = dummy_device.modules.get("cloud") assert module - assert module._device == dummy_device + assert module.device == dummy_device assert isinstance(module, Cloud) module = dummy_device.modules.get(Module.IotCloud) assert module - assert module._device == dummy_device + assert module.device == dummy_device assert isinstance(module, Cloud) # Invalid modules diff --git a/tests/smart/modules/test_fan.py b/tests/smart/modules/test_fan.py index 9a6878e5..5f505e74 100644 --- a/tests/smart/modules/test_fan.py +++ b/tests/smart/modules/test_fan.py @@ -58,7 +58,7 @@ async def test_fan_module(dev: SmartDevice, mocker: MockerFixture): assert isinstance(dev, SmartDevice) fan = next(get_parent_and_child_modules(dev, Module.Fan)) assert fan - device = fan._device + device = fan.device await fan.set_fan_speed_level(1) await dev.update() diff --git a/tests/smart/test_smartdevice.py b/tests/smart/test_smartdevice.py index 2cf87d06..155c2bdf 100644 --- a/tests/smart/test_smartdevice.py +++ b/tests/smart/test_smartdevice.py @@ -604,7 +604,7 @@ async def test_get_modules(): # Modules on device module = dummy_device.modules.get("Cloud") assert module - assert module._device == dummy_device + assert module.device == dummy_device assert isinstance(module, Cloud) module = dummy_device.modules.get(Module.Cloud) @@ -617,8 +617,8 @@ async def test_get_modules(): assert module is None module = next(get_parent_and_child_modules(dummy_device, "Fan")) assert module - assert module._device != dummy_device - assert module._device._parent == dummy_device + assert module.device != dummy_device + assert module.device.parent == dummy_device # Invalid modules module = dummy_device.modules.get("DummyModule") diff --git a/tests/test_common_modules.py b/tests/test_common_modules.py index cba1ef87..3b1d8988 100644 --- a/tests/test_common_modules.py +++ b/tests/test_common_modules.py @@ -176,7 +176,7 @@ async def test_light_brightness(dev: Device): assert light # Test getting the value - feature = light._device.features["brightness"] + feature = light.device.features["brightness"] assert feature.minimum_value == 0 assert feature.maximum_value == 100 @@ -205,7 +205,7 @@ async def test_light_color_temp(dev: Device): ) # Test getting the value - feature = light._device.features["color_temperature"] + feature = light.device.features["color_temperature"] assert isinstance(feature.minimum_value, int) assert isinstance(feature.maximum_value, int) @@ -237,7 +237,7 @@ async def test_light_set_state(dev: Device): light = next(get_parent_and_child_modules(dev, Module.Light)) assert light # For fixtures that have a light effect active switch off - if light_effect := light._device.modules.get(Module.LightEffect): + if light_effect := light.device.modules.get(Module.LightEffect): await light_effect.set_effect(light_effect.LIGHT_EFFECTS_OFF) await light.set_state(LightState(light_on=False)) @@ -264,7 +264,7 @@ async def test_light_preset_module(dev: Device, mocker: MockerFixture): assert preset_mod light_mod = next(get_parent_and_child_modules(dev, Module.Light)) assert light_mod - feat = preset_mod._device.features["light_preset"] + feat = preset_mod.device.features["light_preset"] preset_list = preset_mod.preset_list assert "Not set" in preset_list