Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Commit

Permalink
Add remove_lock parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>
  • Loading branch information
Nardol committed Feb 2, 2023
1 parent 3d58f97 commit 97bf8ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Just copy the URL of this repository and add it under HACS --> Custom Repositori
| discovery_topic | string | No | The home assistant auto. discovery topic (Default: homeassistant) | homeassistant |
| door_sensor_available | boolean | No | If true, the door sensor data is also discovered (Default: false) | true |
| keypad_available | boolean | No | If true, the keypad data is also discovered (Default: false) | false |
| remove_lock | boolean | No | If true, all MQTT Nuki related topics are removed (Default: false) | false |

### Example

Expand Down
25 changes: 15 additions & 10 deletions python_scripts/nuki_mqtt_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
DISCOVERY_TOPIC = "discovery_topic"
DOOR_SENSOR_AVAILABLE = "door_sensor_available"
KEYPAD_AVAILABLE = "keypad_available"
REMOVE_LOCK = "remove_lock"

DEFAULT_DISCOVERY_TOPIC = "homeassistant"

Expand Down Expand Up @@ -239,6 +240,7 @@ def main(hass, data):
discovery_topic = data.get(DISCOVERY_TOPIC) or DEFAULT_DISCOVERY_TOPIC
door_sensor_available = data.get(DOOR_SENSOR_AVAILABLE) or False
keypad_available = data.get(KEYPAD_AVAILABLE) or False
remove_lock = data.get(REMOVE_LOCK) or False

if isinstance(device_id, int): # Because of hex device id, always convert it to string
device_id = str(device_id)
Expand All @@ -255,57 +257,60 @@ def main(hass, data):
logger.error(get_error_message(DEVICE_MODEL, device_model))
return

if remove_lock:
logger.warning("Uninstalling")

# Lock
name = device_name
publish(hass, get_discovery_topic(discovery_topic, "lock", device_id, "lock"),
get_lock_payload(device_id, device_name, device_model, name))
get_lock_payload(device_id, device_name, device_model, name) if not remove_lock else "")

# Battery critical
name = device_name + " Battery critical"
publish(hass, get_discovery_topic(discovery_topic, "binary_sensor", device_id, "lock_battery_critical"),
get_battery_critical_payload(device_id, device_name, device_model, name))
get_battery_critical_payload(device_id, device_name, device_model, name) if not remove_lock else "")

# Battery charge state
name = device_name + " Battery"
publish(hass, get_discovery_topic(discovery_topic, "sensor", device_id, "battery_percent"),
get_battery_charge_state_payload(device_id, device_name, device_model, name))
get_battery_charge_state_payload(device_id, device_name, device_model, name) if not remove_lock else "")

# Battery charging
name = device_name + " Battery charging"
publish(hass, get_discovery_topic(discovery_topic, "binary_sensor", device_id, "battery_charging"),
get_battery_charging_payload(device_id, device_name, device_model, name))
get_battery_charging_payload(device_id, device_name, device_model, name) if not remove_lock else "")

if door_sensor_available:
# Door sensor
name = device_name + " Door sensor"
publish(hass, get_discovery_topic(discovery_topic, "binary_sensor", device_id, "door_sensor"),
get_door_sensor_payload(device_id, device_name, device_model, name))
get_door_sensor_payload(device_id, device_name, device_model, name) if not remove_lock else "")

# Door sensor battery critical
name = device_name + " Door sensor battery critical"
publish(hass, get_discovery_topic(discovery_topic, "binary_sensor", device_id, "door_sensor_battery_critical"),
get_door_sensor_battery_critical_payload(device_id, device_name, device_model, name))
get_door_sensor_battery_critical_payload(device_id, device_name, device_model, name) if not remove_lock else "")

if keypad_available:
# Keypad battery critical
name = device_name + " Keypad battery critical"
publish(hass, get_discovery_topic(discovery_topic, "binary_sensor", device_id, "keypad_battery_critical"),
get_keypad_battery_critical_payload(device_id, device_name, device_model, name))
get_keypad_battery_critical_payload(device_id, device_name, device_model, name) if not remove_lock else "")

# Unlatch button
name = device_name + " Unlatch"
publish(hass, get_discovery_topic(discovery_topic, "button", device_id, "unlatch_button"),
get_button_payload(device_id, device_name, device_model, name, ACTION_UNLATCH, "unlatch"))
get_button_payload(device_id, device_name, device_model, name, ACTION_UNLATCH, "unlatch") if not remove_lock else "")

# Lock'n'Go button
name = device_name + " Lock-n-Go"
publish(hass, get_discovery_topic(discovery_topic, "button", device_id, "lockngo_button"),
get_button_payload(device_id, device_name, device_model, name, ACTION_LOCKNGO, "lock_n_go"))
get_button_payload(device_id, device_name, device_model, name, ACTION_LOCKNGO, "lock_n_go") if not remove_lock else "")

# Lock'n'Go with unlatch button
name = device_name + " Lock-n-Go with unlatch"
publish(hass, get_discovery_topic(discovery_topic, "button", device_id, "lock_n_go_unlatch"),
get_button_payload(device_id, device_name, device_model, name, ACTION_LOCKNGO_UNLATCH, "lock_n_go_unlatch"))
get_button_payload(device_id, device_name, device_model, name, ACTION_LOCKNGO_UNLATCH, "lock_n_go_unlatch") if not remove_lock else "")


main(hass, data)

0 comments on commit 97bf8ed

Please sign in to comment.