Skip to content

Commit

Permalink
add door id for magtentic / external force event
Browse files Browse the repository at this point in the history
  • Loading branch information
pergolafabio committed Apr 11, 2024
1 parent 05fd078 commit fd93ed1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
22 changes: 20 additions & 2 deletions hikvision-doorbell/src/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class DeviceTriggerMetadata(TypedDict):
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'),
Expand All @@ -102,7 +101,6 @@ class DeviceTriggerMetadata(TypedDict):
VideoInterComEventType.UPLOAD_PLATE_INFO: DeviceTriggerMetadata(name='upload_plate_info', type='event', subtype='upload plate info'),
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 @@ -343,6 +341,15 @@ async def update_door_entities(door_id: str, control_source: str):
trigger = DeviceTriggerMetadata(name='illegal_card_swiping_event', type='event', subtype='illegal card_swiping event', payload=attributes)
self.handle_device_trigger(doorbell, trigger)

case VideoInterComEventType.MAGNETIC_DOOR_STATUS:
door_id = alarm_info.uEventInfo.struUnlockRecord.wLockID
logger.info("Magnetic door event detected on door {}", door_id + 1)
attributes = {
'door_id': door_id + 1,
}
trigger = DeviceTriggerMetadata(name='magnetic door status', type='event', subtype='magnetic_door_status', 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 Expand Up @@ -416,6 +423,17 @@ async def video_intercom_alarm(
trigger = DeviceTriggerMetadata(name=f"door_not_closed_{door_id}", type="not closed", subtype=f"Door {door_id+1}")

self.handle_device_trigger(doorbell, trigger)

case VideoInterComAlarmType.DOOR_OPEN_BY_EXTERNAL_FORCE:
# Get information about the door that caused this alarm
door_id = alarm_info.wLockID
logger.info("External force {} detected on door {}", alarm_info.uAlarmInfo, door_id + 1)
attributes = {
'door_id': door_id + 1,
}
trigger = DeviceTriggerMetadata(name='door open by external force', type='event', subtype='door_open_by_external_force', payload=attributes)
self.handle_device_trigger(doorbell, trigger)

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

Expand Down
3 changes: 2 additions & 1 deletion hikvision-doorbell/tests/test_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ 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.DISMISS_INCOMING_CALL,
VideoInterComAlarmType.DOOR_OPEN_BY_EXTERNAL_FORCE
):
pytest.skip("Tested in another function")
video_intercom_alarm = mocker.patch("sdk.hcnetsdk.NET_DVR_VIDEO_INTERCOM_ALARM")
Expand Down

0 comments on commit fd93ed1

Please sign in to comment.