Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Locks to Xiaomi-BLE #111156

Merged
merged 5 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions homeassistant/components/xiaomi_ble/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
key=XiaomiBinarySensorDeviceClass.LIGHT,
device_class=BinarySensorDeviceClass.LIGHT,
),
XiaomiBinarySensorDeviceClass.LOCK: BinarySensorEntityDescription(
key=XiaomiBinarySensorDeviceClass.LOCK,
device_class=BinarySensorDeviceClass.LOCK,
),
XiaomiBinarySensorDeviceClass.MOISTURE: BinarySensorEntityDescription(
key=XiaomiBinarySensorDeviceClass.MOISTURE,
device_class=BinarySensorDeviceClass.MOISTURE,
Expand All @@ -62,6 +66,16 @@
key=XiaomiBinarySensorDeviceClass.SMOKE,
device_class=BinarySensorDeviceClass.SMOKE,
),
ExtendedBinarySensorDeviceClass.ANTILOCK: BinarySensorEntityDescription(
key=ExtendedBinarySensorDeviceClass.ANTILOCK,
),
ExtendedBinarySensorDeviceClass.ARMED: BinarySensorEntityDescription(
key=ExtendedBinarySensorDeviceClass.ARMED,
icon="mdi:shield-check",
),
ExtendedBinarySensorDeviceClass.CHILDLOCK: BinarySensorEntityDescription(
key=ExtendedBinarySensorDeviceClass.CHILDLOCK,
),
ExtendedBinarySensorDeviceClass.DEVICE_FORCIBLY_REMOVED: BinarySensorEntityDescription(
key=ExtendedBinarySensorDeviceClass.DEVICE_FORCIBLY_REMOVED,
device_class=BinarySensorDeviceClass.PROBLEM,
Expand All @@ -74,6 +88,10 @@
key=ExtendedBinarySensorDeviceClass.DOOR_STUCK,
device_class=BinarySensorDeviceClass.PROBLEM,
),
ExtendedBinarySensorDeviceClass.FINGERPRINT: BinarySensorEntityDescription(
key=ExtendedBinarySensorDeviceClass.FINGERPRINT,
icon="mdi:fingerprint",
),
ExtendedBinarySensorDeviceClass.KNOCK_ON_THE_DOOR: BinarySensorEntityDescription(
key=ExtendedBinarySensorDeviceClass.KNOCK_ON_THE_DOOR,
),
Expand Down
11 changes: 9 additions & 2 deletions homeassistant/components/xiaomi_ble/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@
XIAOMI_BLE_EVENT: Final = "xiaomi_ble_event"

EVENT_CLASS_BUTTON: Final = "button"
EVENT_CLASS_CUBE: Final = "cube"
EVENT_CLASS_DIMMER: Final = "dimmer"
EVENT_CLASS_ERROR: Final = "error"
EVENT_CLASS_FINGERPRINT: Final = "fingerprint"
EVENT_CLASS_LOCK: Final = "lock"
EVENT_CLASS_MOTION: Final = "motion"
EVENT_CLASS_CUBE: Final = "cube"

BUTTON: Final = "button"
CUBE: Final = "cube"
DIMMER: Final = "dimmer"
ERROR: Final = "error"
FINGERPRINT: Final = "fingerprint"
LOCK: Final = "lock"
LOCK_FINGERPRINT = "lock_fingerprint"
MOTION_DEVICE: Final = "motion_device"
DOUBLE_BUTTON: Final = "double_button"
TRIPPLE_BUTTON: Final = "tripple_button"
REMOTE: Final = "remote"
Expand All @@ -40,7 +48,6 @@
BUTTON_PRESS_DOUBLE_LONG: Final = "button_press_double_long"
DOUBLE_BUTTON_PRESS_DOUBLE_LONG: Final = "double_button_press_double_long"
TRIPPLE_BUTTON_PRESS_DOUBLE_LONG: Final = "tripple_button_press_double_long"
MOTION_DEVICE: Final = "motion_device"


