Skip to content

Commit 613895c

Browse files
authored
Merge pull request #2768 from adafruit/dhalbert-patch-4
Update PyPortal_Philips_Hue_Controller to use settings.toml
2 parents c6b2695 + 7f2cceb commit 613895c

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

  • PyPortal/PyPortal_Philips_Hue_Controller

PyPortal/PyPortal_Philips_Hue_Controller/code.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
88
Brent Rubell for Adafruit Industries, 2019
99
"""
10+
import os
11+
1012
import board
1113
import displayio
1214
from adafruit_bitmap_font import bitmap_font
@@ -21,12 +23,9 @@
2123
# Import Philips Hue Bridge
2224
from adafruit_hue import Bridge
2325

24-
# Get wifi details and more from a secrets.py file
25-
try:
26-
from secrets import secrets
27-
except ImportError:
28-
print("WiFi secrets are kept in secrets.py, please add them there!")
29-
raise
26+
secrets = dict()
27+
secrets["ssid"] = os.getenv("CIRCUITPY_WIFI_SSID")
28+
secrets["password"] = os.getenv("CIRCUITPY_WIFI_PASSWORD")
3029

3130
# ESP32 SPI
3231
esp32_cs = DigitalInOut(board.ESP_CS)
@@ -39,8 +38,8 @@
3938

4039
# Attempt to load bridge username and IP address from secrets.py
4140
try:
42-
username = secrets['hue_username']
43-
bridge_ip = secrets['bridge_ip']
41+
username = os.getenv("HUE_USERNAME")
42+
bridge_ip = os.getenv("BRIDGE_IP")
4443
my_bridge = Bridge(wifi, bridge_ip, username)
4544
except:
4645
# Perform first-time bridge setup
@@ -49,9 +48,9 @@
4948
ip = my_bridge.discover_bridge()
5049
print('Attempting to register username, press the link button on your Hue Bridge now!')
5150
username = my_bridge.register_username()
52-
print('ADD THESE VALUES TO SECRETS.PY: \
53-
\n\t"bridge_ip":"{0}", \
54-
\n\t"hue_username":"{1}"'.format(ip, username))
51+
print(f'ADD THESE VALUES TO settings.toml: \
52+
\nBRIDGE_IP = "{ip}" \
53+
\nHUE_USERNAME = "{username}"')
5554
raise
5655

5756
# These pins are used as both analog and digital! XL, XR and YU must be analog

0 commit comments

Comments
 (0)