33#
44# SPDX-License-Identifier: MIT
55
6+ import os
67import time
78import board
89import digitalio
1314BOWL_STATE_TOPIC = "funhouse/catbowl/state"
1415LOW_VALUE = 4000
1516EMPTY_VALUE = 2000
16- UPDATE_INTERVAL = 1800 # Every 30 minutes
17-
18- try :
19- from secrets import secrets
20- except ImportError :
21- print ("WiFi secrets are kept in secrets.py, please add them there!" )
22- raise
17+ UPDATE_INTERVAL = 1800 # Every 30 minutes
2318
2419# Text labels for the Display
2520states = {
2823 "full" : "Full" ,
2924}
3025
31- def publish_bowl_state (bowl_state ):
26+ def publish_bowl_state (state ):
3227 funhouse .peripherals .led = True
3328 # Publish the Bowl Level State
3429 print ("Publishing to {}" .format (BOWL_STATE_TOPIC ))
35- funhouse .network .mqtt_publish (BOWL_STATE_TOPIC , bowl_state )
30+ funhouse .network .mqtt_publish (BOWL_STATE_TOPIC , state )
3631 funhouse .peripherals .led = False
3732
38- def connected (client , userdata , result , payload ):
33+ def connected (_client , _userdata , _result , _payload ):
3934 status .fill = 0x00FF00
4035 status .outline = 0x008800
4136
42- def disconnected (client ):
37+ def disconnected (_client ):
4338 status .fill = 0xFF0000
4439 status .outline = 0x880000
4540
@@ -56,10 +51,10 @@ def get_bowl_state(level):
5651 return "low"
5752 return "full"
5853
59- def bowl_level_display (water_level ):
54+ def bowl_level_display (level ):
6055 if funhouse .peripherals .button_sel :
61- return water_level
62- return states [get_bowl_state (water_level )]
56+ return level
57+ return states [get_bowl_state (level )]
6358
6459# Set Initial States
6560funhouse = FunHouse (default_bg = 0x0F0F00 )
@@ -88,22 +83,25 @@ def bowl_level_display(water_level):
8883
8984# Initialize a new MQTT Client object
9085funhouse .network .init_mqtt (
91- secrets [ "mqtt_broker" ] ,
92- secrets [ "mqtt_port" ] ,
93- secrets [ "mqtt_username" ] ,
94- secrets [ "mqtt_password" ] ,
86+ os . getenv ( "MQTT_BROKER" ) ,
87+ os . getenv ( "MQTT_PORT" ) ,
88+ os . getenv ( "MQTT_USERNAME" ) ,
89+ os . getenv ( "MQTT_PASSWORD" ) ,
9590)
9691funhouse .network .on_mqtt_connect = connected
9792funhouse .network .on_mqtt_disconnect = disconnected
9893
99- print ("Attempting to connect to {}" .format (secrets [ "mqtt_broker" ] ))
94+ print ("Attempting to connect to {}" .format (os . getenv ( "MQTT_BROKER" ) ))
10095funhouse .network .mqtt_connect ()
10196
10297last_reading_timestamp = None
10398last_bowl_state = None
10499
105100while True :
106- if last_reading_timestamp is None or time .monotonic () > last_reading_timestamp + UPDATE_INTERVAL :
101+ if (
102+ last_reading_timestamp is None
103+ or time .monotonic () > last_reading_timestamp + UPDATE_INTERVAL
104+ ):
107105 # Take Reading
108106 water_level = get_bowl_reading ()
109107 # Update Display
0 commit comments