class XiaomiBleEvent(TypedDict):
Expand Down
89 changes: 83 additions & 6 deletions homeassistant/components/xiaomi_ble/device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@
DOMAIN,
DOUBLE_BUTTON,
DOUBLE_BUTTON_PRESS_DOUBLE_LONG,
ERROR,
EVENT_CLASS,
EVENT_CLASS_BUTTON,
EVENT_CLASS_CUBE,
EVENT_CLASS_DIMMER,
EVENT_CLASS_ERROR,
EVENT_CLASS_FINGERPRINT,
EVENT_CLASS_LOCK,
EVENT_CLASS_MOTION,
EVENT_TYPE,
FINGERPRINT,
LOCK,
LOCK_FINGERPRINT,
MOTION,
MOTION_DEVICE,
REMOTE,
Expand All @@ -62,6 +69,51 @@
"rotate_left_pressed",
"rotate_right_pressed",
],
ERROR: [
"frequent_unlocking_with_incorrect_password",
"frequent_unlocking_with_wrong_fingerprints",
"operation_timeout_password_input_timeout",
"lock_picking",
"reset_button_is_pressed",
"the_wrong_key_is_frequently_unlocked",
"foreign_body_in_the_keyhole",
"the_key_has_not_been_taken_out",
"error_nfc_frequently_unlocks",
"timeout_is_not_locked_as_required",
"failure_to_unlock_frequently_in_multiple_ways",
"unlocking_the_face_frequently_fails",
"failure_to_unlock_the_vein_frequently",
"hijacking_alarm",
"unlock_inside_the_door_after_arming",
"palmprints_frequently_fail_to_unlock",
"the_safe_was_moved",
"the_battery_level_is_less_than_10_percent",
"the_battery_level_is_less_than_5_percent",
"the_fingerprint_sensor_is_abnormal",
"the_accessory_battery_is_low",
"mechanical_failure",
"the_lock_sensor_is_faulty",
],
FINGERPRINT: [
"match_successful",
"match_failed",
"low_quality_too_light_fuzzy",
"insufficient_area",
"skin_is_too_dry",
"skin_is_too_wet",
],
LOCK: [
"lock_outside_the_door",
"unlock_outside_the_door",
"lock_inside_the_door",
"unlock_inside_the_door",
"locked",
"turn_on_antilock",
"release_the_antilock",
"turn_on_child_lock",
"turn_off_child_lock",
"abnormal",
],
MOTION_DEVICE: ["motion_detected"],
}

Expand All @@ -71,6 +123,10 @@
DIMMER: ["dimmer"],
DOUBLE_BUTTON: ["button_left", "button_right"],
TRIPPLE_BUTTON: ["button_left", "button_middle", "button_right"],
ERROR: ["error"],
FINGERPRINT: ["fingerprint"],
LOCK: ["lock"],
MOTION: ["motion"],
REMOTE: [
"button_on",
"button_off",
Expand Down Expand Up @@ -106,7 +162,6 @@
"button_increase_wind_speed",
"button_decrease_wind_speed",
],
MOTION: ["motion"],
}


Expand Down Expand Up @@ -150,6 +205,26 @@ class TriggerModelData:
event_types=EVENT_TYPES[TRIPPLE_BUTTON],
triggers=TRIGGERS_BY_TYPE[BUTTON_PRESS_DOUBLE_LONG],
),
ERROR: TriggerModelData(
event_class=EVENT_CLASS_ERROR,
event_types=EVENT_TYPES[ERROR],
triggers=TRIGGERS_BY_TYPE[ERROR],
),
LOCK_FINGERPRINT: TriggerModelData(
event_class=EVENT_CLASS_FINGERPRINT,
event_types=EVENT_TYPES[LOCK] + EVENT_TYPES[FINGERPRINT],
triggers=TRIGGERS_BY_TYPE[LOCK] + TRIGGERS_BY_TYPE[FINGERPRINT],
),
LOCK: TriggerModelData(
event_class=EVENT_CLASS_LOCK,
event_types=EVENT_TYPES[LOCK],
triggers=TRIGGERS_BY_TYPE[LOCK],
),
MOTION_DEVICE: TriggerModelData(
event_class=EVENT_CLASS_MOTION,
event_types=EVENT_TYPES[MOTION],
triggers=TRIGGERS_BY_TYPE[MOTION_DEVICE],
),
REMOTE: TriggerModelData(
event_class=EVENT_CLASS_BUTTON,
event_types=EVENT_TYPES[REMOTE],
Expand All @@ -170,11 +245,6 @@ class TriggerModelData:
event_types=EVENT_TYPES[REMOTE_VENFAN],
triggers=TRIGGERS_BY_TYPE[BUTTON_PRESS_LONG],
),
MOTION_DEVICE: TriggerModelData(
event_class=EVENT_CLASS_MOTION,
event_types=EVENT_TYPES[MOTION],
triggers=TRIGGERS_BY_TYPE[MOTION_DEVICE],
),
}


Expand All @@ -197,6 +267,13 @@ class TriggerModelData:
"MUE4094RT": TRIGGER_MODEL_DATA[MOTION_DEVICE],
"XMMF01JQD": TRIGGER_MODEL_DATA[CUBE],
"YLKG07YL/YLKG08YL": TRIGGER_MODEL_DATA[DIMMER],
"DSL-C08": TRIGGER_MODEL_DATA[LOCK],
"XMZNMS08LM": TRIGGER_MODEL_DATA[LOCK],
"Lockin-SV40": TRIGGER_MODEL_DATA[LOCK_FINGERPRINT],
"MJZNMSQ01YD": TRIGGER_MODEL_DATA[LOCK_FINGERPRINT],
"XMZNMS04LM": TRIGGER_MODEL_DATA[LOCK_FINGERPRINT],
"ZNMS16LM": TRIGGER_MODEL_DATA[LOCK_FINGERPRINT],
"ZNMS17LM": TRIGGER_MODEL_DATA[LOCK_FINGERPRINT],
}


