Skip to content

Commit 23d2379

Browse files
authored
Merge pull request #1532 from makermelissa/master
FunHouse Motion Controlled Outlet MQTT loop Bug fix
2 parents c517263 + b419fc3 commit 23d2379

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

FunHouse_Motion_Outlet/code.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
OUTLET_STATE_TOPIC = "funhouse/outlet/state"
1313
OUTLET_COMMAND_TOPIC = "funhouse/outlet/set"
1414
MOTION_TIMEOUT = 300 # Timeout in seconds
15+
USE_MQTT = False
1516

16-
try:
17-
from secrets import secrets
18-
except ImportError:
19-
print("WiFi secrets are kept in secrets.py, please add them there!")
20-
raise
17+
if USE_MQTT:
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
2123

2224
def set_outlet_state(value):
2325
global last_pir_timestamp
@@ -32,7 +34,7 @@ def set_outlet_state(value):
3234
publish_outlet_state()
3335

3436
def publish_outlet_state():
35-
if OUTLET_STATE_TOPIC and OUTLET_COMMAND_TOPIC:
37+
if USE_MQTT:
3638
funhouse.peripherals.led = True
3739
output = "on" if outlet.value else "off"
3840
# Publish the Dotstar State
@@ -88,7 +90,7 @@ def timeleft():
8890
funhouse.splash.append(status)
8991

9092
# Initialize a new MQTT Client object
91-
if OUTLET_STATE_TOPIC and OUTLET_COMMAND_TOPIC:
93+
if USE_MQTT:
9294
funhouse.network.init_mqtt(
9395
secrets["mqtt_broker"],
9496
secrets["mqtt_port"],
@@ -112,4 +114,5 @@ def timeleft():
112114
set_outlet_state(False)
113115
funhouse.set_text(timeleft(), countdown_label)
114116
# Check any topics we are subscribed to
115-
funhouse.network.mqtt_loop(0.5)
117+
if USE_MQTT:
118+
funhouse.network.mqtt_loop(0.5)

0 commit comments

Comments
 (0)