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
try:
for light in device_profile["lights"]:
color_tuple = get_color_tuple((device_profile["lights"][light]))
device.fx.advanced.matrix[
lightmap[light][0], lightmap[light][1]
] = color_tuple
# If lights are declared apply profile, else turn lights off
if "lights" in device_profile:
for light in device_profile["lights"]:
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:
error(
"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):
"""Apply a profile by name."""
@ -133,11 +139,11 @@ def apply_profile(name):
error("couldn't load profile '{}': {}".format(name, e))
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]:
error("'name' declaration is missing for device '{}'".format(device))
error("'name' attribute is missing for device '{}'".format(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])