|
|
@ -1,13 +1,15 @@
|
|
|
|
|
|
|
|
from logging import disable
|
|
|
|
import kivy
|
|
|
|
import kivy
|
|
|
|
|
|
|
|
|
|
|
|
kivy.require('2.2.1')
|
|
|
|
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.button import Button
|
|
|
|
from kivy.uix.button import Button, ColorProperty
|
|
|
|
|
|
|
|
from kivy.uix.label import Label
|
|
|
|
from kivy.uix.screenmanager import Screen, ScreenManager
|
|
|
|
from kivy.uix.screenmanager import Screen, ScreenManager
|
|
|
|
|
|
|
|
|
|
|
|
from tinge import HueBridge, Tinge
|
|
|
|
from src.tinge import HueBridge, Tinge
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HueApp(App):
|
|
|
|
class HueApp(App):
|
|
|
@ -27,29 +29,35 @@ class BridgeScreen(Screen):
|
|
|
|
def __init__(self, tinge, **kwargs):
|
|
|
|
def __init__(self, tinge, **kwargs):
|
|
|
|
super(BridgeScreen, self).__init__(**kwargs)
|
|
|
|
super(BridgeScreen, self).__init__(**kwargs)
|
|
|
|
self.tinge = tinge
|
|
|
|
self.tinge = tinge
|
|
|
|
for bridge_button in self.get_bridge_buttons():
|
|
|
|
for bridge_button in self.set_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, button):
|
|
|
|
print(bridge.get_ipaddress())
|
|
|
|
print(bridge.get_ipaddress())
|
|
|
|
|
|
|
|
|
|
|
|
def manually_add(self, button):
|
|
|
|
def manually_add(self, button):
|
|
|
|
print('hello')
|
|
|
|
bridges = self.tinge.discover_new_bridges()
|
|
|
|
|
|
|
|
|
|
|
|
def get_bridge_buttons(self):
|
|
|
|
|
|
|
|
bridges = self.tinge.discover_new_bridges()
|
|
|
|
|
|
|
|
buttons = []
|
|
|
|
|
|
|
|
if bridges:
|
|
|
|
if bridges:
|
|
|
|
for bridge in bridges:
|
|
|
|
for bridge in bridges:
|
|
|
|
bridge_button = Button(
|
|
|
|
if not bridge in self.tinge.get_bridges():
|
|
|
|
text=str(bridge.get_ipaddress()),
|
|
|
|
self.tinge.append_bridge(bridge)
|
|
|
|
on_press=lambda button: self.press_button(bridge, button))
|
|
|
|
|
|
|
|
buttons.append(bridge_button)
|
|
|
|
def set_bridge_buttons(self):
|
|
|
|
else:
|
|
|
|
buttons = []
|
|
|
|
|
|
|
|
bridges = self.tinge.get_bridges()
|
|
|
|
|
|
|
|
for bridge in bridges:
|
|
|
|
bridge_button = Button(
|
|
|
|
bridge_button = Button(
|
|
|
|
text='Manually add bridge',
|
|
|
|
text=str(bridge.get_ipaddress()),
|
|
|
|
on_press=lambda button: self.manually_add(button))
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
|
|
|
|
on_press=lambda button: self.press_button(bridge, button))
|
|
|
|
buttons.append(bridge_button)
|
|
|
|
buttons.append(bridge_button)
|
|
|
|
|
|
|
|
bridge_button = Button(
|
|
|
|
|
|
|
|
text='Discover Bridges',
|
|
|
|
|
|
|
|
size_hint=(1, 0.1),
|
|
|
|
|
|
|
|
on_press=lambda button: self.manually_add(button))
|
|
|
|
|
|
|
|
buttons.append(bridge_button)
|
|
|
|
|
|
|
|
sizer = Label(disabled = True)
|
|
|
|
|
|
|
|
buttons.append(sizer)
|
|
|
|
return buttons
|
|
|
|
return buttons
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|