Skip to content

Commit

Permalink
some more events from sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
pergolafabio committed Jan 19, 2024
1 parent b3f3422 commit 7e5e4bb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
22 changes: 18 additions & 4 deletions hikvision-doorbell/src/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,26 @@ class DeviceTriggerMetadata(TypedDict):
VideoInterComAlarmType.BLACKLIST_ALARM: DeviceTriggerMetadata(name='smart_lock_blacklist_alarm', type='alarm', subtype='blacklist'),
VideoInterComAlarmType.SMART_LOCK_DISCONNECTED: DeviceTriggerMetadata(name='smart_lock_disconnected', type='smart lock disconnected', subtype=''),
VideoInterComAlarmType.ACCESS_CONTROL_TAMPERING_ALARM: DeviceTriggerMetadata(name='access_control_tampering_alarm', type='alarm', subtype='access control tampering alarm'),
VideoInterComAlarmType.SOS_CANCELLED: DeviceTriggerMetadata(name='sos_cancelled', type='alarm', subtype='sos cancelled'),
VideoInterComAlarmType.NO_MASK_ALARM: DeviceTriggerMetadata(name='no_mask_alarm', type='alarm', subtype='no mask alarm'),
VideoInterComAlarmType.FIRE_INPUT_ALARM: DeviceTriggerMetadata(name='fire_input_alarm', type='alarm', subtype='fire input alarm'),
VideoInterComAlarmType.FIRE_INPUT_RESTORED: DeviceTriggerMetadata(name='fire_input_restored', type='alarm', subtype='fire input restored'),
VideoInterComAlarmType.DOOR_OPEN_BY_EXTERNAL_FORCE: DeviceTriggerMetadata(name='door_open_by_external_force', type='force', subtype='door open by external force'),
VideoInterComAlarmType.TOILET_ALARM: DeviceTriggerMetadata(name='toilet_alarm', type='alarm', subtype='toilet alarm'),
VideoInterComAlarmType.TOILET_ALARM_CANCELLED: DeviceTriggerMetadata(name='toilet_alarm_cancelled', type='alarm', subtype='toilet alarm cancelled'),
VideoInterComAlarmType.DRESSING_REMINDER: DeviceTriggerMetadata(name='dressing_reminder', type='alarm', subtype='dressing reminder'),
VideoInterComAlarmType.FACE_TEMPERATURE_ALARM: DeviceTriggerMetadata(name='face_temperature_alarm', type='alarm', subtype='face temperature alarm'),
VideoInterComAlarmType.DRESSING_REMINDER_CANCELLED: DeviceTriggerMetadata(name='dressing_reminder_cancelled', type='force', subtype='dressing reminder cancelled'),
}
"""Define the attributes of each DeviceTrigger entity, indexing them by the enum VideoInterComAlarmType"""

