Skip to content

Commit 8a5620c

Browse files
authored
Merge pull request #25 from justmobilize/remove-secrets-and-more
Remove secrets and more
2 parents 0efb4dc + 2badb9b commit 8a5620c

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

adafruit_lifx.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,17 @@
4545
class LIFX:
4646
"""HTTP Interface for interacting with the LIFX API
4747
48-
:param wifi_manager: WiFiManager from ESPSPI_WiFiManager/ESPAT_WiFiManager
49-
or session from adafruit_requests.Session
48+
:param wifi_manager wifi_manager: WiFiManager or Session
5049
:param str lifx_token: LIFX API token (https://api.developer.lifx.com/docs/authentication)
5150
"""
5251

5352
def __init__(self, wifi_manager: HTTPProtocol, lifx_token: str) -> None:
54-
wifi_type = str(type(wifi_manager))
55-
allowed_wifi_types = ("ESPSPI_WiFiManager", "ESPAT_WiFiManager", "Session")
56-
if any(x in wifi_type for x in allowed_wifi_types):
57-
self._wifi = wifi_manager
58-
else:
59-
raise TypeError("This library requires a WiFiManager or Session object.")
53+
for attr in ("get", "post", "put"):
54+
if not hasattr(wifi_manager, attr):
55+
error = "This library requires a WiFiManager or Session object with a "
56+
error += f"`{attr}` method, not {type(wifi_manager)}"
57+
raise TypeError(error)
58+
self._wifi = wifi_manager
6059
self._lifx_token = lifx_token
6160
self._auth_header = {
6261
"Authorization": "Bearer %s" % self._lifx_token,

examples/lifx_simpletest.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4+
from os import getenv
45
import board
56
import busio
67
from digitalio import DigitalInOut
78
from adafruit_esp32spi import adafruit_esp32spi
8-
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
9+
from adafruit_esp32spi.adafruit_esp32spi_wifimanager import WiFiManager
910
import neopixel
1011

1112
import adafruit_lifx
1213

13-
# Get wifi details and more from a secrets.py file
14-
try:
15-
from secrets import secrets
16-
except ImportError:
17-
print("WiFi and API secrets are kept in secrets.py, please add them there!")
18-
raise
14+
# Get WiFi details, ensure these are setup in settings.toml
15+
ssid = getenv("CIRCUITPY_WIFI_SSID")
16+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
1917

2018
# ESP32 SPI
2119
esp32_cs = DigitalInOut(board.ESP_CS)
2220
esp32_ready = DigitalInOut(board.ESP_BUSY)
2321
esp32_reset = DigitalInOut(board.ESP_RESET)
2422
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
2523
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
26-
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
27-
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
24+
status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
25+
wifi = WiFiManager(esp, ssid, password, status_pixel=status_pixel)
2826

2927
# Add your LIFX Personal Access token to secrets.py
3028
# (to obtain a token, visit: https://cloud.lifx.com/settings)
31-
lifx_token = secrets["lifx_token"]
29+
lifx_token = getenv("lifx_token")
30+
31+
if lifx_token is None:
32+
raise KeyError("Please add your lifx token to settings.toml")
3233

3334
# Set this to your LIFX light separator label
3435
# https://api.developer.lifx.com/docs/selectors

0 commit comments

Comments
 (0)