turn lights off if none declared

This commit is contained in:
Denis Lehmann 2021-04-29 00:07:36 +02:00
parent 67cc92cc83
commit 83a81aae10

28
bin/rzr
View file

@ -97,11 +97,20 @@ def apply_device_profile(device_profile):
# Set light colors # Set light colors
try: try:
for light in device_profile["lights"]:
color_tuple = get_color_tuple((device_profile["lights"][light])) # If lights are declared apply profile, else turn lights off
device.fx.advanced.matrix[ if "lights" in device_profile:
lightmap[light][0], lightmap[light][1] for light in device_profile["lights"]:
] = color_tuple color_tuple = get_color_tuple((device_profile["lights"][light]))
device.fx.advanced.matrix[
lightmap[light][0], lightmap[light][1]
] = color_tuple
else:
device.fx.none()
# Apply light colors
device.fx.advanced.draw()
except KeyError: except KeyError:
error( error(
"light '{}' is not available in lightmap '{}' for device '{}'".format( "light '{}' is not available in lightmap '{}' for device '{}'".format(
@ -115,9 +124,6 @@ def apply_device_profile(device_profile):
) )
) )
# Apply light colors
device.fx.advanced.draw()
def apply_profile(name): def apply_profile(name):
"""Apply a profile by name.""" """Apply a profile by name."""
@ -133,11 +139,11 @@ def apply_profile(name):
error("couldn't load profile '{}': {}".format(name, e)) error("couldn't load profile '{}': {}".format(name, e))
for device in profile: for device in profile:
# Check if mandatory fields "name" and "lightmap" exist # Check if mandatory attributes "name" and "lightmap" exist
if "name" not in profile[device]: if "name" not in profile[device]:
error("'name' declaration is missing for device '{}'".format(device)) error("'name' attribute is missing for device '{}'".format(device))
if "lightmap" not in profile[device]: if "lightmap" not in profile[device]:
error("'lightmap' declaration is missing for device '{}'".format(device)) error("'lightmap' attribute is missing for device '{}'".format(device))
apply_device_profile(profile[device]) apply_device_profile(profile[device])