Browse Source

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.
tags/0.0.1
Micke Nordin 4 months ago
parent
commit
816f9e6dab
Signed by: Micke Nordin <hej@mic.ke> GPG Key ID: 014B273D614BE877
2 changed files with 27 additions and 22 deletions
  1. 11
    10
      main.py
  2. 16
    12
      tinge/HueBridge/__init__.py

+ 11
- 10
main.py View File

@@ -55,25 +55,25 @@ class Hui(wx.Frame):
55 55
         """Add bridges to sizer, the entry point of the program
56 56
         """
57 57
         self.SetTitle('Tinge - All Bridges')
58
-        one_unreachable: bool = False
58
+        all_unreachable: bool = True
59 59
         no_bridges: bool = True
60 60
         if self.m_tinge.get_bridges():
61 61
             no_bridges = False
62 62
             for bridge in self.m_tinge.get_bridges():
63 63
                 if bridge.is_reachable():
64
+                    bridge.refresh_bridge()
65
+                    all_unreachable = False
64 66
                     btn: wx.Button = wx.Button(self.pnl, label=str(bridge))
65 67
                     self.sizer.Add(btn, 0, wx.EXPAND)
66 68
                     self.Bind(wx.EVT_BUTTON,
67 69
                               lambda event, mbridge=bridge: self.goto_bridge(mbridge), btn)
68 70
                 else:
69
-                    one_unreachable = True
70
-
71
-        if one_unreachable or no_bridges:
72
-            if one_unreachable:
73
-                warn_label = "{} At least one previously discovered bridge unreachable.".format(self.m_unreachable_icon)
74
-                warning: wx.StaticText = wx.StaticText(self.pnl, label=warn_label, style=wx.ALIGN_CENTER)
75
-                self.sizer.Add(warning, 0, wx.EXPAND)
76
-            label = "Press Hue Bridge button, and then here within 30 seconds to connect"
71
+                    label = "{} {} ({})".format(self.m_unreachable_icon, str(bridge), "unreachable")
72
+                    btn: wx.Button = wx.Button(self.pnl, label=label)
73
+                    self.sizer.Add(btn, 0, wx.EXPAND)
74
+
75
+        if no_bridges or all_unreachable:
76
+            label = "Discover bridge"
77 77
             btn: wx.Button = wx.Button(self.pnl, label=label)
78 78
             self.sizer.Add(btn, 0, wx.EXPAND)
79 79
             self.Bind(wx.EVT_BUTTON,
@@ -113,7 +113,8 @@ class Hui(wx.Frame):
113 113
                       lambda event, mgroupid=groupid: self.goto_group(mgroupid), group_btn)
114 114
             self.sizer.Add(inner_sizer, 0, wx.EXPAND)
115 115
         if has_unattached:
116
-            unattached_label: wx.StaticText = wx.StaticText(self.pnl, label=" ⚬ Unattached lights ⚬ ", style=wx.ALIGN_CENTER)
116
+            unattached_label: wx.StaticText = wx.StaticText(self.pnl, label=" ⚬ Unattached lights ⚬ ",
117
+                                                            style=wx.ALIGN_CENTER)
117 118
             self.sizer.Add(unattached_label, 0, wx.EXPAND)
118 119
             for light in self.cur_bridge.unattached_lights:
119 120
                 inner_sizer = wx.BoxSizer(orient=wx.HORIZONTAL)

+ 16
- 12
tinge/HueBridge/__init__.py View File

@@ -23,28 +23,32 @@ class HueBridge:
23 23
         self.m_ipaddress: str = ipaddress
24 24
         self.m_username: str = username
25 25
         self.m_is_reachable = is_reachable
26
+        self.unattached_lights: list[HueLight] = list()
26 27
         if name:
27 28
             self.m_name: str = name
28 29
         else:
29 30
             self.m_name = self.m_ipaddress
30 31
         if is_reachable:
31
-            self.m_lights: list[HueLight] = self.discover_lights()
32
-            self.discover_new_lights()
33
-            self.m_new_lights: list[HueLight] = self.get_new_lights()
34
-            self.unattached_lights: list[HueLight] = list()
35
-            self.m_groups: list[HueGroup] = self.discover_groups()
36
-            for light in self.get_lights():
37
-                is_in_group: bool = False
38
-                for group in self.get_groups():
39
-                    if group.is_light_in_group(light.get_id()):
40
-                        is_in_group = True
41
-                if not is_in_group:
42
-                    self.unattached_lights.append(light)
32
+            self.refresh_bridge()
43 33
         else:
44 34
             self.m_lights: list[HueLight] = list()
45 35
             self.m_new_lights: list[HueLight] = list()
46 36
             self.m_groups: list[HueGroup] = list()
47 37
 
38
+    def refresh_bridge(self):
39
+        self.m_lights: list[HueLight] = self.discover_lights()
40
+        self.discover_new_lights()
41
+        self.m_new_lights: list[HueLight] = self.get_new_lights()
42
+        self.m_groups: list[HueGroup] = self.discover_groups()
43
+        self.unattached_lights: list[HueLight] = list()
44
+        for light in self.get_lights():
45
+            is_in_group: bool = False
46
+            for group in self.get_groups():
47
+                if group.is_light_in_group(light.get_id()):
48
+                    is_in_group = True
49
+            if not is_in_group:
50
+                self.unattached_lights.append(light)
51
+
48 52
     def __str__(self) -> str:
49 53
         """The string representation of this bridge
50 54
 

Loading…
Cancel
Save