187187
188188class KlyqaBulbResponseStatus (KlyqaDeviceResponse ):
189189 """Klyqa_Bulb_Response_Status"""
190-
190+
191191 active_command : int | None = None
192192 active_scene : str | None = None
193193 fwversion : str | None = None
@@ -203,15 +203,12 @@ def __str__(self) -> str:
203203 """__str__"""
204204 return get_obj_attr_values_as_string (self )
205205
206- def __init__ (
207- self ,
208- ** kwargs
209- ) -> None :
206+ def __init__ (self , ** kwargs ) -> None :
210207 """__init__"""
211208 self .active_command = None
212209 self .active_scene = None
213210 self .fwversion = None
214- self .mode = None # cmd, cct, rgb
211+ self .mode = None # cmd, cct, rgb
215212 self .open_slots = None
216213 self .sdkversion = None
217214 self .status = None
@@ -235,7 +232,9 @@ def color(self) -> RGBColor | None:
235232
236233 @color .setter
237234 def color (self , color : dict [str , int ]) -> None :
238- self ._color = RGBColor (color ["red" ], color ["green" ], color ["blue" ]) if color else None
235+ self ._color = (
236+ RGBColor (color ["red" ], color ["green" ], color ["blue" ]) if color else None
237+ )
239238
240239
241240class KlyqaBulb (KlyqaDevice ):
@@ -273,7 +272,6 @@ def setTemp(self, temp: int):
273272 return False
274273
275274
276-
277275def color_message (red , green , blue , transition , skipWait = False ) -> tuple [str , int ]:
278276 waitTime = transition if not skipWait else 0
279277 return (
@@ -306,7 +304,9 @@ def temperature_message(temperature, transition, skipWait=False) -> tuple[str, i
306304 )
307305
308306
309- def percent_color_message (red , green , blue , warm , cold , transition , skipWait ) -> tuple [str , int ]:
307+ def percent_color_message (
308+ red , green , blue , warm , cold , transition , skipWait
309+ ) -> tuple [str , int ]:
310310 waitTime = transition if not skipWait else 0
311311 return (
312312 json .dumps (
@@ -341,6 +341,7 @@ def brightness_message(brightness, transition) -> tuple[str, int]:
341341 transition ,
342342 )
343343
344+
344345commands_send_to_bulb : list [str ] = [
345346 "request" ,
346347 "ping" ,
@@ -381,9 +382,10 @@ def brightness_message(brightness, transition) -> tuple[str, int]:
381382 "magic" ,
382383 "mystic" ,
383384 "cotton" ,
384- "ice"
385+ "ice" ,
385386]
386387
388+
387389def add_command_args_bulb (parser : argparse .ArgumentParser ) -> None :
388390 """Add arguments to the argument parser object.
389391
@@ -483,7 +485,10 @@ def add_command_args_bulb(parser: argparse.ArgumentParser) -> None:
483485 )
484486
485487 parser .add_argument (
486- "--fade" , nargs = 2 , help = "fade in/out time in milliseconds on powering device on/off" , metavar = ("IN" , "OUT" )
488+ "--fade" ,
489+ nargs = 2 ,
490+ help = "fade in/out time in milliseconds on powering device on/off" ,
491+ metavar = ("IN" , "OUT" ),
487492 )
488493
489494 # parser.add_argument("--loop", help="loop", action="store_true")
@@ -515,13 +520,21 @@ def add_command_args_bulb(parser: argparse.ArgumentParser) -> None:
515520 parser .add_argument ("--ice" , help = "Ice Cream" , action = "store_true" )
516521
517522
518- async def process_args_to_msg_lighting (args , args_in , send_to_devices_cb , message_queue_tx_local , message_queue_tx_command_cloud , message_queue_tx_state_cloud , scene_list : list [str ]) -> bool :
523+ async def process_args_to_msg_lighting (
524+ args ,
525+ args_in ,
526+ send_to_devices_cb ,
527+ message_queue_tx_local ,
528+ message_queue_tx_command_cloud ,
529+ message_queue_tx_state_cloud ,
530+ scene_list : list [str ],
531+ ) -> bool :
519532 """process_args_to_msg_lighting"""
520-
533+
521534 def local_and_cloud_command_msg (json_msg , timeout ) -> None :
522535 message_queue_tx_local .append ((json .dumps (json_msg ), timeout ))
523536 message_queue_tx_command_cloud .append (json_msg )
524-
537+
525538 # TODO: Missing cloud discovery and interactive device selection. Send to devices if given as argument working.
526539 if (args .local or args .tryLocalThanCloud ) and (
527540 not args .device_name
@@ -534,7 +547,7 @@ def local_and_cloud_command_msg(json_msg, timeout) -> None:
534547 "--request" ,
535548 "--allDevices" ,
536549 "--selectDevice" ,
537- "--discover"
550+ "--discover" ,
538551 ]
539552
540553 orginal_args_parser : argparse .ArgumentParser = get_description_parser ()
@@ -552,9 +565,7 @@ def local_and_cloud_command_msg(json_msg, timeout) -> None:
552565 discover_local_args , namespace = original_config_args_parsed
553566 )
554567
555- uids = await send_to_devices_cb (
556- discover_local_args_parsed
557- )
568+ uids = await send_to_devices_cb (discover_local_args_parsed )
558569 if isinstance (uids , set ) or isinstance (uids , list ):
559570 # args_in.extend(["--device_unitids", ",".join(list(uids))])
560571 args_in = ["--device_unitids" , "," .join (list (uids ))] + args_in
@@ -566,9 +577,11 @@ def local_and_cloud_command_msg(json_msg, timeout) -> None:
566577
567578 add_command_args_bulb (parser = orginal_args_parser )
568579 args = orginal_args_parser .parse_args (args = args_in , namespace = args )
569-
570- commands_to_send : list [str ] = [i for i in commands_send_to_bulb if hasattr (args , i ) and getattr (args , i )]
571-
580+
581+ commands_to_send : list [str ] = [
582+ i for i in commands_send_to_bulb if hasattr (args , i ) and getattr (args , i )
583+ ]
584+
572585 if commands_to_send :
573586 print ("Commands to send to devices: " + ", " .join (commands_to_send ))
574587 else :
@@ -579,9 +592,7 @@ def get_temp_range(product_id):
579592 temperature_enum = []
580593 try :
581594 temperature_enum = [
582- trait ["value_schema" ]["properties" ]["colorTemperature" ][
583- "enum"
584- ]
595+ trait ["value_schema" ]["properties" ]["colorTemperature" ]["enum" ]
585596 if "properties" in trait ["value_schema" ]
586597 else trait ["value_schema" ]["enum" ]
587598 for trait in device_configs [product_id ]["deviceTraits" ]
@@ -607,10 +618,18 @@ def get_inner_range(tup1, tup2) -> tuple[int, int]:
607618 if u_id not in self .devices or not self .devices [u_id ].ident :
608619
609620 async def send_ping () -> bool :
610- discover_local_args2 : list [str ] = ["--ping" , "--device_unitids" , u_id ]
621+ discover_local_args2 : list [str ] = [
622+ "--ping" ,
623+ "--device_unitids" ,
624+ u_id ,
625+ ]
611626
612- orginal_args_parser : argparse .ArgumentParser = get_description_parser ()
613- discover_local_args_parser2 : argparse .ArgumentParser = get_description_parser ()
627+ orginal_args_parser : argparse .ArgumentParser = (
628+ get_description_parser ()
629+ )
630+ discover_local_args_parser2 : argparse .ArgumentParser = (
631+ get_description_parser ()
632+ )
614633
615634 add_config_args (parser = orginal_args_parser )
616635 add_config_args (parser = discover_local_args_parser2 )
@@ -628,9 +647,7 @@ async def send_ping() -> bool:
628647 )
629648 )
630649
631- ret = send_to_devices_cb (
632- discover_local_args_parsed2
633- )
650+ ret = send_to_devices_cb (discover_local_args_parsed2 )
634651 if isinstance (ret , bool ) and ret :
635652 return True
636653 else :
@@ -705,9 +722,7 @@ async def send_ping() -> bool:
705722 # args.func(args)
706723
707724 if args .ota is not None :
708- local_and_cloud_command_msg (
709- {"type" : "fw_update" , "url" : args .ota }, 10000
710- )
725+ local_and_cloud_command_msg ({"type" : "fw_update" , "url" : args .ota }, 10000 )
711726
712727 if args .ping :
713728 local_and_cloud_command_msg ({"type" : "ping" }, 10000 )
@@ -750,9 +765,7 @@ def forced_continue(reason: str) -> bool:
750765
751766 def missing_config (product_id ) -> bool :
752767 if not forced_continue (
753- "Missing or faulty config values for device "
754- + " product_id: "
755- + product_id
768+ "Missing or faulty config values for device " + " product_id: " + product_id
756769 ):
757770 return True
758771 return False
@@ -804,10 +817,7 @@ def check_brightness_range(product_id, value) -> bool:
804817 100 ,
805818 )
806819
807- if (
808- int (value ) < brightness_range [0 ]
809- or int (value ) > brightness_range [1 ]
810- ):
820+ if int (value ) < brightness_range [0 ] or int (value ) > brightness_range [1 ]:
811821 return forced_continue (
812822 f"Brightness { value } out of range [{ brightness_range [0 ]} ..{ brightness_range [1 ]} ]."
813823 )
@@ -828,10 +838,7 @@ def check_temp_range(product_id, value) -> bool:
828838 # if trait["trait"] == "@core/traits/color-temperature"
829839 # ][0]
830840 temperature_range = [2000 , 6500 ]
831- if (
832- int (value ) < temperature_range [0 ]
833- or int (value ) > temperature_range [1 ]
834- ):
841+ if int (value ) < temperature_range [0 ] or int (value ) > temperature_range [1 ]:
835842 return forced_continue (
836843 f"Temperature { value } out of range [{ temperature_range [0 ]} ..{ temperature_range [1 ]} ]."
837844 )
@@ -891,9 +898,7 @@ def check_device_parameter(
891898 # return False
892899
893900 tt = args .transitionTime [0 ]
894- msg = color_message (
895- r , g , b , int (tt ), skipWait = args .brightness is not None
896- )
901+ msg = color_message (r , g , b , int (tt ), skipWait = args .brightness is not None )
897902
898903 check_color = functools .partial (
899904 check_device_parameter , Check_device_parameter .color , [r , g , b ]
@@ -941,9 +946,7 @@ def check_device_parameter(
941946 message_queue_tx_state_cloud .append ({"brightness" : brightness })
942947
943948 if args .percent_color is not None :
944- if not device_configs and not forced_continue (
945- "Missing configs for devices."
946- ):
949+ if not device_configs and not forced_continue ("Missing configs for devices." ):
947950 return False
948951 r , g , b , w , c = args .percent_color
949952 tt = args .transitionTime [0 ]
@@ -958,7 +961,9 @@ def check_device_parameter(
958961 local_and_cloud_command_msg ({"type" : "factory_reset" }, 500 )
959962
960963 if args .fade is not None and len (args .fade ) == 2 :
961- local_and_cloud_command_msg ({"type" : "request" ,"fade_out" : args .fade [1 ],"fade_in" : args .fade [0 ]}, 500 )
964+ local_and_cloud_command_msg (
965+ {"type" : "request" , "fade_out" : args .fade [1 ], "fade_in" : args .fade [0 ]}, 500
966+ )
962967
963968 scene = ""
964969 if args .WW :
@@ -1090,10 +1095,9 @@ def check_device_parameter(
10901095
10911096 if args .reboot :
10921097 local_and_cloud_command_msg ({"type" : "reboot" }, 500 )
1093-
1098+
10941099 if scene :
10951100 scene_list .append (scene )
10961101
10971102
10981103# async def discover_lightings(args, args_in, send_to_devices_cb):
1099-
0 commit comments