Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions kasa/smart/modules/firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ class Firmware(SmartModule):

def __init__(self, device: "SmartDevice", module: str):
super().__init__(device, module)
self._add_feature(
Feature(
device,
"Auto update enabled",
container=self,
attribute_getter="auto_update_enabled",
attribute_setter="set_auto_update_enabled",
type=FeatureType.Switch,
if self.supported_version > 1:
self._add_feature(
Feature(
device,
"Auto update enabled",
container=self,
attribute_getter="auto_update_enabled",
attribute_setter="set_auto_update_enabled",
type=FeatureType.Switch,
)
)
)
self._add_feature(
Feature(
device,
Expand All @@ -70,12 +71,17 @@ def __init__(self, device: "SmartDevice", module: str):

def query(self) -> Dict:
"""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
def latest_firmware(self):
"""Return latest firmware information."""
fw = self.data["get_latest_fw"]
fw = self.data.get("get_latest_fw") or self.data
if isinstance(fw, SmartErrorCode):
# Error in response, probably disconnected from the cloud.
return UpdateInfo(type=0, need_to_upgrade=False)
Expand All @@ -98,7 +104,10 @@ async def update(self):
@property
def auto_update_enabled(self):
"""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):
"""Change autoupdate setting."""
Expand Down