Add hue and saturation sliders and make API consistent so that it return -1 for default values
This commit is contained in:
parent
d78be65a06
commit
ba4554812c
2 changed files with 145 additions and 28 deletions
75
main.py
75
main.py
|
@ -103,7 +103,7 @@ class Hui(wx.Frame):
|
|||
Args:
|
||||
lights (list[HueLight]): The lights to display
|
||||
"""
|
||||
self.SetTitle("Tinge - {}". format(self.cur_group))
|
||||
self.SetTitle("Tinge - {}".format(self.cur_group))
|
||||
group_btn: wx.Button = wx.Button(self.pnl, label=str(self.cur_bridge))
|
||||
self.sizer.Add(group_btn, 0, wx.EXPAND)
|
||||
self.Bind(wx.EVT_BUTTON,
|
||||
|
@ -200,22 +200,41 @@ class Hui(wx.Frame):
|
|||
toggle_btn)
|
||||
|
||||
# Slider for brightness
|
||||
if is_on and light.get_brightness() > 0:
|
||||
b_label: wx.StaticText = wx.StaticText(self.pnl, label="Brightness")
|
||||
self.sizer.Add(b_label, 0, wx.EXPAND)
|
||||
b_slider: wx.Slider = wx.Slider(self.pnl, value=light.get_state().get_brightness(), minValue=1,
|
||||
maxValue=254)
|
||||
self.sizer.Add(b_slider, 0, wx.EXPAND)
|
||||
self.Bind(wx.EVT_SCROLL,
|
||||
lambda event: self.set_brightness(event, light.get_id()), b_slider)
|
||||
# Slider for colortemp
|
||||
if is_on and light.can_set_ct():
|
||||
c_label: wx.StaticText = wx.StaticText(self.pnl, label="Color Temperature")
|
||||
self.sizer.Add(c_label, 0, wx.EXPAND)
|
||||
c_slider: wx.Slider = wx.Slider(self.pnl, value=light.get_ct(), minValue=153, maxValue=500)
|
||||
self.sizer.Add(c_slider, 0, wx.EXPAND)
|
||||
self.Bind(wx.EVT_SCROLL,
|
||||
lambda event: self.set_colortemp(event, light.get_id()), c_slider)
|
||||
if is_on:
|
||||
if light.get_brightness() > 0:
|
||||
b_label: wx.StaticText = wx.StaticText(self.pnl, label="Brightness")
|
||||
self.sizer.Add(b_label, 0, wx.EXPAND)
|
||||
b_slider: wx.Slider = wx.Slider(self.pnl, value=light.get_state().get_brightness(), minValue=1,
|
||||
maxValue=254)
|
||||
self.sizer.Add(b_slider, 0, wx.EXPAND)
|
||||
self.Bind(wx.EVT_SCROLL,
|
||||
lambda event: self.set_brightness(event, light.get_id()), b_slider)
|
||||
# Slider for colortemp
|
||||
if light.can_set_ct():
|
||||
c_label: wx.StaticText = wx.StaticText(self.pnl, label="Color Temperature")
|
||||
self.sizer.Add(c_label, 0, wx.EXPAND)
|
||||
c_slider: wx.Slider = wx.Slider(self.pnl, value=light.get_ct(), minValue=153, maxValue=500)
|
||||
self.sizer.Add(c_slider, 0, wx.EXPAND)
|
||||
self.Bind(wx.EVT_SCROLL,
|
||||
lambda event: self.set_colortemp(event, light.get_id()), c_slider)
|
||||
|
||||
# Slider for hue
|
||||
if light.can_set_hue():
|
||||
d_label: wx.StaticText = wx.StaticText(self.pnl, label="Hue")
|
||||
self.sizer.Add(d_label, 0, wx.EXPAND)
|
||||
d_slider: wx.Slider = wx.Slider(self.pnl, value=light.get_hue(), minValue=0, maxValue=65535)
|
||||
self.sizer.Add(d_slider, 0, wx.EXPAND)
|
||||
self.Bind(wx.EVT_SCROLL,
|
||||
lambda event: self.set_hue(event, light.get_id()), d_slider)
|
||||
|
||||
# Slider for saturation
|
||||
if light.can_set_sat():
|
||||
e_label: wx.StaticText = wx.StaticText(self.pnl, label="Saturation")
|
||||
self.sizer.Add(e_label, 0, wx.EXPAND)
|
||||
e_slider: wx.Slider = wx.Slider(self.pnl, value=light.get_sat(), minValue=0, maxValue=254)
|
||||
self.sizer.Add(e_slider, 0, wx.EXPAND)
|
||||
self.Bind(wx.EVT_SCROLL,
|
||||
lambda event: self.set_saturation(event, light.get_id()), e_slider)
|
||||
|
||||
def set_brightness(self, event: wx.ScrollEvent, lightid: int):
|
||||
"""Call back for brightness slider
|
||||
|
@ -248,6 +267,28 @@ class Hui(wx.Frame):
|
|||
light: HueLight = self.cur_bridge.get_light_by_id(lightid)
|
||||
light.set_ct(ct)
|
||||
|
||||
def set_hue(self, event, lightid):
|
||||
"""Call back for colortemp slider
|
||||
|
||||
Args:
|
||||
event (wx.ScrollEvent): The scroll event to react to
|
||||
lightid (int): The light id of the light to adjust hue of
|
||||
"""
|
||||
hue: int = event.GetPosition()
|
||||
light: HueLight = self.cur_bridge.get_light_by_id(lightid)
|
||||
light.set_hue(hue)
|
||||
|
||||
def set_saturation(self, event, lightid):
|
||||
"""Call back for colortemp slider
|
||||
|
||||
Args:
|
||||
event (wx.ScrollEvent): The scroll event to react to
|
||||
lightid (int): The light id of the light to adjust hue of
|
||||
"""
|
||||
sat: int = event.GetPosition()
|
||||
light: HueLight = self.cur_bridge.get_light_by_id(lightid)
|
||||
light.set_hue(sat)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = wx.App()
|
||||
|
|
|
@ -27,11 +27,19 @@ class HueLight:
|
|||
if 'bri' in keys:
|
||||
self.m_bri: int = data_slice['bri']
|
||||
else:
|
||||
self.m_bri: int = 0
|
||||
self.m_bri: int = -1
|
||||
if 'ct' in keys:
|
||||
self.m_ct: int = data_slice['ct']
|
||||
else:
|
||||
self.m_ct: int = 0
|
||||
self.m_ct: int = -1
|
||||
if 'hue' in keys:
|
||||
self.m_hue: int = data_slice['hue']
|
||||
else:
|
||||
self.m_hue: int = -1
|
||||
if 'sat' in keys:
|
||||
self.m_sat: int = data_slice['sat']
|
||||
else:
|
||||
self.m_sat: int = -1
|
||||
self.m_alert: str = data_slice['alert']
|
||||
if 'colormode' in keys:
|
||||
self.m_colormode: str = data_slice['colormode']
|
||||
|
@ -44,7 +52,7 @@ class HueLight:
|
|||
"""Get current brightness of the light
|
||||
|
||||
Returns:
|
||||
int: 0-254
|
||||
int: -1-254
|
||||
"""
|
||||
return self.m_bri
|
||||
|
||||
|
@ -52,10 +60,26 @@ class HueLight:
|
|||
"""Get current color temp of the light
|
||||
|
||||
Returns:
|
||||
int: 0, 153-500, 0 means it cant do color temp
|
||||
int: -1, 153-500, -1 means it cant do color temp
|
||||
"""
|
||||
return self.m_ct
|
||||
|
||||
def get_hue(self) -> int:
|
||||
"""Get current hue of the light
|
||||
|
||||
Returns:
|
||||
int: -1-65535
|
||||
"""
|
||||
return self.m_hue
|
||||
|
||||
def get_sat(self):
|
||||
"""Get current saturation of the light
|
||||
|
||||
Returns:
|
||||
int: -1-254
|
||||
"""
|
||||
return self.m_hue
|
||||
|
||||
def is_on(self) -> bool:
|
||||
"""Is this thing on?
|
||||
|
||||
|
@ -107,17 +131,17 @@ class HueLight:
|
|||
if 'min' in keys:
|
||||
self.m_min: int = data_slice['min']
|
||||
else:
|
||||
self.m_min: int = 0
|
||||
self.m_min: int = -1
|
||||
if 'max' in keys:
|
||||
self.m_max: int = data_slice['max']
|
||||
else:
|
||||
self.m_max: int = 0
|
||||
self.m_max: int = -1
|
||||
|
||||
def get_max(self) -> int:
|
||||
"""Get the max colortemp of this light
|
||||
|
||||
Returns:
|
||||
int: Max colortemp of this light, 0 means you can't change colortemp
|
||||
int: Max colortemp of this light, -1 means you can't change colortemp
|
||||
"""
|
||||
return self.m_max
|
||||
|
||||
|
@ -131,11 +155,11 @@ class HueLight:
|
|||
if 'mindimlevel' in keys:
|
||||
self.m_mindimlevel: int = data_slice['mindimlevel']
|
||||
else:
|
||||
self.m_mindimlevel: int = 0
|
||||
self.m_mindimlevel: int = -1
|
||||
if 'maxlumen' in keys:
|
||||
self.m_maxlumen: int = data_slice['maxlumen']
|
||||
else:
|
||||
self.m_maxlumen: int = 0
|
||||
self.m_maxlumen: int = -1
|
||||
if 'ct' in data_slice.keys():
|
||||
self.m_ct = HueLight.Capabilites.Control.ColorTemp(data_slice['ct'])
|
||||
else:
|
||||
|
@ -246,7 +270,23 @@ class HueLight:
|
|||
Returns:
|
||||
bool: True if we can, otherwise False
|
||||
"""
|
||||
return self.get_ct() > 0
|
||||
return self.get_ct() > -1
|
||||
|
||||
def can_set_hue(self) -> bool:
|
||||
"""Check if we can set hue for this light
|
||||
|
||||
Returns:
|
||||
bool: True if we can, otherwise False
|
||||
"""
|
||||
return self.get_hue() != -1
|
||||
|
||||
def can_set_sat(self) -> bool:
|
||||
"""Check if we can set saturation for this light
|
||||
|
||||
Returns:
|
||||
bool: True if we can, otherwise False
|
||||
"""
|
||||
return self.get_sat() != -1
|
||||
|
||||
def get_state(self):
|
||||
"""Get the state object for this light
|
||||
|
@ -315,6 +355,26 @@ class HueLight:
|
|||
state = '{{"ct":{0}}}'.format(colortemp)
|
||||
self.set_state(state)
|
||||
|
||||
def set_hue(self, hue: int):
|
||||
"""Set the hue of the light, if possible
|
||||
|
||||
Args:
|
||||
hue (int): 0-65535
|
||||
"""
|
||||
if self.can_set_hue():
|
||||
state = '{{"hue":{0}}}'.format(hue)
|
||||
self.set_state(state)
|
||||
|
||||
def set_sat(self, sat: int):
|
||||
"""Set the saturation of the light, if possible
|
||||
|
||||
Args:
|
||||
sat (int): 0-254
|
||||
"""
|
||||
if self.can_set_sat():
|
||||
state = '{{"sat":{0}}}'.format(sat)
|
||||
self.set_state(state)
|
||||
|
||||
def toggle(self):
|
||||
"""Toggle light
|
||||
"""
|
||||
|
@ -343,6 +403,22 @@ class HueLight:
|
|||
"""Get current colortemp
|
||||
|
||||
Returns:
|
||||
int: 0,153-500
|
||||
int: -1,153-500
|
||||
"""
|
||||
return self.get_state().get_ct()
|
||||
|
||||
def get_hue(self) -> int:
|
||||
"""Get current hue
|
||||
|
||||
Returns:
|
||||
int: -1-65535
|
||||
"""
|
||||
return self.get_state().get_hue()
|
||||
|
||||
def get_sat(self):
|
||||
"""Get current saturation
|
||||
|
||||
Returns:
|
||||
int: -1-254
|
||||
"""
|
||||
return self.get_state().get_sat()
|
||||
|
|
Loading…
Add table
Reference in a new issue