Skip to content

Commit

Permalink
added controlsource for illegal swipe event
Browse files Browse the repository at this point in the history
  • Loading branch information
pergolafabio committed Feb 15, 2024
1 parent 00e4a0d commit 05fd078
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 10 additions & 5 deletions hikvision-doorbell/src/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class DeviceTriggerMetadata(TypedDict):
VideoInterComEventType.AUTHENTICATION_LOG: DeviceTriggerMetadata(name='authentication_log', type='event', subtype='authentication log'),
VideoInterComEventType.ANNOUNCEMENT_READING_RECEIPT: DeviceTriggerMetadata(name='announcement_reading_receipt', type='event', subtype='announcement reading receipt'),
VideoInterComEventType.UPLOAD_PLATE_INFO: DeviceTriggerMetadata(name='upload_plate_info', type='event', subtype='upload plate info'),
VideoInterComEventType.ILLEGAL_CARD_SWIPING_EVENT: DeviceTriggerMetadata(name='illegal_card_swiping_event', type='event', subtype='illegal card_swiping event'),
VideoInterComEventType.DOOR_STATION_ISSUED_CARD_LOG: DeviceTriggerMetadata(name='door_station_issued_card_log', type='event', subtype='door station issued card log'),
VideoInterComEventType.MASK_DETECT_EVENT: DeviceTriggerMetadata(name='mask_detect_event', type='event', subtype='mask detect event'),
VideoInterComEventType.MAGNETIC_DOOR_STATUS: DeviceTriggerMetadata(name='magnetic_door_status', type='event', subtype='magnetic door status'),
Expand Down Expand Up @@ -319,9 +318,7 @@ async def update_door_entities(door_id: str, control_source: str):
case VideoInterComEventType.UNLOCK_LOG:
door_id = alarm_info.uEventInfo.struUnlockRecord.wLockID
control_source = alarm_info.uEventInfo.struUnlockRecord.controlSource()
# unlock_type = alarm_info.uEventInfo.struUnlockRecord.byUnlockType
# card_number = str(alarm_info.uEventInfo.struAuthInfo.byCardNo

# card_number = alarm_info.uEventInfo.struAuthInfo.cardNo()
# Name of the entity inside the dict array containing all the sensors
entity_id = f'door_{door_id}'
# Extract the sensor entity from the dict and cast to know type
Expand All @@ -337,7 +334,15 @@ async def update_door_entities(door_id: str, control_source: str):
await update_door_entities(door_id, control_source)
return
await update_door_entities(door_id, control_source)


case VideoInterComEventType.ILLEGAL_CARD_SWIPING_EVENT:
control_source = alarm_info.uEventInfo.struUnlockRecord.controlSource()
attributes = {
'control_source': control_source,
}
trigger = DeviceTriggerMetadata(name='illegal_card_swiping_event', type='event', subtype='illegal card_swiping event', payload=attributes)
self.handle_device_trigger(doorbell, trigger)

case _:
"""Generic event: create the device trigger entity according to the information inside the DEVICE_TRIGGERS_DEFINITIONS dict"""

Expand Down
5 changes: 5 additions & 0 deletions hikvision-doorbell/src/sdk/hcnetsdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ class NET_DVR_AUTH_INFO(Structure):
("byRes", BYTE * 212),
]

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

class NET_DVR_VIDEO_INTERCOM_EVENT_INFO_UINON(Union):
_fields_ = [
("byLen", BYTE),
Expand Down

0 comments on commit 05fd078

Please sign in to comment.