@service
def filter_rbg_light_list(light_list=None ):
assert isinstance(light_list, list), log.info ('input light_list '+light_list+' is not a list.')
filter_light_list = []
for light in light_list:
if light.startswith('light'):
rgb_supported = 0
for color_mode in state.getattr(light)['supported_color_modes']:
rgb_supported += 1 if color_mode == 'hs' else 0
rgb_supported += 1 if color_mode == 'rgb' else 0
filter_light_list += [light] if rgb_supported > 0 else []
return filter_light_list
@service
def set_rgb_light_list(light_list=None, profile_name='soho'):
assert isinstance(light_list, list), log.info ('input light_list '+light_list+' is not a list.')
# Filter lights that support colour mode
light_list = filter_rbg_light_list(light_list)
# Select a colour profile
colour_list = []
for _profile_name, _colour_list in get_hue_colour_profiles().items():
if profile_name == _profile_name:
colour_list = _colour_list
# Picking up random colour for a light from a sepecific colour profile
num_of_lights = len(light_list)
colour_index_5 = [0,1,2,3,4]
import random
random.shuffle(colour_index_5)
colour_index = []
for i in range(len(light_list)):
colour_index += [colour_index_5[i%5]]
# Turn on lights with the selected colour index
for i in range(len(light_list)):
rgb_colour = colour_list[colour_index[i]]
light.turn_on(entity_id=light_list[i], rgb_color=rgb_colour)