Add support for firmware module v1 (#821)

The v1 of firmware does not support changing the auto update setting,
this makes it so that it isn't requested in that case.
This commit is contained in:
Steven B 2024-03-12 17:18:08 +00:00 committed by GitHub
parent 33be568897
commit 063518b7db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -48,16 +48,17 @@ class Firmware(SmartModule):
def __init__(self, device: "SmartDevice", module: str): def __init__(self, device: "SmartDevice", module: str):
super().__init__(device, module) super().__init__(device, module)
self._add_feature( if self.supported_version > 1:
Feature( self._add_feature(
device, Feature(
"Auto update enabled", device,
container=self, "Auto update enabled",
attribute_getter="auto_update_enabled", container=self,
attribute_setter="set_auto_update_enabled", attribute_getter="auto_update_enabled",
type=FeatureType.Switch, attribute_setter="set_auto_update_enabled",
type=FeatureType.Switch,
)
) )
)
self._add_feature( self._add_feature(
Feature( Feature(
device, device,
@ -70,12 +71,17 @@ class Firmware(SmartModule):
def query(self) -> Dict: def query(self) -> Dict:
"""Query to execute during the update cycle.""" """Query to execute during the update cycle."""
return {"get_auto_update_info": None, "get_latest_fw": None} req = {
"get_latest_fw": None,
}
if self.supported_version > 1:
req["get_auto_update_info"] = None
return req
@property @property
def latest_firmware(self): def latest_firmware(self):
"""Return latest firmware information.""" """Return latest firmware information."""
fw = self.data["get_latest_fw"] fw = self.data.get("get_latest_fw") or self.data
if isinstance(fw, SmartErrorCode): if isinstance(fw, SmartErrorCode):
# Error in response, probably disconnected from the cloud. # Error in response, probably disconnected from the cloud.
return UpdateInfo(type=0, need_to_upgrade=False) return UpdateInfo(type=0, need_to_upgrade=False)
@ -98,7 +104,10 @@ class Firmware(SmartModule):
@property @property
def auto_update_enabled(self): def auto_update_enabled(self):
"""Return True if autoupdate is enabled.""" """Return True if autoupdate is enabled."""
return self.data["get_auto_update_info"]["enable"] return (
"get_auto_update_info" in self.data
and self.data["get_auto_update_info"]["enable"]
)
async def set_auto_update_enabled(self, enabled: bool): async def set_auto_update_enabled(self, enabled: bool):
"""Change autoupdate setting.""" """Change autoupdate setting."""