Remove bridges; fixes: #6

master
Micke Nordin 3 years ago
parent 6e4f6edbb6
commit cfef9595d7
Signed by: micke
GPG Key ID: 014B273D614BE877

@ -81,6 +81,20 @@ class Hui(wx.Frame):
self.sizer.Add(btn, 0, wx.EXPAND)
self.Bind(wx.EVT_BUTTON, lambda event: self.discover_new_bridges(),
btn)
@redraw
def add_manage_bridge(self):
"""Add bridges to sizer, the entry point of the program
"""
self.SetTitle('Tinge - Manage Bridge')
label = "Delete Bridge"
btn: wx.Button = wx.Button(self.pnl, label=label)
self.sizer.Add(btn, 0, wx.EXPAND)
self.Bind(wx.EVT_BUTTON, lambda event: self.delete_bridge(),
btn)
back_btn: wx.Button = wx.Button(self.pnl, label="Go Back")
self.sizer.Add(back_btn, 0, wx.EXPAND)
self.Bind(wx.EVT_BUTTON, lambda event: self.add_groups(self.cur_bridge.get_groups()),
back_btn)
@redraw
def add_groups(self, groups: list[HueGroup]):
@ -152,6 +166,9 @@ class Hui(wx.Frame):
add_single_light(mlightid, True),
light_btn)
self.sizer.Add(inner_sizer, 0, wx.EXPAND)
bridge_mgm_btn: wx.Button = wx.Button(self.pnl, label="Manage Bridge")
self.sizer.Add(bridge_mgm_btn, 0, wx.EXPAND)
self.Bind(wx.EVT_BUTTON, lambda event: self.manage_bridge(), bridge_mgm_btn)
def add_manual_discovery_dialog(self) -> bool:
self.sizer.Clear(delete_windows=True)
@ -329,6 +346,19 @@ class Hui(wx.Frame):
delete_light_and_goto_group(mlightid),
delete_btn)
def delete_bridge(self):
dlg: wx.MessageDialog = wx.MessageDialog(self.pnl,
"Delete " + self.cur_bridge.m_name + "?",
"Are you sure?",
style=wx.CANCEL | wx.CANCEL_DEFAULT | wx.OK)
dlg.SetOKCancelLabels("&Yes", "&Don't delete")
reply: int = dlg.ShowModal()
if reply == wx.ID_CANCEL:
self.add_groups(self.cur_bridge.get_groups())
else:
self.m_tinge.delete_bridge(self.cur_bridge)
self.add_bridges()
def delete_light_and_goto_group(self, lightid):
"""Combo call back for delete and goto group
@ -426,6 +456,12 @@ class Hui(wx.Frame):
self.cur_group = group
self.add_lights(group.get_lights())
def manage_bridge(self):
"""Call back for manage bridge button
"""
self.add_manage_bridge()
def rename_light_and_goto_light(self, lightid, unattached: bool = False):
"""Combo call back to rename a light and display that light again

@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
setuptools.setup(
name="tinge",
version="0.0.2",
version="0.0.3",
author="Micke Nordin",
author_email="hej@mic.ke",
data_files = [('share/applications', ['data/org.smolnet.tinge.desktop']),('share/icons/hicolor/scalable/apps',['data/org.smolnet.tinge.svg']),],

@ -8,8 +8,7 @@ import toml
from upnpy import UPnP
from .HueBridge import HueBridge
from .HueUtils import connect, is_valid_config, make_request, is_bridge
from .UserOrError import UserOrError
from .HueUtils import is_valid_config, make_request, is_bridge
class Tinge:
@ -25,16 +24,25 @@ class Tinge:
self.create_confdir()
self.read_bridges_from_file()
def append_bridge(self, bridge: HueBridge):
def append_bridge(self, bridge: HueBridge) -> None:
"""Append a bridge to the list
"""
self.m_bridges.append(bridge)
self.m_discovered.append(bridge.get_ipaddress())
def create_confdir(self):
def create_confdir(self) -> None:
"""Create the config dir if it does not allready exist
"""
if not os.path.exists(os.path.dirname(self.m_config)):
os.makedirs(os.path.dirname(self.m_config))
def delete_bridge(self, bridge: HueBridge) -> None:
"""Delete a bridge from the list
"""
self.m_bridges.remove(bridge)
self.m_discovered.remove(bridge.get_ipaddress())
self.write_all_bridges_to_conf()
def discover_new_bridges(self) -> Union[None, list[dict]]:
"""Use UPnP to discover bridges on the current network
"""
@ -76,7 +84,7 @@ class Tinge:
"""
return self.m_bridges
def read_bridges_from_file(self):
def read_bridges_from_file(self) -> None:
"""Read config file and add back previously discovered bridges
"""
if is_valid_config(self.m_config):
@ -95,9 +103,11 @@ class Tinge:
self.m_bridges.append(bridge)
self.m_discovered.append(key)
def write_all_bridges_to_conf(self):
def write_all_bridges_to_conf(self) -> None:
"""Save to file
"""
with open(self.m_config, 'w') as configfile:
for bridge in self.m_bridges:
configfile.write('["{}"]\nuser = "{}"\n'.format(bridge.get_ipaddress(), bridge.get_user()))
if len(self.m_bridges) == 0:
configfile.truncate()

Loading…
Cancel
Save