Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_color(self):
from yeelight import Bulb
with patch('yeelight.discover_bulbs', return_value=[Bulb('')]):
self.get_component().send(color='#FAEBD7')
self.bulb_mock.return_value.set_rgb.assert_called_with(250, 235, 215)
def setUp(self):
self.socket = SocketMock()
self.bulb = Bulb(ip="", auto_on=True)
self.bulb._Bulb__socket = self.socket
def test_christmas_transition(self):
from yeelight import Bulb
with patch('yeelight.discover_bulbs', return_value=[Bulb('')]):
self.get_component().send(flow_transition='christmas', flow_duration=500,
brightness=80, flow_sleep=600)
flow = self.bulb_mock.return_value.start_flow.call_args[0][0]
self.assertEqual(flow.transitions[0].brightness, 80)
self.assertEqual(flow.transitions[0].duration, 500)
self.assertEqual(flow.transitions[1].duration, 600)
self.bulb_mock.return_value.set_brightness.assert_not_called()
def api_factory(ip : str) -> Any:
api = None
try:
from yeelight import Bulb, BulbException
try:
api = Bulb(ip)
except BulbException:
exit(wording.get('connection_no').format('XIAOMI YEELIGHT') + wording.get('exclamation_mark'))
try:
api.turn_on()
except BulbException:
exit(wording.get('enable_feature').format('LAN CONTROL', 'XIAOMI YEELIGHT') + wording.get('exclamation_mark'))
return api
except ImportError:
exit(wording.get('package_no').format('XIAOMI YEELIGHT') + wording.get('exclamation_mark'))
def cli(ip, port, effect, duration, bulb, auto_on):
"""Easily control the YeeLight RGB LED lightbulb."""
config = ConfigParser.SafeConfigParser()
config.read([os.path.expanduser('~/.config/yeecli/yeecli.cfg')])
ip = param_or_config(ip, config, bulb, "ip", None)
port = param_or_config(port, config, bulb, "port", 55443)
effect = param_or_config(effect, config, bulb, "effect", "sudden")
duration = param_or_config(duration, config, bulb, "duration", 500)
if not ip:
click.echo("No IP address specified.")
sys.exit(1)
BULBS.append(yeelight.Bulb(
ip=ip,
port=port,
effect=effect,
duration=duration,
auto_on=auto_on,
))
def get_bulb(self, index):
ip_addr = self.bulbs[index].get('ip')
bulb = yeelight.Bulb(ip_addr)
return bulb
def get_bulb(self):
from yeelight import Bulb, discover_bulbs
ip = self.component.ip
if not ip:
devices = discover_bulbs()
list_devices(devices)
ip = devices[0]['ip']
return Bulb(ip)
def room_handler():
post_dict = request.query.decode()
if 'ct' in post_dict and 'bri' in post_dict:
ct = int(post_dict['ct'])
bri = int(float(post_dict['bri']) * 100)
for (currentbulb, maxtemp, mintemp) in zip(bulbs, maxtemps, mintemps):
if currentbulb != '':
print('Sending command to Yeelight at', currentbulb)
bulb = Bulb(currentbulb)
if static_brightness is False:
bulb.set_brightness(bri)
print('Brightness set to', bri, 'percent')
if int(mintemp) < ct < int(maxtemp):
bulb.set_color_temp(ct)
print('Color temperature set to', ct, 'Kelvin')
else:
if ct > int(maxtemp):
bulb.set_color_temp(int(maxtemp))
print('Reached highest color temperature of', maxtemp, 'Kelvin')
if ct < int(mintemp):
bulb.set_color_temp(int(mintemp))
print('Reached lowest color temperature of', mintemp, 'Kelvin')
default_brightness = int(config.get('general', 'BrightnessValue'))
for n in range(1, (bulb_count + 1)):
bulbs.append(config.get(str(n), 'ip'))
if config.get(str(n), 'MaxColorTemperature') == '':
maxtemps.append(6500)
else:
maxtemps.append(config.get(str(n), 'MaxColorTemperature'))
if config.get(str(n), 'MinColorTemperature') == '':
mintemps.append(1700)
else:
mintemps.append(config.get(str(n), 'MinColorTemperature'))
print('Initializing...')
for init_bulb in bulbs:
if init_bulb != '':
print('Initializing Yeelight at %s' % init_bulb)
bulb = Bulb(init_bulb)
if check_state is True:
state = bulb.get_properties(requested_properties=['power'])
if 'off' in state['power']:
print('Powered off. Ignoring Yeelight at %s' % init_bulb)
elif static_brightness is True:
print('Changing brightness of', init_bulb)
bulb.set_brightness(default_brightness)
else:
print('Turning on Yeelight at %s' % init_bulb)
bulb.turn_on()
if static_brightness is True:
bulb.set_brightness(default_brightness)
else:
bulb.set_brightness(100)
run(host='127.0.0.1', port=8080)