Skip to content

Commit

Permalink
reorder new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
msp1974 committed Jul 8, 2023
1 parent 2e4e072 commit 4620765
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions custom_components/hikvision_next/isapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ async def get_device_event_capabilities(
device_id: int,
connection_type: str = CONNECTION_TYPE_DIRECT,
) -> list[EventInfo]:
"""Get events support by device (device id NVR = 0, camera > 0) and integration"""
"""Get events support by device (device id: NVR = 0, camera > 0)"""
events = []

if device_id == 0: # NVR
Expand Down Expand Up @@ -546,30 +546,6 @@ def get_storage_device_by_id(self, device_id: int) -> HDDInfo | None:
# Storage id does not exist
return None

async def get_port_status(self, port_type: str, port_no: int) -> str:
"""Get status of physical ports"""
if port_type == "input":
status = await self.isapi.System.IO.inputs[port_no].status(method=GET)
_LOGGER.debug("%s/ISAPI/System/IO/inputs/%s/status %s", self.isapi.host, port_no, status)
else:
status = await self.isapi.System.IO.outputs[port_no].status(method=GET)
_LOGGER.debug("%s/ISAPI/System/IO/outputs/%s/status %s", self.isapi.host, port_no, status)

if status.get("IOPortStatus"):
return status["IOPortStatus"].get("ioState")

async def set_port_state(self, port_no: int, turn_on: bool):
"""Set status of output port"""
data = {}
if turn_on:
data["IOPortData"] = {"outputState": "high"}
else:
data["IOPortData"] = {"outputState": "low"}

xml = xmltodict.unparse(data)
response = await self.isapi.System.IO.outputs[port_no].trigger(method=PUT, data=xml)
_LOGGER.debug("[PUT] %s/ISAPI/System/IO/outputs/%s/trigger %s", self.isapi.host, port_no, response)

def get_device_info(self, device_id: int = 0) -> DeviceInfo:
"""Return device registry information."""
if device_id == 0:
Expand All @@ -593,7 +569,7 @@ def get_device_info(self, device_id: int = 0) -> DeviceInfo:
sw_version=camera_info.firmware if is_ip_camera else "Unknown",
via_device=(DOMAIN, self.device_info.serial_no) if self.device_info.is_nvr else None,
)

def get_event_state_node(self, event: EventInfo) -> str:
"""Get xml key for event state"""
slug = EVENTS[event.id]["slug"]
Expand Down Expand Up @@ -678,6 +654,30 @@ async def set_event_enabled_state(self, channel_id: int, event: EventInfo, is_en
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"
)

async def get_port_status(self, port_type: str, port_no: int) -> str:
"""Get status of physical ports"""
if port_type == "input":
status = await self.isapi.System.IO.inputs[port_no].status(method=GET)
_LOGGER.debug("%s/ISAPI/System/IO/inputs/%s/status %s", self.isapi.host, port_no, status)
else:
status = await self.isapi.System.IO.outputs[port_no].status(method=GET)
_LOGGER.debug("%s/ISAPI/System/IO/outputs/%s/status %s", self.isapi.host, port_no, status)

if status.get("IOPortStatus"):
return status["IOPortStatus"].get("ioState")

async def set_port_state(self, port_no: int, turn_on: bool):
"""Set status of output port"""
data = {}
if turn_on:
data["IOPortData"] = {"outputState": "high"}
else:
data["IOPortData"] = {"outputState": "low"}

xml = xmltodict.unparse(data)
response = await self.isapi.System.IO.outputs[port_no].trigger(method=PUT, data=xml)
_LOGGER.debug("[PUT] %s/ISAPI/System/IO/outputs/%s/trigger %s", self.isapi.host, port_no, response)

async def get_holiday_enabled_state(self, holiday_index=0) -> bool:
"""Get holiday state"""

Expand Down

0 comments on commit 4620765

Please sign in to comment.