3
3
#
4
4
# SPDX-License-Identifier: MIT
5
5
6
+ import os
6
7
import time
7
8
import board
8
9
import digitalio
13
14
BOWL_STATE_TOPIC = "funhouse/catbowl/state"
14
15
LOW_VALUE = 4000
15
16
EMPTY_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
23
18
24
19
# Text labels for the Display
25
20
states = {
28
23
"full" : "Full" ,
29
24
}
30
25
31
- def publish_bowl_state (bowl_state ):
26
+ def publish_bowl_state (state ):
32
27
funhouse .peripherals .led = True
33
28
# Publish the Bowl Level State
34
29
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 )
36
31
funhouse .peripherals .led = False
37
32
38
- def connected (client , userdata , result , payload ):
33
+ def connected (_client , _userdata , _result , _payload ):
39
34
status .fill = 0x00FF00
40
35
status .outline = 0x008800
41
36
42
- def disconnected (client ):
37
+ def disconnected (_client ):
43
38
status .fill = 0xFF0000
44
39
status .outline = 0x880000
45
40
@@ -56,10 +51,10 @@ def get_bowl_state(level):
56
51
return "low"
57
52
return "full"
58
53
59
- def bowl_level_display (water_level ):
54
+ def bowl_level_display (level ):
60
55
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 )]
63
58
64
59
# Set Initial States
65
60
funhouse = FunHouse (default_bg = 0x0F0F00 )
@@ -88,22 +83,25 @@ def bowl_level_display(water_level):
88
83
89
84
# Initialize a new MQTT Client object
90
85
funhouse .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" ) ,
95
90
)
96
91
funhouse .network .on_mqtt_connect = connected
97
92
funhouse .network .on_mqtt_disconnect = disconnected
98
93
99
- print ("Attempting to connect to {}" .format (secrets [ "mqtt_broker" ] ))
94
+ print ("Attempting to connect to {}" .format (os . getenv ( "MQTT_BROKER" ) ))
100
95
funhouse .network .mqtt_connect ()
101
96
102
97
last_reading_timestamp = None
103
98
last_bowl_state = None
104
99
105
100
while 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
+ ):
107
105
# Take Reading
108
106
water_level = get_bowl_reading ()
109
107
# Update Display
0 commit comments