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

- Linting !


git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@3027 b32b6428-25c9-4566-ad07-03861ab6144f
parent 2b4eb553
Branches
No related tags found
No related merge requests found
import colorsys
from xaal.schemas import devices
from xaal.lib import tools,Device
import logging
import copy
import functools
import gevent
from decorator import decorator
from xaal.schemas import devices
from xaal.lib import tools
logger = logging.getLogger(__name__)
def run(func, *args, **kwargs):
self = args[0]
if not self.lock.ready():
logger.warning("LOCKED waiting.. %s" % func)
logger.warning(f"LOCKED waiting.. {func}")
self.lock.wait()
self.lock.acquire()
try:
......@@ -32,12 +32,12 @@ def spawn(func, *args, **kwargs):
def properties_compare(orig, new):
r = {}
res = {}
for k in new.keys():
if k in orig.keys():
if new[k] != orig[k]:
r.update({k:new[k]})
return r
res.update({k: new[k]})
return res
class YeelightDev(object):
......@@ -48,7 +48,7 @@ class YeelightDev(object):
self.dev = None
self.setup()
self.set_xaal()
logger.info('New device at %s : %s' % (bulb._ip,self.addr))
logger.info(f"New device at {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)
......@@ -113,7 +113,7 @@ class RGBW(YeelightDev):
dev.methods['set_hsv'] = self.set_hsv
dev.methods['set_white_temperature'] = self.set_white_temperature
dev.methods['set_mode'] = self.set_mode
dev.info = 'RGBW / %s' % self.addr
dev.info = f"RGBW / {self.addr}"
dev.attributes['hsv'] = [0, 0, 0]
dev.unsupported_attributes = ['scene']
dev.unsupported_methods = ['get_scene', 'set_scene']
......@@ -146,8 +146,7 @@ class RGBW(YeelightDev):
duration = int(_smooth)
else:
duration = int(self.cfg.get('smooth_default', 500))
if duration < 50:
duration = 50
duration = max(duration, 50)
self.bulb.turn_on()
self.bulb.duration = duration
self.bulb.set_hsv(h, s, v)
......@@ -159,7 +158,6 @@ 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
......@@ -173,8 +171,7 @@ class RGBW(YeelightDev):
duration = int(_smooth)
else:
duration = int(self.cfg.get('smooth_default', 500))
if duration < 50:
duration = 50
duration = max(duration, 50)
self.bulb.turn_on()
self.bulb.duration = duration
......@@ -247,7 +244,6 @@ class RGBW(YeelightDev):
# hsv[0] = int(hue)
# attrs['hsv']=hsv
if rgb:
rgb = int(rgb)
r = (rgb >> 16) / 255
......
......@@ -14,6 +14,7 @@ logger = logging.getLogger(PACKAGE_NAME)
# disable internal logging
logging.getLogger("yeelight").setLevel(logging.WARNING)
class GW(object):
def __init__(self, engine):
self.engine = engine
......@@ -33,7 +34,6 @@ class GW(object):
cfg.write()
self.cfg = cfg
def setup_(self):
logger.info("Searching for bulbs")
bulbs = yeelight.discover_bulbs()
......@@ -50,7 +50,6 @@ class GW(object):
dev = devices.RGBW(bulb, cfg[k])
self.engine.add_device(dev.dev)
def setup(self):
logger.info("Loading bulbs")
cfg = self.cfg['devices']
......@@ -68,9 +67,9 @@ class GW(object):
self.engine.add_device(dev.dev)
def refresh(self):
for d in self.devices:
d.get_properties()
d.set_xaal()
for dev in self.devices:
dev.get_properties()
dev.set_xaal()
def _exit(self):
cfg = tools.load_cfg(PACKAGE_NAME)
......@@ -78,6 +77,7 @@ class GW(object):
logger.info('Saving configuration file')
self.cfg.write()
def setup(eng):
GW(eng)
return True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment