This commit fixes #19 and #2

All long labels have been removed as the bridge list interface and
discovery interface was reworked. Discovery of new lights happens
automatically and bridges are refereshed when changes happen.
master
Micke Nordin 4 years ago
parent 43657440a3
commit 816f9e6dab
Signed by: micke
GPG Key ID: 014B273D614BE877

@ -55,25 +55,25 @@ class Hui(wx.Frame):
"""Add bridges to sizer, the entry point of the program """Add bridges to sizer, the entry point of the program
""" """
self.SetTitle('Tinge - All Bridges') self.SetTitle('Tinge - All Bridges')
one_unreachable: bool = False all_unreachable: bool = True
no_bridges: bool = True no_bridges: bool = True
if self.m_tinge.get_bridges(): if self.m_tinge.get_bridges():
no_bridges = False no_bridges = False
for bridge in self.m_tinge.get_bridges(): for bridge in self.m_tinge.get_bridges():
if bridge.is_reachable(): if bridge.is_reachable():
bridge.refresh_bridge()
all_unreachable = False
btn: wx.Button = wx.Button(self.pnl, label=str(bridge)) btn: wx.Button = wx.Button(self.pnl, label=str(bridge))
self.sizer.Add(btn, 0, wx.EXPAND) self.sizer.Add(btn, 0, wx.EXPAND)
self.Bind(wx.EVT_BUTTON, self.Bind(wx.EVT_BUTTON,
lambda event, mbridge=bridge: self.goto_bridge(mbridge), btn) lambda event, mbridge=bridge: self.goto_bridge(mbridge), btn)
else: else:
one_unreachable = True label = "{} {} ({})".format(self.m_unreachable_icon, str(bridge), "unreachable")
btn: wx.Button = wx.Button(self.pnl, label=label)
if one_unreachable or no_bridges: self.sizer.Add(btn, 0, wx.EXPAND)
if one_unreachable:
warn_label = "{} At least one previously discovered bridge unreachable.".format(self.m_unreachable_icon) if no_bridges or all_unreachable:
warning: wx.StaticText = wx.StaticText(self.pnl, label=warn_label, style=wx.ALIGN_CENTER) label = "Discover bridge"
self.sizer.Add(warning, 0, wx.EXPAND)
label = "Press Hue Bridge button, and then here within 30 seconds to connect"
btn: wx.Button = wx.Button(self.pnl, label=label) btn: wx.Button = wx.Button(self.pnl, label=label)
self.sizer.Add(btn, 0, wx.EXPAND) self.sizer.Add(btn, 0, wx.EXPAND)
self.Bind(wx.EVT_BUTTON, self.Bind(wx.EVT_BUTTON,
@ -113,7 +113,8 @@ class Hui(wx.Frame):
lambda event, mgroupid=groupid: self.goto_group(mgroupid), group_btn) lambda event, mgroupid=groupid: self.goto_group(mgroupid), group_btn)
self.sizer.Add(inner_sizer, 0, wx.EXPAND) self.sizer.Add(inner_sizer, 0, wx.EXPAND)
if has_unattached: if has_unattached:
unattached_label: wx.StaticText = wx.StaticText(self.pnl, label=" ⚬ Unattached lights ⚬ ", style=wx.ALIGN_CENTER) unattached_label: wx.StaticText = wx.StaticText(self.pnl, label=" ⚬ Unattached lights ⚬ ",
style=wx.ALIGN_CENTER)
self.sizer.Add(unattached_label, 0, wx.EXPAND) self.sizer.Add(unattached_label, 0, wx.EXPAND)
for light in self.cur_bridge.unattached_lights: for light in self.cur_bridge.unattached_lights:
inner_sizer = wx.BoxSizer(orient=wx.HORIZONTAL) inner_sizer = wx.BoxSizer(orient=wx.HORIZONTAL)

@ -23,16 +23,24 @@ class HueBridge:
self.m_ipaddress: str = ipaddress self.m_ipaddress: str = ipaddress
self.m_username: str = username self.m_username: str = username
self.m_is_reachable = is_reachable self.m_is_reachable = is_reachable
self.unattached_lights: list[HueLight] = list()
if name: if name:
self.m_name: str = name self.m_name: str = name
else: else:
self.m_name = self.m_ipaddress self.m_name = self.m_ipaddress
if is_reachable: if is_reachable:
self.refresh_bridge()
else:
self.m_lights: list[HueLight] = list()
self.m_new_lights: list[HueLight] = list()
self.m_groups: list[HueGroup] = list()
def refresh_bridge(self):
self.m_lights: list[HueLight] = self.discover_lights() self.m_lights: list[HueLight] = self.discover_lights()
self.discover_new_lights() self.discover_new_lights()
self.m_new_lights: list[HueLight] = self.get_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() self.m_groups: list[HueGroup] = self.discover_groups()
self.unattached_lights: list[HueLight] = list()
for light in self.get_lights(): for light in self.get_lights():
is_in_group: bool = False is_in_group: bool = False
for group in self.get_groups(): for group in self.get_groups():
@ -40,10 +48,6 @@ class HueBridge:
is_in_group = True is_in_group = True
if not is_in_group: if not is_in_group:
self.unattached_lights.append(light) self.unattached_lights.append(light)
else:
self.m_lights: list[HueLight] = list()
self.m_new_lights: list[HueLight] = list()
self.m_groups: list[HueGroup] = list()
def __str__(self) -> str: def __str__(self) -> str:
"""The string representation of this bridge """The string representation of this bridge

Loading…
Cancel
Save