|
|
@ -6,13 +6,13 @@ kivy.require('2.2.1')
|
|
|
|
|
|
|
|
|
|
|
|
from kivy.app import App
|
|
|
|
from kivy.app import App
|
|
|
|
from kivy.uix.boxlayout import BoxLayout
|
|
|
|
from kivy.uix.boxlayout import BoxLayout
|
|
|
|
from kivy.uix.stacklayout import StackLayout
|
|
|
|
|
|
|
|
from kivy.uix.button import Button
|
|
|
|
from kivy.uix.button import Button
|
|
|
|
from kivy.uix.label import Label
|
|
|
|
from kivy.uix.label import Label
|
|
|
|
from kivy.uix.popup import Popup
|
|
|
|
from kivy.uix.popup import Popup
|
|
|
|
from kivy.uix.screenmanager import Screen, ScreenManager
|
|
|
|
from kivy.uix.screenmanager import Screen, ScreenManager
|
|
|
|
|
|
|
|
from kivy.uix.stacklayout import StackLayout
|
|
|
|
|
|
|
|
|
|
|
|
from src.tinge import HueBridge, HueUtils, Tinge
|
|
|
|
from src.tinge import HueBridge, HueGroup, HueUtils, Tinge
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HueApp(App):
|
|
|
|
class HueApp(App):
|
|
|
@ -25,6 +25,40 @@ class HueApp(App):
|
|
|
|
return sm
|
|
|
|
return sm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GroupScreen(Screen):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, sm, tinge, id: int, bridge: HueBridge, **kwargs):
|
|
|
|
|
|
|
|
super(GroupScreen, self).__init__(**kwargs)
|
|
|
|
|
|
|
|
self.sm = sm
|
|
|
|
|
|
|
|
self.tinge = tinge
|
|
|
|
|
|
|
|
self.id = id
|
|
|
|
|
|
|
|
self.group = bridge.get_group_by_id(id)
|
|
|
|
|
|
|
|
self.bridge = bridge
|
|
|
|
|
|
|
|
self.layout = StackLayout()
|
|
|
|
|
|
|
|
self.add_widget(self.layout)
|
|
|
|
|
|
|
|
for button in self.get_light_buttons():
|
|
|
|
|
|
|
|
self.layout.add_widget(button)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_light_buttons(self):
|
|
|
|
|
|
|
|
buttons = []
|
|
|
|
|
|
|
|
for light in self.group.get_lights():
|
|
|
|
|
|
|
|
button = Button(text=str(light),
|
|
|
|
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
|
|
|
|
on_press=lambda _: self.press_button(light))
|
|
|
|
|
|
|
|
buttons.append(button)
|
|
|
|
|
|
|
|
backbutton = Button(text="Back",
|
|
|
|
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
|
|
|
|
on_press=lambda _: self.press_back_button())
|
|
|
|
|
|
|
|
buttons.append(backbutton)
|
|
|
|
|
|
|
|
return buttons
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def press_back_button(self):
|
|
|
|
|
|
|
|
self.sm.current = "bridge_" + str(self.bridge.id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def press_button(self, light):
|
|
|
|
|
|
|
|
print(button, light)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SingleBridgeScreen(Screen):
|
|
|
|
class SingleBridgeScreen(Screen):
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, sm, tinge, bridge: HueBridge, **kwargs):
|
|
|
|
def __init__(self, sm, tinge, bridge: HueBridge, **kwargs):
|
|
|
@ -34,26 +68,33 @@ class SingleBridgeScreen(Screen):
|
|
|
|
self.bridge = bridge
|
|
|
|
self.bridge = bridge
|
|
|
|
self.layout = StackLayout()
|
|
|
|
self.layout = StackLayout()
|
|
|
|
self.add_widget(self.layout)
|
|
|
|
self.add_widget(self.layout)
|
|
|
|
self.set_group_buttons()
|
|
|
|
self.groups = []
|
|
|
|
|
|
|
|
|
|
|
|
def set_group_buttons(self):
|
|
|
|
|
|
|
|
for group in self.bridge.get_groups():
|
|
|
|
for group in self.bridge.get_groups():
|
|
|
|
button = Button(
|
|
|
|
self.layout.add_widget(self.get_group_button(group))
|
|
|
|
text=str(group),
|
|
|
|
self.layout.add_widget(
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
Button(text="Back",
|
|
|
|
on_press=lambda button: self.press_button(button, group))
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
self.layout.add_widget(button)
|
|
|
|
on_press=lambda _: self.press_back_button()))
|
|
|
|
backbutton = Button(
|
|
|
|
|
|
|
|
text="Back",
|
|
|
|
def get_group_button(self, group):
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
button = Button(text=str(group), size_hint=(1, 0.1))
|
|
|
|
on_press=lambda button: self.press_back_button(button, "back"))
|
|
|
|
button.bind(on_press=lambda _: self.press_button(group.get_id()))
|
|
|
|
self.layout.add_widget(backbutton)
|
|
|
|
return button
|
|
|
|
|
|
|
|
|
|
|
|
def press_back_button(self, button, group):
|
|
|
|
def press_back_button(self):
|
|
|
|
self.sm.current = "bridge_screen"
|
|
|
|
self.sm.current = "bridge_screen"
|
|
|
|
|
|
|
|
|
|
|
|
def press_button(self, light, button):
|
|
|
|
def press_button(self, group: int):
|
|
|
|
print(light)
|
|
|
|
print(group)
|
|
|
|
|
|
|
|
group_name: str = 'group_' + str(group)
|
|
|
|
|
|
|
|
group_screen = GroupScreen(self.sm,
|
|
|
|
|
|
|
|
self.tinge,
|
|
|
|
|
|
|
|
group,
|
|
|
|
|
|
|
|
self.bridge,
|
|
|
|
|
|
|
|
name=group_name)
|
|
|
|
|
|
|
|
if not self.sm.has_screen(group_name):
|
|
|
|
|
|
|
|
self.sm.add_widget(group_screen)
|
|
|
|
|
|
|
|
self.sm.current = group_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BridgeScreen(Screen):
|
|
|
|
class BridgeScreen(Screen):
|
|
|
@ -64,18 +105,20 @@ class BridgeScreen(Screen):
|
|
|
|
super(BridgeScreen, self).__init__(**kwargs)
|
|
|
|
super(BridgeScreen, self).__init__(**kwargs)
|
|
|
|
self.sm = sm
|
|
|
|
self.sm = sm
|
|
|
|
self.tinge = tinge
|
|
|
|
self.tinge = tinge
|
|
|
|
for bridge_button in self.set_bridge_buttons():
|
|
|
|
for bridge_button in self.get_bridge_buttons():
|
|
|
|
self.layout.add_widget(bridge_button)
|
|
|
|
self.layout.add_widget(bridge_button)
|
|
|
|
|
|
|
|
|
|
|
|
def press_button(self, bridge, button):
|
|
|
|
def press_button(self, bridge):
|
|
|
|
self.sm.add_widget(
|
|
|
|
bridge_name = "bridge_" + str(bridge.id)
|
|
|
|
SingleBridgeScreen(self.sm,
|
|
|
|
if not self.sm.has_screen(bridge_name):
|
|
|
|
self.tinge,
|
|
|
|
self.sm.add_widget(
|
|
|
|
bridge,
|
|
|
|
SingleBridgeScreen(self.sm,
|
|
|
|
name='single_bridge'))
|
|
|
|
self.tinge,
|
|
|
|
self.sm.current = 'single_bridge'
|
|
|
|
bridge,
|
|
|
|
|
|
|
|
name=bridge_name))
|
|
|
|
def discover_bridge(self, button):
|
|
|
|
self.sm.current = bridge_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def discover_bridge(self):
|
|
|
|
bridges = self.tinge.discover_new_bridges()
|
|
|
|
bridges = self.tinge.discover_new_bridges()
|
|
|
|
if bridges:
|
|
|
|
if bridges:
|
|
|
|
for bridge in bridges:
|
|
|
|
for bridge in bridges:
|
|
|
@ -88,33 +131,34 @@ class BridgeScreen(Screen):
|
|
|
|
new_bridge_button = Button(
|
|
|
|
new_bridge_button = Button(
|
|
|
|
text='Press button on Bridge',
|
|
|
|
text='Press button on Bridge',
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
on_press=lambda button: self.wait_for_button_press(
|
|
|
|
on_press=lambda _: self.wait_for_button_press(
|
|
|
|
button, popup, bridge['ipaddress']))
|
|
|
|
popup, bridge['ipaddress']))
|
|
|
|
popup.add_widget(new_bridge_button)
|
|
|
|
popup.add_widget(new_bridge_button)
|
|
|
|
popup.open()
|
|
|
|
popup.open()
|
|
|
|
|
|
|
|
|
|
|
|
def wait_for_button_press(self, button, popup, ipaddress):
|
|
|
|
def wait_for_button_press(self, popup, ipaddress):
|
|
|
|
|
|
|
|
bridge_id = len(self.tinge.get_bridges())
|
|
|
|
user_or_error = HueUtils.connect(ipaddress)
|
|
|
|
user_or_error = HueUtils.connect(ipaddress)
|
|
|
|
while user_or_error.is_error():
|
|
|
|
while user_or_error.is_error():
|
|
|
|
user_or_error = HueUtils.connect(ipaddress)
|
|
|
|
user_or_error = HueUtils.connect(ipaddress)
|
|
|
|
self.tinge.append_bridge(
|
|
|
|
self.tinge.append_bridge(
|
|
|
|
HueBridge(ipaddress, user_or_error.get_user(), ipaddress))
|
|
|
|
HueBridge(bridge_id, ipaddress, user_or_error.get_user(),
|
|
|
|
|
|
|
|
ipaddress))
|
|
|
|
self.tinge.write_all_bridges_to_conf()
|
|
|
|
self.tinge.write_all_bridges_to_conf()
|
|
|
|
popup.dismiss()
|
|
|
|
popup.dismiss()
|
|
|
|
|
|
|
|
|
|
|
|
def set_bridge_buttons(self):
|
|
|
|
def get_bridge_buttons(self):
|
|
|
|
buttons = []
|
|
|
|
buttons = []
|
|
|
|
bridges = self.tinge.get_bridges()
|
|
|
|
bridges = self.tinge.get_bridges()
|
|
|
|
for bridge in bridges:
|
|
|
|
for bridge in bridges:
|
|
|
|
bridge_button = Button(
|
|
|
|
bridge_button = Button(
|
|
|
|
text=str(bridge.get_ipaddress()),
|
|
|
|
text=str(bridge.get_ipaddress()),
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
on_press=lambda button: self.press_button(bridge, button))
|
|
|
|
on_press=lambda _: self.press_button(bridge))
|
|
|
|
buttons.append(bridge_button)
|
|
|
|
buttons.append(bridge_button)
|
|
|
|
bridge_button = Button(
|
|
|
|
bridge_button = Button(text='Discover Bridges',
|
|
|
|
text='Discover Bridges',
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
on_press=lambda _: self.discover_bridge())
|
|
|
|
on_press=lambda button: self.discover_bridge(button))
|
|
|
|
|
|
|
|
buttons.append(bridge_button)
|
|
|
|
buttons.append(bridge_button)
|
|
|
|
sizer = Label(disabled=True)
|
|
|
|
sizer = Label(disabled=True)
|
|
|
|
buttons.append(sizer)
|
|
|
|
buttons.append(sizer)
|
|
|
|