python-kasa/kasa/smart/modules/devicemodule.py
Steven B 905a14895d
Handle module errors more robustly and add query params to light preset and transition (#1036)
Ensures that all modules try to access their data in `_post_update_hook` in a safe manner and disable themselves if there's an error.
Also adds parameters to get_preset_rules and get_on_off_gradually_info to fix issues with recent firmware updates.
[#1033](https://github.com/python-kasa/python-kasa/issues/1033)
2024-07-04 08:02:50 +01:00

30 lines
780 B
Python

"""Implementation of device module."""
from __future__ import annotations
from ..smartmodule import SmartModule
class DeviceModule(SmartModule):
"""Implementation of device module."""
REQUIRED_COMPONENT = "device"
def _post_update_hook(self):
"""Perform actions after a device update.
Overrides the default behaviour to disable a module if the query returns
an error because this module is critical.
"""
def query(self) -> dict:
"""Query to execute during the update cycle."""
query = {
"get_device_info": None,
}
# Device usage is not available on older firmware versions
if self.supported_version >= 2:
query["get_device_usage"] = None
return query