diff --git a/tinge/HueBridge/__init__.py b/tinge/HueBridge/__init__.py index 8ed397c..48e5212 100644 --- a/tinge/HueBridge/__init__.py +++ b/tinge/HueBridge/__init__.py @@ -27,6 +27,8 @@ class HueBridge: else: self.m_name = self.m_ipaddress self.m_lights: list[HueLight] = self.discover_lights() + self.discover_new_lights() + self.m_new_lights: list[HueLight] = self.get_new_lights() self.m_groups: list[HueGroup] = self.discover_groups() def __str__(self) -> str: @@ -183,6 +185,19 @@ class HueBridge: """ return self.m_lights + def get_new_lights(self) -> list[HueLight]: + path: str = "{}/lights/new".format(self.m_username) + response = make_request(self.m_ipaddress, path) + newlights: list[HueLight] = list() + for lightid, nameobj in response.json().items(): + if lightid != "lastscan": + print(lightid) + if not self.get_light_by_id(int(lightid)): + lightpath: str = "{}/lights/{}".format(self.m_username, int(lightid)) + lightresponse = make_request(self.m_ipaddress, lightpath) + newlights.append(HueLight(int(lightid), lightresponse.json(), self.get_ipaddress(),self.get_user())) + return newlights + def get_user(self) -> str: """A user, or username, is more like a password and is needed to authenticate with the Hue API