diff --git a/.gitignore b/.gitignore index 03910c478c78239a6a357f2af0567dc56349f73f..8340c174917cfac2f69f880ddca4ca8e1340eb63 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 54a68faea363825fa49e50783ee46f7c0cbb1c10..84ebe38a5a6e9ea7ec709fe505f67dd8e1cd2363 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 646c674f2536f02c723adb7305b83cec7c665a55..0e03063ae41bdcc82a67539e007fcd1cdcdd9e8e 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 6ae14fe4268eed0fe7afe2859eda1585503ee864..53b70d209544e746732347f1489f0df3c84d9f53 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, } ),