FEAT: Started the outline of the LIFX code needed to at least get the lights

This commit is contained in:
Dan 2024-07-18 21:56:59 -04:00
parent 74b9cd6a3b
commit 70418ef16c
2 changed files with 33 additions and 0 deletions

6
config/config.py Normal file
View File

@ -0,0 +1,6 @@
from dotenv import load_dotenv
import os
load_dotenv()
LIFX_TOKEN = os.getenv("LIFX_TOKEN")

View File

@ -0,0 +1,27 @@
from config.config import LIFX_TOKEN
import requests
token = LIFX_TOKEN
# Authorize ourselves
headers = {
"Authorization": "Bearer %s" % token,
}
def get_lights() -> str:
# This is for Troubleshooting purposes
# Get all lights
response = requests.get("https://api.lifx.com/v1/lights/all",
headers=headers)
# Make sure we got a response of 200
if response.status_code == 200:
lights = response.json()
# Show what Lights we have access to
for light in lights:
print(f"ID: {light['id']}, Label: {light['label']},"
f"Power: {light['power']}, "
f"Brightness: {light['brightness']}, Color: {light['color']}"
)
else:
print("Error: %s" % response.status_code)