mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-12-01 13:48:15 +00:00
Make get_module return typed module (#892)
Passing in a string still works and returns either `IotModule` or
`SmartModule` type when called on `IotDevice` or `SmartDevice`
respectively. When calling on `Device` will return `Module` type.
Passing in a module type is then typed to that module, i.e.:
```py
smartdev.get_module(FanModule) # type is FanModule
smartdev.get_module("FanModule") # type is SmartModule
```
Only thing this doesn't do is check that you can't pass an `IotModule`
to a `SmartDevice.get_module()`. However there is a runtime check which
will return null if the passed `ModuleType` is not a subclass of
`SmartModule`.
Many thanks to @cdce8p for helping with this.
This commit is contained in:
@@ -33,7 +33,7 @@ async def test_brightness_component(dev: SmartDevice):
|
||||
|
||||
|
||||
@dimmable
|
||||
async def test_brightness_dimmable(dev: SmartDevice):
|
||||
async def test_brightness_dimmable(dev: IotDevice):
|
||||
"""Test brightness feature."""
|
||||
assert isinstance(dev, IotDevice)
|
||||
assert "brightness" in dev.sys_info or bool(dev.sys_info["is_dimmable"])
|
||||
|
||||
Reference in New Issue
Block a user