Skip to content
Snippets Groups Projects
Commit 4a48814d authored by jkerdreu's avatar jkerdreu
Browse files

- Switch to music mode (need to provide a config flag)

- Switch from yeelight hsv to rgb (due to missing hue&sat properties in music-mode)



git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2938 b32b6428-25c9-4566-ad07-03861ab6144f
parent b0222ef6
No related branches found
No related tags found
No related merge requests found
import colorsys
from xaal.schemas import devices
from xaal.lib import tools,Device
......@@ -110,7 +111,6 @@ class RGBW(YeelightDev):
dev.methods['set_mode'] = self.set_mode
dev.methods['debug'] = self.debug
dev.info = 'RGBW / %s' % self.addr
dev.schema = 'https://redmine.telecom-bretagne.eu/svn/xaal/schemas/branches/schemas-0.7/lamp.color'
dev.attributes['hsv'] = [0,0,0]
dev.unsupported_attributes = ['scene']
dev.unsupported_methods = ['get_scene','set_scene']
......@@ -132,7 +132,7 @@ class RGBW(YeelightDev):
self._update_properties()
@spawn
def set_hsv(self,_hsv,_smooth=None):
def set_hsv_(self,_hsv,_smooth=None):
# FIXME
if isinstance(_hsv,str):
hsv = [float(k) for k in list(_hsv.split(','))]
......@@ -159,6 +159,37 @@ class RGBW(YeelightDev):
self.dev.engine.add_timer(self.get_properties,target,1)
self.dev.engine.add_timer(self.get_properties,target+0.5,1)
@spawn
def set_hsv(self,_hsv,_smooth=None):
# FIXME
if isinstance(_hsv,str):
hsv = [float(k) for k in list(_hsv.split(','))]
else:
hsv = _hsv
h,s,v = hsv
if _smooth:
duration = int(_smooth)
else:
duration = int(self.cfg.get('smooth_default',500))
if duration < 50:
duration = 50
self.bulb.turn_on()
self.bulb.duration = duration
rgb=tuple(round(i * 255) for i in colorsys.hsv_to_rgb(h/360.0,s,v))
self.bulb.set_rgb(rgb[0],rgb[1],rgb[2])
gevent.sleep(0.2)
self._update_properties()
target = round((duration / 1000.0),1)
# we schedule some get_properties at the end of the flow to update the current color
# As time drift, don't expect to have it working for a 1 hour flow.
self.dev.engine.add_timer(self.get_properties,target,1)
self.dev.engine.add_timer(self.get_properties,target+0.5,1)
@spawn
def set_white_temperature(self,_white_temperature):
val = int(_white_temperature)
......@@ -199,16 +230,30 @@ class RGBW(YeelightDev):
hsv = list(attrs['hsv'])
hsv[2] = int(bright)/100.0
attrs['hsv'] = hsv
# colors stuff
# Yeelight Python API provide both rgb and hsv values
# we parse both, even if we don't' issue set_hsv
# sat ?
sat = props.get('sat',None)
if sat:
hsv = attrs['hsv']
hsv[1] = (int(sat) / 100.0)
attrs['hsv']=list(hsv)
# sat = props.get('sat',None)
# if sat:
# hsv = attrs['hsv']
# hsv[1] = (int(sat) / 100.0)
# attrs['hsv']=list(hsv)
# hue
hue = props.get('hue',None)
if hue:
hsv = list(attrs['hsv'])
hsv[0] = int(hue)
attrs['hsv']=hsv
# hue = props.get('hue',None)
# if hue:
# hsv = list(attrs['hsv'])
# hsv[0] = int(hue)
# attrs['hsv']=hsv
rgb = props.get('rgb',None)
if rgb:
rgb = int(rgb)
r = (rgb >> 16) / 255
g = ((rgb >> 8) & 0xFF) / 255
b = (rgb & 0xFF) / 255
hsv = colorsys.rgb_to_hsv(r,g,b)
h = round(hsv[0] * 360)
s = round(hsv[1],2)
v = round(hsv[2],2)
attrs['hsv'] = [h,s,v]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment