Skip to content

Remove secrets and more #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions adafruit_lifx.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,17 @@
class LIFX:
"""HTTP Interface for interacting with the LIFX API

:param wifi_manager: WiFiManager from ESPSPI_WiFiManager/ESPAT_WiFiManager
or session from adafruit_requests.Session
:param wifi_manager wifi_manager: WiFiManager or Session
:param str lifx_token: LIFX API token (https://api.developer.lifx.com/docs/authentication)
"""

def __init__(self, wifi_manager: HTTPProtocol, lifx_token: str) -> None:
wifi_type = str(type(wifi_manager))
allowed_wifi_types = ("ESPSPI_WiFiManager", "ESPAT_WiFiManager", "Session")
if any(x in wifi_type for x in allowed_wifi_types):
self._wifi = wifi_manager
else:
raise TypeError("This library requires a WiFiManager or Session object.")
for attr in ("get", "post", "put"):
if not hasattr(wifi_manager, attr):
error = "This library requires a WiFiManager or Session object with a "
error += f"`{attr}` method, not {type(wifi_manager)}"
raise TypeError(error)
self._wifi = wifi_manager
self._lifx_token = lifx_token
self._auth_header = {
"Authorization": "Bearer %s" % self._lifx_token,
Expand Down
21 changes: 11 additions & 10 deletions examples/lifx_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

from os import getenv
import board
import busio
from digitalio import DigitalInOut
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
from adafruit_esp32spi.adafruit_esp32spi_wifimanager import WiFiManager
import neopixel

import adafruit_lifx

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

# ESP32 SPI
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
wifi = WiFiManager(esp, ssid, password, status_pixel=status_pixel)

# Add your LIFX Personal Access token to secrets.py
# (to obtain a token, visit: https://cloud.lifx.com/settings)
lifx_token = secrets["lifx_token"]
lifx_token = getenv("lifx_token")

if lifx_token is None:
raise KeyError("Please add your lifx token to settings.toml")

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