Add hue and saturation sliders and make API consistent so that it return -1 for default values

pull/17/head
Micke Nordin 4 years ago
parent d78be65a06
commit ba4554812c
Signed by: micke
GPG Key ID: 014B273D614BE877

@ -200,7 +200,8 @@ class Hui(wx.Frame):
toggle_btn) toggle_btn)
# Slider for brightness # Slider for brightness
if is_on and light.get_brightness() > 0: if is_on:
if light.get_brightness() > 0:
b_label: wx.StaticText = wx.StaticText(self.pnl, label="Brightness") b_label: wx.StaticText = wx.StaticText(self.pnl, label="Brightness")
self.sizer.Add(b_label, 0, wx.EXPAND) self.sizer.Add(b_label, 0, wx.EXPAND)
b_slider: wx.Slider = wx.Slider(self.pnl, value=light.get_state().get_brightness(), minValue=1, b_slider: wx.Slider = wx.Slider(self.pnl, value=light.get_state().get_brightness(), minValue=1,
@ -209,7 +210,7 @@ class Hui(wx.Frame):
self.Bind(wx.EVT_SCROLL, self.Bind(wx.EVT_SCROLL,
lambda event: self.set_brightness(event, light.get_id()), b_slider) lambda event: self.set_brightness(event, light.get_id()), b_slider)
# Slider for colortemp # Slider for colortemp
if is_on and light.can_set_ct(): if light.can_set_ct():
c_label: wx.StaticText = wx.StaticText(self.pnl, label="Color Temperature") c_label: wx.StaticText = wx.StaticText(self.pnl, label="Color Temperature")
self.sizer.Add(c_label, 0, wx.EXPAND) self.sizer.Add(c_label, 0, wx.EXPAND)
c_slider: wx.Slider = wx.Slider(self.pnl, value=light.get_ct(), minValue=153, maxValue=500) c_slider: wx.Slider = wx.Slider(self.pnl, value=light.get_ct(), minValue=153, maxValue=500)
@ -217,6 +218,24 @@ class Hui(wx.Frame):
self.Bind(wx.EVT_SCROLL, self.Bind(wx.EVT_SCROLL,
lambda event: self.set_colortemp(event, light.get_id()), c_slider) 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): def set_brightness(self, event: wx.ScrollEvent, lightid: int):
"""Call back for brightness slider """Call back for brightness slider
@ -248,6 +267,28 @@ class Hui(wx.Frame):
light: HueLight = self.cur_bridge.get_light_by_id(lightid) light: HueLight = self.cur_bridge.get_light_by_id(lightid)
light.set_ct(ct) 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__": if __name__ == "__main__":
app = wx.App() app = wx.App()

@ -27,11 +27,19 @@ class HueLight:
if 'bri' in keys: if 'bri' in keys:
self.m_bri: int = data_slice['bri'] self.m_bri: int = data_slice['bri']
else: else:
self.m_bri: int = 0 self.m_bri: int = -1
if 'ct' in keys: if 'ct' in keys:
self.m_ct: int = data_slice['ct'] self.m_ct: int = data_slice['ct']
else: 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'] self.m_alert: str = data_slice['alert']
if 'colormode' in keys: if 'colormode' in keys:
self.m_colormode: str = data_slice['colormode'] self.m_colormode: str = data_slice['colormode']
@ -44,7 +52,7 @@ class HueLight:
"""Get current brightness of the light """Get current brightness of the light
Returns: Returns:
int: 0-254 int: -1-254
""" """
return self.m_bri return self.m_bri
@ -52,10 +60,26 @@ class HueLight:
"""Get current color temp of the light """Get current color temp of the light
Returns: 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 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: def is_on(self) -> bool:
"""Is this thing on? """Is this thing on?
@ -107,17 +131,17 @@ class HueLight:
if 'min' in keys: if 'min' in keys:
self.m_min: int = data_slice['min'] self.m_min: int = data_slice['min']
else: else:
self.m_min: int = 0 self.m_min: int = -1
if 'max' in keys: if 'max' in keys:
self.m_max: int = data_slice['max'] self.m_max: int = data_slice['max']
else: else:
self.m_max: int = 0 self.m_max: int = -1
def get_max(self) -> int: def get_max(self) -> int:
"""Get the max colortemp of this light """Get the max colortemp of this light
Returns: 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 return self.m_max
@ -131,11 +155,11 @@ class HueLight:
if 'mindimlevel' in keys: if 'mindimlevel' in keys:
self.m_mindimlevel: int = data_slice['mindimlevel'] self.m_mindimlevel: int = data_slice['mindimlevel']
else: else:
self.m_mindimlevel: int = 0 self.m_mindimlevel: int = -1
if 'maxlumen' in keys: if 'maxlumen' in keys:
self.m_maxlumen: int = data_slice['maxlumen'] self.m_maxlumen: int = data_slice['maxlumen']
else: else:
self.m_maxlumen: int = 0 self.m_maxlumen: int = -1
if 'ct' in data_slice.keys(): if 'ct' in data_slice.keys():
self.m_ct = HueLight.Capabilites.Control.ColorTemp(data_slice['ct']) self.m_ct = HueLight.Capabilites.Control.ColorTemp(data_slice['ct'])
else: else:
@ -246,7 +270,23 @@ class HueLight:
Returns: Returns:
bool: True if we can, otherwise False 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): def get_state(self):
"""Get the state object for this light """Get the state object for this light
@ -315,6 +355,26 @@ class HueLight:
state = '{{"ct":{0}}}'.format(colortemp) state = '{{"ct":{0}}}'.format(colortemp)
self.set_state(state) 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): def toggle(self):
"""Toggle light """Toggle light
""" """
@ -343,6 +403,22 @@ class HueLight:
"""Get current colortemp """Get current colortemp
Returns: Returns:
int: 0,153-500 int: -1,153-500
""" """
return self.get_state().get_ct() 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…
Cancel
Save