Better firmware module support for devices not connected to the internet (#854)

Devices not connected to the internet will either error when querying
firmware queries (e.g. P300) or return misleading information (e.g.
P100). This PR adds the cloud connect query to the initial queries and
bypasses the firmware module if not connected.
This commit is contained in:
Steven B
2024-04-23 12:56:32 +01:00
committed by GitHub
parent 03a0ef3cc3
commit aa969ef020
5 changed files with 89 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from ...exceptions import SmartErrorCode
from ...feature import Feature, FeatureType
from ..smartmodule import SmartModule
@@ -34,4 +35,6 @@ class CloudModule(SmartModule):
@property
def is_connected(self):
"""Return True if device is connected to the cloud."""
if isinstance(self.data, SmartErrorCode):
return False
return self.data["status"] == 0

View File

@@ -2,7 +2,7 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING, Any, Optional
from ...exceptions import SmartErrorCode
from ...feature import Feature, FeatureType
@@ -74,9 +74,7 @@ class Firmware(SmartModule):
def query(self) -> dict:
"""Query to execute during the update cycle."""
req = {
"get_latest_fw": None,
}
req: dict[str, Any] = {"get_latest_fw": None}
if self.supported_version > 1:
req["get_auto_update_info"] = None
return req
@@ -85,15 +83,17 @@ class Firmware(SmartModule):
def latest_firmware(self):
"""Return latest firmware information."""
fw = self.data.get("get_latest_fw") or self.data
if isinstance(fw, SmartErrorCode):
if not self._device.is_cloud_connected or isinstance(fw, SmartErrorCode):
# Error in response, probably disconnected from the cloud.
return UpdateInfo(type=0, need_to_upgrade=False)
return UpdateInfo.parse_obj(fw)
@property
def update_available(self):
def update_available(self) -> bool | None:
"""Return True if update is available."""
if not self._device.is_cloud_connected:
return None
return self.latest_firmware.update_available
async def get_update_state(self):