From 70418ef16cf8751eb34400f02edfa3d48a14bea4 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 18 Jul 2024 21:56:59 -0400 Subject: [PATCH] FEAT: Started the outline of the LIFX code needed to at least get the lights --- config/config.py | 6 ++++++ modules/smart_home/lifx.py | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 config/config.py create mode 100644 modules/smart_home/lifx.py diff --git a/config/config.py b/config/config.py new file mode 100644 index 0000000..a903962 --- /dev/null +++ b/config/config.py @@ -0,0 +1,6 @@ +from dotenv import load_dotenv +import os + +load_dotenv() + +LIFX_TOKEN = os.getenv("LIFX_TOKEN") diff --git a/modules/smart_home/lifx.py b/modules/smart_home/lifx.py new file mode 100644 index 0000000..47ec146 --- /dev/null +++ b/modules/smart_home/lifx.py @@ -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)