2727class LedsPage (Gtk .Box ):
2828 __gtype_name__ = 'LedsPage'
2929
30+ first_run = True
31+
3032 led_pwr = Gtk .Template .Child ()
3133 led_pwr_scale = Gtk .Template .Child ()
3234
@@ -35,17 +37,12 @@ class LedsPage(Gtk.Box):
3537
3638 led_advanced = Gtk .Template .Child ()
3739
38- led_pwr_colour = Gtk .Template .Child ()
39-
40- led_chg_colour = Gtk .Template .Child ()
41-
4240 def __init__ (self , ** kwargs ):
4341 super ().__init__ (** kwargs )
4442
4543 def setup (self , app ):
4644 # Power LED
4745 try :
48-
4946 def handle_led_pwr (scale ):
5047 value = int (abs (scale .get_value () - 2 ))
5148 ec_commands .framework_laptop .set_fp_led_level (app .cros_ec , value )
@@ -84,31 +81,35 @@ def handle_led_kbd(scale):
8481 self .led_kbd .set_visible (False )
8582
8683 # Advanced options
87- if ec_commands .general .get_cmd_versions (
88- app .cros_ec , ec_commands .leds .EC_CMD_LED_CONTROL
84+ if (
85+ ec_commands .general .get_cmd_versions (
86+ app .cros_ec , ec_commands .leds .EC_CMD_LED_CONTROL
87+ )
88+ and self .first_run
8989 ):
9090
91- # Advanced: Power LED
92- led_pwr_colour_strings = self .led_pwr_colour .get_model ()
93-
9491 all_colours = ["Red" , "Green" , "Blue" , "Yellow" , "White" , "Amber" ]
95-
96- def add_colours (strings , led_id ):
97- # Auto and Off should already be present
98- if strings .get_n_items () <= 2 :
99- supported_colours = ec_commands .leds .led_control_get_max_values (
92+ led_names = {
93+ ec_commands .leds .EcLedId .EC_LED_ID_BATTERY_LED : "Battery LED" ,
94+ ec_commands .leds .EcLedId .EC_LED_ID_POWER_LED : "Power LED" ,
95+ ec_commands .leds .EcLedId .EC_LED_ID_ADAPTER_LED : "Adapter LED" ,
96+ ec_commands .leds .EcLedId .EC_LED_ID_LEFT_LED : "Left LED" ,
97+ ec_commands .leds .EcLedId .EC_LED_ID_RIGHT_LED : "Right LED" ,
98+ ec_commands .leds .EcLedId .EC_LED_ID_RECOVERY_HW_REINIT_LED : "Recovery LED" ,
99+ ec_commands .leds .EcLedId .EC_LED_ID_SYSRQ_DEBUG_LED : "SysRq LED" ,
100+ }
101+ leds = {}
102+ for i in range (ec_commands .leds .EcLedId .EC_LED_ID_COUNT .value ):
103+ try :
104+ led_id = ec_commands .leds .EcLedId (i )
105+ leds [led_id ] = ec_commands .leds .led_control_get_max_values (
100106 app .cros_ec , led_id
101107 )
102- for i , colour in enumerate (all_colours ):
103- if supported_colours [i ]:
104- strings .append (colour )
105-
106- try :
107- add_colours (
108- led_pwr_colour_strings , ec_commands .leds .EcLedId .EC_LED_ID_POWER_LED
109- )
110- except ec_exceptions .ECError as e :
111- self .led_pwr_colour .set_sensitive (False )
108+ except ec_exceptions .ECError as e :
109+ if e .ec_status == ec_exceptions .EcStatus .EC_RES_INVALID_PARAM :
110+ continue
111+ else :
112+ raise e
112113
113114 def handle_led_colour (combobox , led_id ):
114115 colour = combobox .get_selected () - 2
@@ -132,30 +133,20 @@ def handle_led_colour(combobox, led_id):
132133 100 ,
133134 ec_commands .leds .EcLedColors (colour_idx ),
134135 )
136+ for led_id , supported_colours in leds .items ():
137+ if any (supported_colours ):
138+ combo = Adw .ComboRow (title = led_names [led_id ])
139+ model = Gtk .StringList .new (["Auto" , "Off" ])
140+ for i , colour in enumerate (all_colours ):
141+ if supported_colours [i ]:
142+ model .append (colour )
143+ combo .set_model (model )
144+ combo .connect (
145+ "notify::selected" ,
146+ lambda combobox , _ , led_id = led_id : handle_led_colour (
147+ combobox , led_id
148+ ),
149+ )
150+ self .led_advanced .add_row (combo )
135151
136- self .led_pwr_colour .connect (
137- "notify::selected" ,
138- lambda combo , _ : handle_led_colour (
139- combo , ec_commands .leds .EcLedId .EC_LED_ID_POWER_LED
140- ),
141- )
142-
143- # Advanced: Charging LED
144- led_chg_colour_strings = self .led_chg_colour .get_model ()
145-
146- try :
147- add_colours (
148- led_chg_colour_strings ,
149- ec_commands .leds .EcLedId .EC_LED_ID_BATTERY_LED ,
150- )
151- except ec_exceptions .ECError as e :
152- self .led_chg_colour .set_sensitive (False )
153-
154- self .led_chg_colour .connect (
155- "notify::selected" ,
156- lambda combo , _ : handle_led_colour (
157- combo , ec_commands .leds .EcLedId .EC_LED_ID_BATTERY_LED
158- ),
159- )
160- else :
161- self .led_advanced .set_visible (False )
152+ self .first_run = False
0 commit comments