8000 Add module.device to the public api (#1478) · python-kasa/python-kasa@ebd370d · GitHub
[go: up one dir, main page]

Skip to content

Commit ebd370d

Browse files
authored
Add module.device to the public api (#1478)
1 parent 82fbe12 commit ebd370d

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

kasa/module.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ def __init__(self, device: Device, module: str) -> None:
182182
self._module = module
183183
self._module_features: dict[str, Feature] = {}
184184

185+
@property
186+
def device(self) -> Device:
187+
"""Return the device exposing the module."""
188+
return self._device
189+
185190
@property
186191
def _all_features(self) -> dict[str, Feature]:
187192
"""Get the features for this module and any sub modules."""

tests/iot/test_iotdevice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,12 @@ async def test_get_modules():
277277
# Modules on device
278278
module = dummy_device.modules.get("cloud")
279279
assert module
280-
assert module._device == dummy_device
280+
assert module.device == dummy_device
281281
assert isinstance(module, Cloud)
282282

283283
module = dummy_device.modules.get(Module.IotCloud)
284284
assert module
285-
assert module._device == dummy_device
285+
assert module.device == dummy_device
286286
assert isinstance(module, Cloud)
287287

288288
# Invalid modules

tests/smart/modules/test_fan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async def test_fan_module(dev: SmartDevice, mocker: MockerFixture):
5858
assert isinstance(dev, SmartDevice)
5959
fan = next(get_parent_and_child_modules(dev, Module.Fan))
6060
assert fan
61-
device = fan._device
61+
device = fan.device
6262

6363
await fan.set_fan_speed_level(1)
6464
await dev.update()

tests/smart/test_smartdevice.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ async def test_get_modules():
604604
# Modules on device
605605
module = dummy_device.modules.get("Cloud")
606606
assert module
607-
assert module._device == dummy_device
607+
assert module.device == dummy_device
608608
assert isinstance(module, Cloud)
609609

610610
module = dummy_device.modules.get(Module.Cloud)
@@ -617,8 +617,8 @@ async def test_get_modules():
617617
assert module is None
618618
module = next(get_parent_and_child_modules(dummy_device, "Fan"))
619619
assert module
620-
assert module._device != dummy_device
621-
assert module._device._parent == dummy_device
620+
assert module.device != dummy_device
621+
assert module.device.parent == dummy_device
622622

623623
# Invalid modules
624624
module = dummy_device.modules.get("DummyModule")

tests/test_common_modules.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async def test_light_brightness(dev: Device):
176176
assert light
177177

178178
# Test getting the value
179-
feature = light._device.features["brightness"]
179+
feature = light.device.features["brightness"]
180180
assert feature.minimum_value == 0
181181
assert feature.maximum_value == 100
182182

@@ -205,7 +205,7 @@ async def test_light_color_temp(dev: Device):
205205
)
206206

207207
# Test getting the value
208-
feature = light._device.features["color_temperature"]
208+
feature = light.device.features["color_temperature"]
209209
assert isinstance(feature.minimum_value, int)
210210
assert isinstance(feature.maximum_value, int)
211211

@@ -237,7 +237,7 @@ async def test_light_set_state(dev: Device):
237237
light = next(get_parent_and_child_modules(dev, Module.Light))
238238
assert light
239239
# For fixtures that have a light effect active switch off
240-
if light_effect := light._device.modules.get(Module.LightEffect):
240+
if light_effect := light.device.modules.get(Module.LightEffect):
241241
await light_effect.set_effect(light_effect.LIGHT_EFFECTS_OFF)
242242

243243
await light.set_state(LightState(light_on=False))
@@ -264,7 +264,7 @@ async def test_light_preset_module(dev: Device, mocker: MockerFixture):
264264
assert preset_mod
265265
light_mod = next(get_parent_and_child_modules(dev, Module.Light))
266266
assert light_mod
267-
feat = preset_mod._device.features["light_preset"]
267+
feat = preset_mod.device.features["light_preset"]
268268

269269
preset_list = preset_mod.preset_list
270270
assert "Not set" in preset_list

0 commit comments

Comments
 (0)
0