Skip to content

Commit

Permalink
hotfix for switching events and alarm outputs regression from v1.0.12 (
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-or authored Apr 15, 2024
1 parent a0a3e64 commit 63f7dd5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion custom_components/hikvision_next/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def _async_update_data(self):
)
data[entity_id] = await self.isapi.get_port_status("output", i)
except Exception as ex: # pylint: disable=broad-except
self.isapi.handle_exception(ex, f"Cannot fetch state for {event.id}")
self.isapi.handle_exception(ex, f"Cannot fetch state for alarm output {i}")

# Refresh HDD data
try:
Expand Down
12 changes: 4 additions & 8 deletions custom_components/hikvision_next/isapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,11 +607,9 @@ async def get_event_switch_mutex(self, event: EventInfo, channel_id: int) -> lis

data = {"function": event_id, "channelID": int(channel_id)}
url = "System/mutexFunction?format=json"
try:
response = await self.request(POST, url, present="json", data=json.dumps(data))
except HTTPStatusError:
response = await self.request(POST, url, present="json", data=json.dumps(data))
if not response:
return []

response = json.loads(response)

if mutex_list := response.get("MutexFunctionList"):
Expand All @@ -638,15 +636,13 @@ async def set_event_enabled_state(self, channel_id: int, event: EventInfo, is_en

if not mutex_issues:
data = await self.request(GET, event.url)
_LOGGER.debug("%s/ISAPI/%s %s", self.isapi.host, event.url, data)
node = self.get_event_state_node(event)
new_state = bool_to_str(is_enabled)
if new_state == data[node]["enabled"]:
return
data[node]["enabled"] = new_state
xml = xmltodict.unparse(data)
response = await self.request(PUT, event.url, data=xml)
_LOGGER.debug("[PUT] %s/ISAPI/%s %s", self.isapi.host, event.url, response)
await self.request(PUT, event.url, data=xml)
else:
raise HomeAssistantError(
f"You cannot enable {EVENTS[event.id]['label']} events. Please disable {EVENTS[mutex_issues[0].event_id]['label']} on channels {mutex_issues[0].channels} first"
Expand All @@ -658,7 +654,7 @@ async def get_port_status(self, port_type: str, port_no: int) -> str:
status = await self.request(GET, f"System/IO/inputs/{port_no}/status", ignore_exception=False)
else:
status = await self.request(GET, f"System/IO/outputs/{port_no}/status", ignore_exception=False)
return deep_get(status, "IOStatus.ioState")
return deep_get(status, "IOPortStatus.ioState")

async def set_port_state(self, port_no: int, turn_on: bool):
"""Set status of output port."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hikvision_next/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"hikvisionapi==0.3.2",
"requests-toolbelt==0.10.1"
],
"version": "1.0.12"
"version": "1.0.13"
}

0 comments on commit 63f7dd5

Please sign in to comment.