diff --git a/src/device_controller/abstract_component/device_controller.py b/src/device_controller/abstract_component/device_controller.py index d34a0b5..44d10ff 100755 --- a/src/device_controller/abstract_component/device_controller.py +++ b/src/device_controller/abstract_component/device_controller.py @@ -134,7 +134,6 @@ class DeviceCmd: cmd_name = self.full_name[self.full_name.find('.')+1:] return cmd_name.startswith('do_') or cmd_name.startswith('get_') or cmd_name.startswith('set_') - ''' @classmethod def is_generic_cmd_name(cls, cmd_name:str): @@ -340,11 +339,24 @@ class Gen2NatCmds: ''' def add_cmd(self, cmd:Cmd): self.GEN2NAT_CMDS[cmd.generic_name] = cmd - def add_cmds(self, *cmds): - if isinstance(cmds[0], str): - self.GEN2NAT_CMDS[cmds[0]] = { cmd.generic_name:cmd for cmd in cmds[1] } + def add_cmds(self, *cmds): + # add a dict + if isinstance(cmds[0], dict): + self.GEN2NAT_CMDS.update(cmds[0]) + # add a list elif isinstance(cmds[0], list): for cmd in cmds[0]: self.add_cmd(cmd) + elif isinstance(cmds[0], str): + if len(cmds) == 1: raise Exception("Missing second arg (list or dict)") + # add a key:dict + if isinstance(cmds[1], dict): + self.GEN2NAT_CMDS[cmds[0]] = cmds[1] + # add a key:list + elif isinstance(cmds[1], list): + self.GEN2NAT_CMDS[cmds[0]] = { cmd.generic_name:cmd for cmd in cmds[1] } + else: + raise Exception("Second arg should be a list or a dict") + # add a list of cmd (cmd1, cmd2, cmd3, ...) elif isinstance(cmds[0], Cmd): for cmd in cmds: self.add_cmd(cmd) else: diff --git a/src/device_controller/concrete_component/gemini/gemini_controller.py b/src/device_controller/concrete_component/gemini/gemini_controller.py index 5a767fb..eb0c208 100755 --- a/src/device_controller/concrete_component/gemini/gemini_controller.py +++ b/src/device_controller/concrete_component/gemini/gemini_controller.py @@ -384,9 +384,8 @@ class DC_Gemini(DeviceController): get_time, set_time, ] + GEN2NAT_CMDS_GENERAL_obj = Gen2NatCmds(GEN2NAT_CMDS_GENERAL_obj).get_as_dict() - my_cmds = Gen2NatCmds() - my_cmds.add_cmds(GEN2NAT_CMDS_GENERAL_obj) ''' my_cmds.add_cmds( get_ack, @@ -412,7 +411,7 @@ class DC_Gemini(DeviceController): 'get_time': ['GL', '10:20:36'], 'set_time': ['SL'], } - GEN2NAT_CMDS_GENERAL = GEN2NAT_CMDS_GENERAL_dict + #GEN2NAT_CMDS_GENERAL = GEN2NAT_CMDS_GENERAL_dict # RA-DEC (p109-110) @@ -523,7 +522,8 @@ class DC_Gemini(DeviceController): Cmd('do_moveeast', 'Me'), Cmd('do_stop', 'Q'), ] - my_cmds.add_cmds('DC_Mount', GEN2NAT_CMDS_MOUNT_obj) + GEN2NAT_CMDS_MOUNT_obj = Gen2NatCmds(GEN2NAT_CMDS_MOUNT_obj).get_as_dict() + GEN2NAT_CMDS_MOUNT_dict = { @@ -575,14 +575,15 @@ class DC_Gemini(DeviceController): } GEN2NAT_CMDS_MOUNT = GEN2NAT_CMDS_MOUNT_dict - GEN2NAT_CMDS_MOUNT = Gen2NatCmds(GEN2NAT_CMDS_MOUNT_obj).get_as_dict() + GEN2NAT_CMDS_MOUNT = GEN2NAT_CMDS_MOUNT_obj + GEN2NAT_CMDS_dict = { # My GENERAL commands - **GEN2NAT_CMDS_GENERAL, + **GEN2NAT_CMDS_GENERAL_dict, # SPECIFIC commands for my DCCs - 'DC_Mount' : GEN2NAT_CMDS_MOUNT + 'DC_Mount' : GEN2NAT_CMDS_MOUNT_dict } ''' GEN2NAT_CMDS_obj = [ @@ -593,8 +594,12 @@ class DC_Gemini(DeviceController): GEN2NAT_CMDS_MOUNT_obj ] ''' + GEN2NAT_CMDS_obj = Gen2NatCmds() + GEN2NAT_CMDS_obj.add_cmds(GEN2NAT_CMDS_GENERAL_obj) + GEN2NAT_CMDS_obj.add_cmds('DC_Mount', GEN2NAT_CMDS_MOUNT_obj) + GEN2NAT_CMDS = GEN2NAT_CMDS_dict - GEN2NAT_CMDS = my_cmds.get_as_dict() + GEN2NAT_CMDS = GEN2NAT_CMDS_obj.get_as_dict() # Utilisation, affichage #mes_commandes.add_cmd(get_ack) -- libgit2 0.21.2