mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-12 02:18:02 +00:00
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)
This commit is contained in:
@@ -13,7 +13,6 @@ from typing import TYPE_CHECKING, Any, Callable, Optional
|
||||
from async_timeout import timeout as asyncio_timeout
|
||||
from pydantic.v1 import BaseModel, Field, validator
|
||||
|
||||
from ...exceptions import SmartErrorCode
|
||||
from ...feature import Feature
|
||||
from ..smartmodule import SmartModule
|
||||
|
||||
@@ -123,6 +122,13 @@ class Firmware(SmartModule):
|
||||
req["get_auto_update_info"] = None
|
||||
return req
|
||||
|
||||
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 some of the module still functions.
|
||||
"""
|
||||
|
||||
@property
|
||||
def current_firmware(self) -> str:
|
||||
"""Return the current firmware version."""
|
||||
@@ -136,11 +142,11 @@ class Firmware(SmartModule):
|
||||
@property
|
||||
def firmware_update_info(self):
|
||||
"""Return latest firmware information."""
|
||||
fw = self.data.get("get_latest_fw") or self.data
|
||||
if not self._device.is_cloud_connected or isinstance(fw, SmartErrorCode):
|
||||
if not self._device.is_cloud_connected or self._has_data_error():
|
||||
# Error in response, probably disconnected from the cloud.
|
||||
return UpdateInfo(type=0, need_to_upgrade=False)
|
||||
|
||||
fw = self.data.get("get_latest_fw") or self.data
|
||||
return UpdateInfo.parse_obj(fw)
|
||||
|
||||
@property
|
||||
|
Reference in New Issue
Block a user