More stuff

This commit is contained in:
Micke Nordin 2023-11-19 14:55:17 +01:00
parent 25a2d75ae3
commit 9d3856f91b
3 changed files with 24 additions and 15 deletions

38
main.py
View file

@ -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

0
src/__init__.py Normal file
View file

View file

@ -48,6 +48,7 @@ class Tinge:
""" """
upnp: UPnP = UPnP() upnp: UPnP = UPnP()
discovered_devices = list() discovered_devices = list()
print("Discovering new bridges")
try: try:
discovered_devices = upnp.discover() discovered_devices = upnp.discover()
except http.client.BadStatusLine: except http.client.BadStatusLine: