From 301a80e47fb664676d9cebc7ba58df8b9ee9162f Mon Sep 17 00:00:00 2001 From: Gary O'Donovan <zixty@ucc.asn.au> Date: Wed, 18 Sep 2024 01:21:08 +0800 Subject: [PATCH] updated original files with ucc specfic updates --- .gitignore | 3 +++ scripts/repl | 2 +- src/code.py | 8 ++++---- src/mqtt.py | 10 +++++----- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 03910c4..8340c17 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ # User-specific configuration /src/settings.toml + +# vim swap files +*~ diff --git a/scripts/repl b/scripts/repl index 54a68fa..84ebe38 100755 --- a/scripts/repl +++ b/scripts/repl @@ -2,7 +2,7 @@ set -euo pipefail -device=$(ls -1 -t /dev/tty.usbmodem*) +device=$(ls -1 -t /dev/ttyACM*) # Reattach to an existing session if one exists; otherwise create a new one screen -D -R -S circuitpython "$device" 115200 diff --git a/src/code.py b/src/code.py index 646c674..0e03063 100644 --- a/src/code.py +++ b/src/code.py @@ -22,8 +22,8 @@ def main(logger: adafruit_logging.Logger) -> None: led = digitalio.DigitalInOut(board.LED) led.switch_to_output() - switch_io = digitalio.DigitalInOut(board.GP22) - # GPIO 22 has a pull-up resistor so we don't pull it up in code + switch_io = digitalio.DigitalInOut(board.GP18) + switch_io.pull = digitalio.Pull.DOWN switch_io.switch_to_input() switch = adafruit_debouncer.Debouncer(switch_io) @@ -58,7 +58,7 @@ def main(logger: adafruit_logging.Logger) -> None: logger.info("Connected to the MQTT broker") mqtt_device_id = binascii.hexlify(microcontroller.cpu.uid).decode("utf-8") - mqtt_state_topic = f"door/{mqtt_device_id}/state" + mqtt_state_topic = f"door/ucc-door/state" publish_homeassistant_discovery_message(mqtt, mqtt_device_id, mqtt_state_topic) publish_sensor_state_message(mqtt, mqtt_state_topic, not switch.value) logger.info("Advertised Home Assistant discovery message and current door state") @@ -69,7 +69,7 @@ def main(logger: adafruit_logging.Logger) -> None: mqtt.loop() if switch.rose or switch.fell: - is_door_open = not switch.value + is_door_open = switch.value logger.info( "Detected the door open" if is_door_open else "Detected the door closed" ) diff --git a/src/mqtt.py b/src/mqtt.py index 6ae14fe..53b70d2 100644 --- a/src/mqtt.py +++ b/src/mqtt.py @@ -9,16 +9,16 @@ def publish_homeassistant_discovery_message( json.dumps( { "unique_id": device_id, - "name": "Garage Door", - "object_id": "garage_door", + "name": "UCC Door", + "object_id": "door", "device": { - "name": "Door Sensor", + "name": "UCC Door Sensor", "identifiers": [device_id], "model": "Raspberry Pi Pico W Door Sensor", "manufacturer": "Raspberry Pi", - "suggested_area": "garage", + "suggested_area": "UCC Door", }, - "device_class": "garage_door", + "device_class": "door", "state_topic": state_topic, } ), -- GitLab