Expand Down
60 changes: 60 additions & 0 deletions homeassistant/components/xiaomi_ble/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
EVENT_CLASS_BUTTON,
EVENT_CLASS_CUBE,
EVENT_CLASS_DIMMER,
EVENT_CLASS_ERROR,
EVENT_CLASS_FINGERPRINT,
EVENT_CLASS_LOCK,
EVENT_CLASS_MOTION,
EVENT_PROPERTIES,
EVENT_TYPE,
Expand Down Expand Up @@ -59,6 +62,63 @@
"rotate_right_pressed",
],
),
EVENT_CLASS_ERROR: EventEntityDescription(
key=EVENT_CLASS_ERROR,
translation_key="error",
event_types=[
"frequent_unlocking_with_incorrect_password",
"frequent_unlocking_with_wrong_fingerprints",
"operation_timeout_password_input_timeout",
"lock_picking",
"reset_button_is_pressed",
"the_wrong_key_is_frequently_unlocked",
"foreign_body_in_the_keyhole",
"the_key_has_not_been_taken_out",
"error_nfc_frequently_unlocks",
"timeout_is_not_locked_as_required",
"failure_to_unlock_frequently_in_multiple_ways",
"unlocking_the_face_frequently_fails",
"failure_to_unlock_the_vein_frequently",
"hijacking_alarm",
"unlock_inside_the_door_after_arming",
"palmprints_frequently_fail_to_unlock",
"the_safe_was_moved",
"the_battery_level_is_less_than_10_percent",
"the_battery_is_less_than_5_percent",
"the_fingerprint_sensor_is_abnormal",
"the_accessory_battery_is_low",
"mechanical_failure",
"the_lock_sensor_is_faulty",
],
),
EVENT_CLASS_FINGERPRINT: EventEntityDescription(
key=EVENT_CLASS_FINGERPRINT,
translation_key="fingerprint",
event_types=[
"match_successful",
"match_failed",
"low_quality_too_light_fuzzy",
"insufficient_area",
"skin_is_too_dry",
"skin_is_too_wet",
],
),
EVENT_CLASS_LOCK: EventEntityDescription(
key=EVENT_CLASS_LOCK,
translation_key="lock",
event_types=[
"lock_outside_the_door",
"unlock_outside_the_door",
"lock_inside_the_door",
"unlock_inside_the_door",
"locked",
"turn_on_antilock",
"release_the_antilock",
"turn_on_child_lock",
"turn_off_child_lock",
"abnormal",
],
),
EVENT_CLASS_MOTION: EventEntityDescription(
key=EVENT_CLASS_MOTION,
translation_key="motion",
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/xiaomi_ble/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
"dependencies": ["bluetooth_adapters"],
"documentation": "https://www.home-assistant.io/integrations/xiaomi_ble",
"iot_class": "local_push",
"requirements": ["xiaomi-ble==0.25.2"]
"requirements": ["xiaomi-ble==0.26.1"]
}
14 changes: 11 additions & 3 deletions homeassistant/components/xiaomi_ble/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,31 @@
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
),
# Used for e.g. consumable sensor on WX08ZM and M1S-T500
# E.g. consumable sensor on WX08ZM and M1S-T500
(ExtendedSensorDeviceClass.CONSUMABLE, Units.PERCENTAGE): SensorEntityDescription(
key=str(ExtendedSensorDeviceClass.CONSUMABLE),
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
# Used for score after brushing with a toothbrush
# Score after brushing with a toothbrush
(ExtendedSensorDeviceClass.SCORE, None): SensorEntityDescription(
key=str(ExtendedSensorDeviceClass.SCORE),
state_class=SensorStateClass.MEASUREMENT,
),
# Used for counting during brushing
# Counting during brushing
(ExtendedSensorDeviceClass.COUNTER, Units.TIME_SECONDS): SensorEntityDescription(
key=str(ExtendedSensorDeviceClass.COUNTER),
native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.MEASUREMENT,
),
# Key id for locks and fingerprint readers
(ExtendedSensorDeviceClass.KEY_ID, None): SensorEntityDescription(
key=str(ExtendedSensorDeviceClass.KEY_ID), icon="mdi:identifier"
),
# Lock method for locks
(ExtendedSensorDeviceClass.LOCK_METHOD, None): SensorEntityDescription(
key=str(ExtendedSensorDeviceClass.LOCK_METHOD), icon="mdi:key-variant"
),
}


Expand Down