-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdashboard_lightbulb.py
41 lines (25 loc) · 1.12 KB
/
dashboard_lightbulb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import tkinter as tk
from tkinter import ttk
import logging
import requests
from messaging import ActuatorState
import common
def lightbulb_cmd(state, did):
new_state = state.get()
logging.info(f"Dashboard: {new_state}")
# TODO: START
# send HTTP request with new actuator state to cloud service
# TODO: END
def init_lightbulb(container, did):
lb_lf = ttk.LabelFrame(container, text=f'LightBulb [{did}]')
lb_lf.grid(column=0, row=0, padx=20, pady=20, sticky=tk.W)
# variable used to keep track of lightbulb state
lightbulb_state_var = tk.StringVar(None, 'Off')
on_radio = ttk.Radiobutton(lb_lf, text='On', value='On',
variable=lightbulb_state_var,
command=lambda: lightbulb_cmd(lightbulb_state_var, did))
on_radio.grid(column=0, row=0, ipadx=10, ipady=10)
off_radio = ttk.Radiobutton(lb_lf, text='Off', value='Off',
variable=lightbulb_state_var,
command=lambda: lightbulb_cmd(lightbulb_state_var, did))
off_radio.grid(column=1, row=0, ipadx=10, ipady=10)