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

Mr Proper

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2523 b32b6428-25c9-4566-ad07-03861ab6144f
parent af2f23bd
Branches
No related tags found
No related merge requests found
from xaal.schemas import devices
from xaal.lib import tools,Device
import asyncio
import time
import logging
import copy
import functools
logger = logging.getLogger(__name__)
import gevent
from gevent.util import wrap_errors
from decorator import decorator
logger = logging.getLogger(__name__)
def run(func,*args,**kwargs):
self = args[0]
if not self.lock.ready():
......@@ -42,13 +36,15 @@ def properties_compare(orig,new):
return r
class YeelightDev(object):
def __init__(self,bulb,addr):
logger.info('New device at %s : %s' % (bulb._ip,addr))
def __init__(self,bulb,cfg):
self.bulb = bulb
self.addr = addr
self.cfg = cfg
self.addr = tools.get_uuid(cfg.get('addr'))
self.dev = None
self.setup()
self.set_xaal()
logger.info('New device at %s : %s' % (bulb._ip,self.addr))
# It's safer to use a lock to avoid the socket to be used w/ 2 greenlets at the same time.
# This can occurs on the device refresh
self.lock = gevent.lock.BoundedSemaphore(1)
......@@ -77,20 +73,24 @@ class YeelightDev(object):
@spawn
def turn_on(self):
self.bulb.duration = 200
self.bulb.duration = int(self.cfg.get('smooth_on',200))
self.bulb.turn_on()
self._update_properties()
@spawn
def turn_off(self):
self.bulb.duration = 5000
self.bulb.duration = int(self.cfg.get('smooth_off',200))
self.bulb.turn_off()
self._update_properties()
@spawn
#@spawn
def toggle(self):
self.bulb.toggle()
self._update_properties()
#self.bulb.toggle()
if self.dev.attributes['light']:
self.turn_off()
else:
self.turn_on()
#self._update_properties()
@spawn
def get_properties(self):
......@@ -123,14 +123,19 @@ class RGBW(YeelightDev):
import pdb;pdb.set_trace()
@spawn
def set_brightness(self,_brightness,_smooth=0):
def set_brightness(self,_brightness,_smooth=None):
val = int(_brightness)
if _smooth:
duration = int(_smooth)
else:
duration = int(self.cfg.get('smooth_default',500))
self.bulb.turn_on()
self.bulb.duration = duration
self.bulb.set_brightness(val)
self._update_properties()
@spawn
def set_hsv(self,_hsv,_smooth=200):
def set_hsv(self,_hsv,_smooth=None):
# FIXME
if isinstance(_hsv,str):
hsv = [float(k) for k in list(_hsv.split(','))]
......@@ -140,7 +145,10 @@ class RGBW(YeelightDev):
v = int(v * 100)
s = int(s * 100)
h = int(h)
if _smooth:
duration = int(_smooth)
else:
duration = int(self.cfg.get('smooth_default',500))
if duration < 50:
duration = 50
self.bulb.turn_on()
......@@ -158,7 +166,7 @@ class RGBW(YeelightDev):
def set_white_temperature(self,_white_temperature):
val = int(_white_temperature)
self.bulb.turn_on()
self.bulb.duration = 5000
self.bulb.duration = int(self.cfg.get('smooth_default',500))
self.bulb.set_color_temp(val)
self._update_properties()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment