FEAT: Started the outline of the LIFX code needed to at least get the lights
This commit is contained in:
parent
74b9cd6a3b
commit
70418ef16c
6
config/config.py
Normal file
6
config/config.py
Normal file
@ -0,0 +1,6 @@
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
|
||||
load_dotenv()
|
||||
|
||||
LIFX_TOKEN = os.getenv("LIFX_TOKEN")
|
27
modules/smart_home/lifx.py
Normal file
27
modules/smart_home/lifx.py
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user