Skip to content

Commit

Permalink
Fix KeyError when None not in ch_list of check_new_firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG committed Dec 30, 2024
1 parent 781c713 commit 75fda9d
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions reolink_aio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2677,8 +2677,11 @@ async def check_new_firmware(self, ch_list: list[None | int] | None = None) -> L
ch_list.extend(self.channels)

# check current firmware version
body: typings.reolink_json = [{"cmd": "GetDevInfo", "action": 0, "param": {}}]
channels = [-1]
body: typings.reolink_json = []
channels: list[int] = []
if None in ch_list:
body.append({"cmd": "GetDevInfo", "action": 0, "param": {}})
channels.append(-1)
for ch in self.channels:
if ch in ch_list and self.supported(ch, "firmware"):
body.append({"cmd": "GetChnTypeInfo", "action": 0, "param": {"channel": ch}})
Expand All @@ -2694,7 +2697,7 @@ async def check_new_firmware(self, ch_list: list[None | int] | None = None) -> L
self.map_channels_json_response(json_data, channels)

# check for host update using API
if self.supported(None, "update"):
if None in ch_list and self.supported(None, "update"):
body = [{"cmd": "CheckFirmware"}]

try:
Expand Down Expand Up @@ -2739,16 +2742,18 @@ async def check_new_firmware(self, ch_list: list[None | int] | None = None) -> L
self._latest_sw_version[ch] = False

# check host online update result
latest_sw_version_host = self._latest_sw_version[None]
if new_firmware != 0 and latest_sw_version_host is False:
if new_firmware == 1:
latest_sw_version_host = "New firmware available"
else:
latest_sw_version_host = str(new_firmware)
if isinstance(latest_sw_version_host, NewSoftwareVersion):
latest_sw_version_host.online_update_available = new_firmware == 1
latest_sw_version_host = False
if None in ch_list:
latest_sw_version_host = self._latest_sw_version[None]
if new_firmware != 0 and latest_sw_version_host is False:
if new_firmware == 1:
latest_sw_version_host = "New firmware available"
else:
latest_sw_version_host = str(new_firmware)
if isinstance(latest_sw_version_host, NewSoftwareVersion):
latest_sw_version_host.online_update_available = new_firmware == 1
self._latest_sw_version[None] = latest_sw_version_host

self._latest_sw_version[None] = latest_sw_version_host
return latest_sw_version_host

def firmware_update_available(self, channel: int | None = None) -> Literal[False] | NewSoftwareVersion | str:
Expand Down

0 comments on commit 75fda9d

Please sign in to comment.