You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tinge/tinge/HueBridge/__init__.py

36 lines
1.0 KiB

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
from ..HueLight import HueLight
from ..HueUtils import make_request
class HueBridge():
def __init__(self, ipaddress: str, username: str):
self.m_ipaddress: str = ipaddress
self.m_username: str = username
self.m_lights: list[HueLight] = self.discover_lights()
def discover_lights(self) -> list[HueLight]:
path: str = "{}/lights".format(self.m_username)
response = make_request(self.m_ipaddress, path)
lights: list[HueLight] = list()
for key, value in json.loads(response.text).items():
lights.append(HueLight(key, value, self.get_ipaddress(), self.get_user()))
return lights
def get_lights(self):
return self.m_lights
def get_light_by_id(self, id: int) -> HueLight:
for light in self.m_lights:
if light.get_id() == id:
return light
def get_ipaddress(self):
return self.m_ipaddress
def get_user(self):
return self.m_username