Skip to content

Commit

Permalink
refactor(HomeAssistantAPI): print controlSource as a string, removing…
Browse files Browse the repository at this point in the history
… suffix 0s
  • Loading branch information
mion00 committed Mar 6, 2023
1 parent 951c70f commit 2f55312
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions hikvision-doorbell/src/home_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,15 @@ async def video_intercom_event(
buffer_length,
user_pointer: c_void_p):
if alarm_info.byEventType == VIDEO_INTERCOM_EVENT_EVENTTYPE_UNLOCK_LOG:
# Convert the controlSource to a string, removing suffix `0`s
control_source = alarm_info.uEventInfo.struUnlockRecord.controlSource()
logger.info("Door {} unlocked by {}, updating sensor {}",
alarm_info.uEventInfo.struUnlockRecord.wLockID,
list(alarm_info.uEventInfo.struUnlockRecord.byControlSrc),
control_source,
self._sensors[doorbell]['door'])
additional_attributes = {
'Unlock': list(alarm_info.uEventInfo.struUnlockRecord.byControlSrc),
# TODO: better rename to `control source`, similar to the original field?
'Unlock': control_source,
'DoorID': alarm_info.uEventInfo.struUnlockRecord.wLockID
}
# Add additional attributes to the sensor
Expand Down
6 changes: 6 additions & 0 deletions hikvision-doorbell/src/sdk/hcnetsdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ class NET_DVR_UNLOCK_RECORD_INFO(Structure):
("byRes", BYTE * 168),
]

def controlSource(self):
"""Return the controls source number as a string representation, removing the ending `0`s"""
serial = "".join([str(number) for number in self.byControlSrc[:]])
return re.sub(r"0*$", "", serial)


class NET_DVR_NOTICEDATA_RECEIPT_INFO(Structure):
_fields_ = [
("byNoticeNumber", BYTE * MAX_NOTICE_NUMBER_LEN),
Expand Down

0 comments on commit 2f55312

Please sign in to comment.