DEVICE_TRIGGERS_DEFINITIONS_EVENT: dict[VideoInterComEventType, DeviceTriggerMetadata] = {
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'),
}
"""Define the attributes of each DeviceTrigger entity, indexing them by the enum VideoInterComEventType"""
Expand Down Expand Up @@ -237,17 +251,17 @@ async def acs_alarm(
minor_alarm = AcsAlarmInfoMajorOperation(minor)
case AcsAlarmInfoMajor.MAJOR_EVENT.value:
minor_alarm = AcsAlarmInfoMajorEvent(minor)
logger.info("Access control event: {} found with event: {}", major_alarm.name, minor_alarm.name)
logger.info("Access control event: {} found with event: {}", major_alarm.name.lower(), minor_alarm.name.lower())
match minor_alarm.name:
case "MINOR_FACE_VERIFY_PASS":
logger.debug("Minor control event: {} found on door {} with employee id: {}", minor_alarm.name, door_id, employee_id)
logger.debug("Minor control event: {} found on door {} with employee id: {}", minor_alarm.name.lower(), door_id, employee_id)
attributes = {
'employee_id': employee_id,
}
trigger = DeviceTriggerMetadata(name=f"{major_alarm.name} {minor_alarm.name}", type=f"", subtype=f"{major_alarm.name} {minor_alarm.name}", payload=attributes)
trigger = DeviceTriggerMetadata(name=f"{major_alarm.name.lower()} {minor_alarm.name.lower()}", type=f"", subtype=f"{major_alarm.name.lower()} {minor_alarm.name.lower()}", payload=attributes)
self.handle_device_trigger(doorbell, trigger)
case _:
trigger = DeviceTriggerMetadata(name=f"{major_alarm.name} {minor_alarm.name}", type=f"", subtype=f"{major_alarm.name} {minor_alarm.name}")
trigger = DeviceTriggerMetadata(name=f"{major_alarm.name.lower()} {minor_alarm.name.lower()}", type=f"", subtype=f"{major_alarm.name.lower()} {minor_alarm.name.lower()}")
self.handle_device_trigger(doorbell, trigger)
except:
logger.warning("Received unknown Access control event with Major: {} Minor: {}", major, minor)
Expand Down
2 changes: 2 additions & 0 deletions hikvision-doorbell/src/sdk/hcnetsdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
VIDEO_INTERCOM_EVENT_EVENTTYPE_UNLOCK_LOG = 1
VIDEO_INTERCOM_EVENT_EVENTTYPE_ANNOUNCEMENT_READING_RECEIPT = 2
VIDEO_INTERCOM_EVENT_EVENTTYPE_AUTHENTICATION_LOG = 3
VIDEO_INTERCOM_EVENT_EVENTTYPE_UPLOAD_PLATE_INFO = 4
VIDEO_INTERCOM_EVENT_EVENTTYPE_ILLEGAL_CARD_SWIPING_EVENT = 5
VIDEO_INTERCOM_EVENT_EVENTTYPE_DOOR_STATION_ISSUED_CARD_LOG = 6
VIDEO_INTERCOM_EVENT_EVENTTYPE_MASK_DETECT_EVENT = 7
Expand All @@ -172,6 +173,7 @@ class VideoInterComEventType(IntEnum):
UNLOCK_LOG = 1
ANNOUNCEMENT_READING_RECEIPT = 2
AUTHENTICATION_LOG = 3
UPLOAD_PLATE_INFO = 4
ILLEGAL_CARD_SWIPING_EVENT = 5
DOOR_STATION_ISSUED_CARD_LOG = 6
MASK_DETECT_EVENT = 7
Expand Down
11 changes: 1 addition & 10 deletions hikvision-doorbell/tests/test_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,7 @@ def test_all_alarm_types(self, mocked_doorbell: Doorbell, handler: MQTTHandler,
VideoInterComAlarmType.DOOR_NOT_CLOSED,
VideoInterComAlarmType.ZONE_ALARM,
VideoInterComAlarmType.DOORBELL_RINGING,
VideoInterComAlarmType.DISMISS_INCOMING_CALL,
VideoInterComAlarmType.SOS_CANCELLED,
VideoInterComAlarmType.NO_MASK_ALARM,
VideoInterComAlarmType.FIRE_INPUT_ALARM,
VideoInterComAlarmType.FIRE_INPUT_RESTORED,
VideoInterComAlarmType.TOILET_ALARM,
VideoInterComAlarmType.TOILET_ALARM_CANCELLED,
VideoInterComAlarmType.DRESSING_REMINDER,
VideoInterComAlarmType.FACE_TEMPERATURE_ALARM,
VideoInterComAlarmType.DRESSING_REMINDER_CANCELLED
VideoInterComAlarmType.DISMISS_INCOMING_CALL
):
pytest.skip("Tested in another function")
video_intercom_alarm = mocker.patch("sdk.hcnetsdk.NET_DVR_VIDEO_INTERCOM_ALARM")
Expand Down

0 comments on commit 7e5e4bb

Please sign in to comment.