Fix for #1 Show unattached lights
This patch will allow lights that have not yet been added to a group to be manipulated on their own, potentially opening up for support for adding lights to groups from the ui.
This commit is contained in:
parent
a6f2e69e2e
commit
d6bfe8dcef
3 changed files with 62 additions and 12 deletions
54
main.py
Normal file → Executable file
54
main.py
Normal file → Executable file
|
@ -88,9 +88,15 @@ class Hui(wx.Frame):
|
|||
"""
|
||||
self.SetTitle("Tinge - {}".format(self.cur_bridge.m_name))
|
||||
bridge_btn: wx.Button = wx.Button(self.pnl, label="All Bridges")
|
||||
group_label: wx.StaticText = wx.StaticText(self.pnl, label=" ⚯ Groups ⚯ ", style=wx.ALIGN_CENTER)
|
||||
unattached_label: wx.StaticText = wx.StaticText(self.pnl, label=" ⚬ Unattached lights ⚬ ", style=wx.ALIGN_CENTER)
|
||||
|
||||
has_unattached: bool = len(self.cur_bridge.unattached_lights) > 0
|
||||
self.sizer.Add(bridge_btn, 0, wx.EXPAND)
|
||||
self.Bind(wx.EVT_BUTTON,
|
||||
lambda event: self.add_bridges(), bridge_btn)
|
||||
if has_unattached:
|
||||
self.sizer.Add(group_label, 0, wx.EXPAND)
|
||||
for group in groups:
|
||||
inner_sizer: wx.BoxSizer = wx.BoxSizer(orient=wx.HORIZONTAL)
|
||||
groupid: int = group.get_id()
|
||||
|
@ -101,12 +107,33 @@ class Hui(wx.Frame):
|
|||
inner_sizer.Add(toggle_btn, 1, wx.EXPAND)
|
||||
self.Bind(wx.EVT_BUTTON,
|
||||
lambda event, mgroupid=groupid: self.toggle_group(mgroupid), toggle_btn)
|
||||
label: str = str(group)
|
||||
label: str = "{}".format(str(group))
|
||||
group_btn: wx.Button = wx.Button(self.pnl, label=label, style=wx.BU_LEFT)
|
||||
inner_sizer.Add(group_btn, 4, wx.EXPAND)
|
||||
self.Bind(wx.EVT_BUTTON,
|
||||
lambda event, mgroupid=groupid: self.goto_group(mgroupid), group_btn)
|
||||
self.sizer.Add(inner_sizer, 0, wx.EXPAND)
|
||||
if has_unattached:
|
||||
self.sizer.Add(unattached_label, 0, wx.EXPAND)
|
||||
for light in self.cur_bridge.unattached_lights:
|
||||
inner_sizer = wx.BoxSizer(orient=wx.HORIZONTAL)
|
||||
lightid: int = light.get_id()
|
||||
icon: str = self.m_off_icon
|
||||
if light.is_on():
|
||||
icon = self.m_on_icon
|
||||
elif not light.is_reachable():
|
||||
icon = self.m_unreachable_icon
|
||||
toggle_btn: wx.Button = wx.Button(self.pnl, label=icon)
|
||||
inner_sizer.Add(toggle_btn, 1, wx.EXPAND)
|
||||
self.Bind(wx.EVT_BUTTON,
|
||||
lambda event, mlightid=lightid: self.toggle_light_and_goto_group(mlightid, lights),
|
||||
toggle_btn)
|
||||
label: str = "{}".format(light)
|
||||
light_btn: wx.Button = wx.Button(self.pnl, label=label, style=wx.BU_LEFT)
|
||||
inner_sizer.Add(light_btn, 4, wx.EXPAND)
|
||||
self.Bind(wx.EVT_BUTTON,
|
||||
lambda event, mlightid=lightid: self.add_single_light(mlightid, True), light_btn)
|
||||
self.sizer.Add(inner_sizer, 0, wx.EXPAND)
|
||||
|
||||
def add_manual_discovery_dialog(self) -> bool:
|
||||
self.sizer.Clear(delete_windows=True)
|
||||
|
@ -164,20 +191,27 @@ class Hui(wx.Frame):
|
|||
self.sizer.Add(inner_sizer, 0, wx.EXPAND)
|
||||
|
||||
@redraw
|
||||
def add_single_light(self, lightid: int):
|
||||
def add_single_light(self, lightid: int, unattached: bool = False):
|
||||
"""Call back for light button
|
||||
|
||||
Args:
|
||||
lightid (int): The light id of the light to display
|
||||
unattached (bool, optional): Is the light unattached to any group?
|
||||
"""
|
||||
light: HueLight = self.cur_bridge.get_light_by_id(lightid)
|
||||
self.SetTitle("Tinge - {}".format(light))
|
||||
is_on: bool = light.is_on()
|
||||
group: HueGroup = self.cur_group
|
||||
group_btn: wx.Button = wx.Button(self.pnl, label=str(group))
|
||||
self.sizer.Add(group_btn, 0, wx.EXPAND)
|
||||
self.Bind(wx.EVT_BUTTON,
|
||||
lambda event: self.goto_group(self.cur_group.get_id()), group_btn)
|
||||
if unattached:
|
||||
group_btn: wx.Button = wx.Button(self.pnl, label=str(self.cur_bridge))
|
||||
self.sizer.Add(group_btn, 0, wx.EXPAND)
|
||||
self.Bind(wx.EVT_BUTTON,
|
||||
lambda event: self.add_groups(self.cur_bridge.get_groups()), group_btn)
|
||||
else:
|
||||
group: HueGroup = self.cur_group
|
||||
group_btn: wx.Button = wx.Button(self.pnl, label=str(group))
|
||||
self.sizer.Add(group_btn, 0, wx.EXPAND)
|
||||
self.Bind(wx.EVT_BUTTON,
|
||||
lambda event: self.goto_group(self.cur_group.get_id()), group_btn)
|
||||
# Toggle
|
||||
icon: str = self.m_off_icon
|
||||
if is_on:
|
||||
|
@ -229,7 +263,7 @@ class Hui(wx.Frame):
|
|||
rename_btn: wx.Button = wx.Button(self.pnl, label="Rename")
|
||||
self.sizer.Add(rename_btn, 0, wx.EXPAND)
|
||||
self.Bind(wx.EVT_BUTTON,
|
||||
lambda event, mlightid=lightid: self.rename_light_and_goto_light(mlightid),
|
||||
lambda event, mlightid=lightid: self.rename_light_and_goto_light(mlightid, unattached),
|
||||
rename_btn)
|
||||
delete_btn: wx.Button = wx.Button(self.pnl, label="Delete")
|
||||
self.sizer.Add(delete_btn, 0, wx.EXPAND)
|
||||
|
@ -324,7 +358,7 @@ class Hui(wx.Frame):
|
|||
self.cur_group = group
|
||||
self.add_lights(group.get_lights())
|
||||
|
||||
def rename_light_and_goto_light(self, lightid):
|
||||
def rename_light_and_goto_light(self, lightid, unattached: bool = False):
|
||||
"""Combo call back to rename a light and display that light again
|
||||
|
||||
Args:
|
||||
|
@ -333,7 +367,7 @@ class Hui(wx.Frame):
|
|||
newname: str = self.get_text_answer_from_modal("Set new name", "New name:")
|
||||
if newname:
|
||||
self.cur_bridge.get_light_by_id(lightid).rename(newname)
|
||||
self.add_single_light(lightid)
|
||||
self.add_single_light(lightid, unattached)
|
||||
|
||||
def set_brightness(self, event: wx.ScrollEvent, lightid: int):
|
||||
"""Call back for brightness slider
|
||||
|
|
|
@ -31,7 +31,15 @@ class HueBridge:
|
|||
self.m_lights: list[HueLight] = self.discover_lights()
|
||||
self.discover_new_lights()
|
||||
self.m_new_lights: list[HueLight] = self.get_new_lights()
|
||||
self.unattached_lights: list[HueLight] = list()
|
||||
self.m_groups: list[HueGroup] = self.discover_groups()
|
||||
for light in self.get_lights():
|
||||
is_in_group: bool = False
|
||||
for group in self.get_groups():
|
||||
if group.is_light_in_group(light.get_id()):
|
||||
is_in_group = True
|
||||
if not is_in_group:
|
||||
self.unattached_lights.append(light)
|
||||
else:
|
||||
self.m_lights: list[HueLight] = list()
|
||||
self.m_new_lights: list[HueLight] = list()
|
||||
|
@ -201,7 +209,8 @@ class HueBridge:
|
|||
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()))
|
||||
newlights.append(
|
||||
HueLight(int(lightid), lightresponse.json(), self.get_ipaddress(), self.get_user()))
|
||||
return newlights
|
||||
|
||||
def get_user(self) -> str:
|
||||
|
@ -224,4 +233,4 @@ class HueBridge:
|
|||
self.m_lights.remove(light)
|
||||
|
||||
def is_reachable(self):
|
||||
return self.m_is_reachable
|
||||
return self.m_is_reachable
|
||||
|
|
|
@ -142,6 +142,13 @@ class HueGroup:
|
|||
on = True
|
||||
return on
|
||||
|
||||
def is_light_in_group(self, lightid: int) -> bool:
|
||||
is_in_group: bool = False
|
||||
for light in self.get_lights():
|
||||
if light.get_id() == lightid:
|
||||
is_in_group = True
|
||||
return is_in_group
|
||||
|
||||
def remove_light(self, light: HueLight):
|
||||
"""Remove a light
|
||||
"""
|
||||
|
|
Loading…
Add table
Reference in a new issue