Commit fba59912999070702562359efdb9ce41e66d0716
1 parent
8188e03d
Exists in
dev
Nouvelle classe "Cmd" pour les commandes (v2)
Showing
2 changed files
with
29 additions
and
12 deletions
Show diff stats
src/device_controller/abstract_component/device_controller.py
... | ... | @@ -134,7 +134,6 @@ class DeviceCmd: |
134 | 134 | cmd_name = self.full_name[self.full_name.find('.')+1:] |
135 | 135 | return cmd_name.startswith('do_') or cmd_name.startswith('get_') or cmd_name.startswith('set_') |
136 | 136 | |
137 | - | |
138 | 137 | ''' |
139 | 138 | @classmethod |
140 | 139 | def is_generic_cmd_name(cls, cmd_name:str): |
... | ... | @@ -340,11 +339,24 @@ class Gen2NatCmds: |
340 | 339 | ''' |
341 | 340 | def add_cmd(self, cmd:Cmd): |
342 | 341 | self.GEN2NAT_CMDS[cmd.generic_name] = cmd |
343 | - def add_cmds(self, *cmds): | |
344 | - if isinstance(cmds[0], str): | |
345 | - self.GEN2NAT_CMDS[cmds[0]] = { cmd.generic_name:cmd for cmd in cmds[1] } | |
342 | + def add_cmds(self, *cmds): | |
343 | + # add a dict | |
344 | + if isinstance(cmds[0], dict): | |
345 | + self.GEN2NAT_CMDS.update(cmds[0]) | |
346 | + # add a list | |
346 | 347 | elif isinstance(cmds[0], list): |
347 | 348 | for cmd in cmds[0]: self.add_cmd(cmd) |
349 | + elif isinstance(cmds[0], str): | |
350 | + if len(cmds) == 1: raise Exception("Missing second arg (list or dict)") | |
351 | + # add a key:dict | |
352 | + if isinstance(cmds[1], dict): | |
353 | + self.GEN2NAT_CMDS[cmds[0]] = cmds[1] | |
354 | + # add a key:list | |
355 | + elif isinstance(cmds[1], list): | |
356 | + self.GEN2NAT_CMDS[cmds[0]] = { cmd.generic_name:cmd for cmd in cmds[1] } | |
357 | + else: | |
358 | + raise Exception("Second arg should be a list or a dict") | |
359 | + # add a list of cmd (cmd1, cmd2, cmd3, ...) | |
348 | 360 | elif isinstance(cmds[0], Cmd): |
349 | 361 | for cmd in cmds: self.add_cmd(cmd) |
350 | 362 | else: | ... | ... |
src/device_controller/concrete_component/gemini/gemini_controller.py
... | ... | @@ -384,9 +384,8 @@ class DC_Gemini(DeviceController): |
384 | 384 | get_time, |
385 | 385 | set_time, |
386 | 386 | ] |
387 | + GEN2NAT_CMDS_GENERAL_obj = Gen2NatCmds(GEN2NAT_CMDS_GENERAL_obj).get_as_dict() | |
387 | 388 | |
388 | - my_cmds = Gen2NatCmds() | |
389 | - my_cmds.add_cmds(GEN2NAT_CMDS_GENERAL_obj) | |
390 | 389 | ''' |
391 | 390 | my_cmds.add_cmds( |
392 | 391 | get_ack, |
... | ... | @@ -412,7 +411,7 @@ class DC_Gemini(DeviceController): |
412 | 411 | 'get_time': ['GL', '10:20:36'], |
413 | 412 | 'set_time': ['SL'], |
414 | 413 | } |
415 | - GEN2NAT_CMDS_GENERAL = GEN2NAT_CMDS_GENERAL_dict | |
414 | + #GEN2NAT_CMDS_GENERAL = GEN2NAT_CMDS_GENERAL_dict | |
416 | 415 | |
417 | 416 | |
418 | 417 | # RA-DEC (p109-110) |
... | ... | @@ -523,7 +522,8 @@ class DC_Gemini(DeviceController): |
523 | 522 | Cmd('do_moveeast', 'Me'), |
524 | 523 | Cmd('do_stop', 'Q'), |
525 | 524 | ] |
526 | - my_cmds.add_cmds('DC_Mount', GEN2NAT_CMDS_MOUNT_obj) | |
525 | + GEN2NAT_CMDS_MOUNT_obj = Gen2NatCmds(GEN2NAT_CMDS_MOUNT_obj).get_as_dict() | |
526 | + | |
527 | 527 | |
528 | 528 | GEN2NAT_CMDS_MOUNT_dict = { |
529 | 529 | |
... | ... | @@ -575,14 +575,15 @@ class DC_Gemini(DeviceController): |
575 | 575 | } |
576 | 576 | |
577 | 577 | GEN2NAT_CMDS_MOUNT = GEN2NAT_CMDS_MOUNT_dict |
578 | - GEN2NAT_CMDS_MOUNT = Gen2NatCmds(GEN2NAT_CMDS_MOUNT_obj).get_as_dict() | |
578 | + GEN2NAT_CMDS_MOUNT = GEN2NAT_CMDS_MOUNT_obj | |
579 | + | |
579 | 580 | |
580 | 581 | GEN2NAT_CMDS_dict = { |
581 | 582 | # My GENERAL commands |
582 | - **GEN2NAT_CMDS_GENERAL, | |
583 | + **GEN2NAT_CMDS_GENERAL_dict, | |
583 | 584 | |
584 | 585 | # SPECIFIC commands for my DCCs |
585 | - 'DC_Mount' : GEN2NAT_CMDS_MOUNT | |
586 | + 'DC_Mount' : GEN2NAT_CMDS_MOUNT_dict | |
586 | 587 | } |
587 | 588 | ''' |
588 | 589 | GEN2NAT_CMDS_obj = [ |
... | ... | @@ -593,8 +594,12 @@ class DC_Gemini(DeviceController): |
593 | 594 | GEN2NAT_CMDS_MOUNT_obj |
594 | 595 | ] |
595 | 596 | ''' |
597 | + GEN2NAT_CMDS_obj = Gen2NatCmds() | |
598 | + GEN2NAT_CMDS_obj.add_cmds(GEN2NAT_CMDS_GENERAL_obj) | |
599 | + GEN2NAT_CMDS_obj.add_cmds('DC_Mount', GEN2NAT_CMDS_MOUNT_obj) | |
600 | + | |
596 | 601 | GEN2NAT_CMDS = GEN2NAT_CMDS_dict |
597 | - GEN2NAT_CMDS = my_cmds.get_as_dict() | |
602 | + GEN2NAT_CMDS = GEN2NAT_CMDS_obj.get_as_dict() | |
598 | 603 | |
599 | 604 | # Utilisation, affichage |
600 | 605 | #mes_commandes.add_cmd(get_ack) | ... | ... |