cli: allow to change LED settings
This commit is contained in:
@@ -124,6 +124,7 @@ def _lightspeed_receiver(product_id: int) -> dict:
|
||||
"receiver_kind": "lightspeed",
|
||||
"name": _("Lightspeed Receiver"),
|
||||
"may_unpair": False,
|
||||
"re_pairs": True,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1640,7 +1640,7 @@ _LEDP = hidpp20.LEDParam
|
||||
|
||||
# an LED Zone has an index, a set of possible LED effects, and an LED effect setting
|
||||
class LEDZoneSetting(settings.Setting):
|
||||
name = "led_zone_"
|
||||
name = "led_zone_" # the trailing underscore signals that this setting creates other settings
|
||||
label = _("LED Zone Effects")
|
||||
description = _("Set effect for LED Zone") + "\n" + _("LED Control needs to be set to Solaar to be effective.")
|
||||
feature = _F.COLOR_LED_EFFECTS
|
||||
@@ -1688,7 +1688,7 @@ class RGBControl(settings.Setting):
|
||||
|
||||
|
||||
class RGBEffectSetting(LEDZoneSetting):
|
||||
name = "rgb_zone_"
|
||||
name = "rgb_zone_" # the trailing underscore signals that this setting creates other settings
|
||||
label = _("LED Zone Effects")
|
||||
description = _("Set effect for LED Zone") + "\n" + _("LED Control needs to be set to Solaar to be effective.")
|
||||
feature = _F.RGB_EFFECTS
|
||||
@@ -2100,10 +2100,18 @@ def check_feature_settings(device, already_known) -> bool:
|
||||
|
||||
def check_feature_setting(device, setting_name: str) -> settings.Setting | None:
|
||||
for sclass in SETTINGS:
|
||||
if sclass.feature and sclass.name == setting_name and device.features:
|
||||
if (
|
||||
sclass.feature
|
||||
and device.features
|
||||
and (sclass.name == setting_name or sclass.name.endswith("_") and setting_name.startswith(sclass.name))
|
||||
):
|
||||
try:
|
||||
setting = check_feature(device, sclass)
|
||||
except Exception:
|
||||
return None
|
||||
if setting:
|
||||
if isinstance(setting, list):
|
||||
for s in setting:
|
||||
if s.name == setting_name:
|
||||
return s
|
||||
elif setting:
|
||||
return setting
|
||||
|
||||
@@ -210,7 +210,8 @@ def run(receivers, args, _find_receiver, find_device):
|
||||
if remote:
|
||||
argl = ["config", dev.serial or dev.unitId, setting.name]
|
||||
argl.extend([a for a in [args.value_key, args.extra_subkey, args.extra2] if a is not None])
|
||||
application.run(yaml.safe_dump(argl))
|
||||
args = yaml.dump(argl)
|
||||
application.run(args)
|
||||
else:
|
||||
if dev.persister and setting.persist:
|
||||
dev.persister[setting.name] = setting._value
|
||||
@@ -278,8 +279,6 @@ def set(dev, setting: SettingsProtocol, args, save):
|
||||
key = args.value_key
|
||||
all_keys = getattr(setting, "choices_universe", None)
|
||||
ikey = all_keys[int(key) if key.isdigit() else key] if isinstance(all_keys, NamedInts) else to_int(key)
|
||||
print("S", args.extra2, key, type(all_keys), ikey)
|
||||
print("SS", args)
|
||||
if args.extra2 is None or to_int(args.extra2) is None:
|
||||
raise Exception(f"{setting.name}: setting needs an integer value, not {args.extra2}")
|
||||
if not setting._value: # ensure that there are values to look through
|
||||
@@ -308,8 +307,14 @@ def set(dev, setting: SettingsProtocol, args, save):
|
||||
message = f"Setting {setting.name} of {dev.name} key {key} to {value}"
|
||||
result = setting.write_key_value(key, value, save=save)
|
||||
|
||||
elif setting.kind == settings.Kind.HETERO:
|
||||
value = yaml.safe_load(args.value_key)
|
||||
args.value_key = value
|
||||
message = f"Setting {setting.name} of {dev.name} to {value}"
|
||||
result = setting.write(value, save=save)
|
||||
|
||||
else:
|
||||
print("KIND", setting.kind)
|
||||
print(f"Setting {setting.name}, with kind {setting.kind.name}, not implemented")
|
||||
raise Exception("NotImplemented")
|
||||
|
||||
return result, message, value
|
||||
|
||||
Reference in New Issue
Block a user