Skip to content

Commit 64d7df9

Browse files
authored
Merge pull request #2612 from makermelissa/main
Update and Lint FunHouse Pet Bowl Sensor code to work with settings.toml
2 parents 4bce9de + 61c29b5 commit 64d7df9

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

FunHouse_Pet_Bowl_Sensor/.circuitpython.skip

Lines changed: 0 additions & 8 deletions
This file was deleted.

FunHouse_Pet_Bowl_Sensor/code.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44
# SPDX-License-Identifier: MIT
55

6+
import os
67
import time
78
import board
89
import digitalio
@@ -13,13 +14,7 @@
1314
BOWL_STATE_TOPIC = "funhouse/catbowl/state"
1415
LOW_VALUE = 4000
1516
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
2318

2419
# Text labels for the Display
2520
states = {
@@ -28,18 +23,18 @@
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
6560
funhouse = FunHouse(default_bg=0x0F0F00)
@@ -88,22 +83,25 @@ def bowl_level_display(water_level):
8883

8984
# Initialize a new MQTT Client object
9085
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"),
9590
)
9691
funhouse.network.on_mqtt_connect = connected
9792
funhouse.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")))
10095
funhouse.network.mqtt_connect()
10196

10297
last_reading_timestamp = None
10398
last_bowl_state = None
10499

105100
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+
):
107105
# Take Reading
108106
water_level = get_bowl_reading()
109107
# Update Display

0 commit comments

Comments
 (0)