Skip to content

Commit

Permalink
fixed boolean values conversion (#174)
Browse files Browse the repository at this point in the history
* valid boolean values conversion

* requests-toolbelt upgrade
  • Loading branch information
maciej-or authored Apr 24, 2024
1 parent a7154cf commit 4e3f692
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
14 changes: 9 additions & 5 deletions custom_components/hikvision_next/isapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,13 @@ async def get_hardware_info(self):
# Set DeviceInfo
self.device_info.support_analog_cameras = int(deep_get(capabilities, "SysCap.VideoCap.videoInputPortNums", 0))
self.device_info.support_digital_cameras = int(deep_get(capabilities, "RacmCap.inputProxyNums", 0))
self.device_info.support_holiday_mode = deep_get(capabilities, "SysCap.isSupportHolidy", False)
self.device_info.support_channel_zero = deep_get(capabilities, "RacmCap.isSupportZeroChan", False)
self.device_info.support_event_mutex_checking = capabilities.get("isSupportGetmutexFuncErrMsg", False)
self.device_info.support_holiday_mode = str_to_bool(deep_get(capabilities, "SysCap.isSupportHolidy", "false"))
self.device_info.support_channel_zero = str_to_bool(
deep_get(capabilities, "RacmCap.isSupportZeroChan", "false")
)
self.device_info.support_event_mutex_checking = str_to_bool(
capabilities.get("isSupportGetmutexFuncErrMsg", "false")
)
self.device_info.input_ports = int(deep_get(capabilities, "SysCap.IOCap.IOInputPortNums", 0))
self.device_info.output_ports = int(deep_get(capabilities, "SysCap.IOCap.IOOutputPortNums", 0))

Expand Down Expand Up @@ -473,7 +477,7 @@ async def get_camera_streams(self, channel_id: int) -> list[CameraStreamInfo]:
codec=deep_get(stream_info, "Video.videoCodecType"),
width=deep_get(stream_info, "Video.videoResolutionWidth", 0),
height=deep_get(stream_info, "Video.videoResolutionHeight", 0),
audio=deep_get(stream_info, "Audio.enabled", False),
audio=str_to_bool(deep_get(stream_info, "Audio.enabled", "false")),
)
)
return streams
Expand Down Expand Up @@ -592,7 +596,7 @@ async def get_event_enabled_state(self, event: EventInfo) -> bool:
"""Get event detection state."""
state = await self.request(GET, event.url)
node = self.get_event_state_node(event)
return str_to_bool(state[node].get("enabled", False)) if state.get(node) else False
return str_to_bool(state[node].get("enabled", "false")) if state.get(node) else False

async def get_event_switch_mutex(self, event: EventInfo, channel_id: int) -> list[MutexIssue]:
"""Get if event is mutually exclusive with enabled events."""
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 @@ -12,7 +12,7 @@
"requirements": [
"xmltodict==0.13.0",
"hikvisionapi==0.3.2",
"requests-toolbelt==0.10.1"
"requests-toolbelt==1.0.0"
],
"version": "1.0.14"
}
6 changes: 3 additions & 3 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ async def test_async_setup_entry_nvr(hass: HomeAssistant, init_integration: Mock
assert len(device_info.storage) == 1
assert device_info.support_alarm_server is True
assert device_info.support_analog_cameras == 0
assert device_info.support_channel_zero == "true"
assert device_info.support_channel_zero is True
assert device_info.support_digital_cameras == 8
assert device_info.support_event_mutex_checking == "false"
assert device_info.support_holiday_mode == "true"
assert device_info.support_event_mutex_checking is False
assert device_info.support_holiday_mode is True

# test successful unload
await hass.config_entries.async_unload(entry.entry_id)
Expand Down

0 comments on commit 4e3f692

Please sign in to comment.