Exemplo n.º 1
0
 def update_name(self, tx):
     new_name = input_with_cancel("  New name for sensor [{:s}]:".format(self.name))
     if new_name:
         self.name = new_name.strip()
     
     if self.name.lower() in ["agg", "aggregate", "mains", "whole_house",
                              "whole house", "wholehouse", "whole-house"]:
         self.agg_chan = True
     
     self.agg_chan = yes_no_cancel("  Is this an aggregate (whole-house) "
                                   " channel?", self.agg_chan)
     
     log_chan_list = tx.manager.get_log_chan_list()
     default_log_chan = self.log_chan if self.log_chan \
                        else tx.manager.next_free_log_chan()
     while True:
         new_log_chan = input_int_with_cancel(
                             "  New log channel or 0 to not log [{:d}]:"
                             .format(default_log_chan))
     
         if new_log_chan == "":
             self.log_chan = default_log_chan
             break
         else:
             if new_log_chan in log_chan_list:
                 print("  Log chan {:d} is already in use. "
                       "Please pick another.".format(new_log_chan))
             else:
                 self.log_chan = new_log_chan
                 break
 
     self.update_filename(tx)
    def update_name(self, detected_sensors=None):
        super(Cc_tx, self).update_name()
        print("Sensor type = TX")
        print("Sensor ID =", self.id)
        
        if self.sensors:
            default_sensor_list = self.sensors.keys()
        elif detected_sensors:
            default_sensor_list = [int(s) for s in detected_sensors.keys()]
            for s in detected_sensors:
                print("Sensor", s, "=", detected_sensors[s], "watts")
        else:
            default_sensor_list = [1]
        
        ask_the_question = True
        while ask_the_question:
            print("List the detected_sensors inputs used on this transmitter,"
                  " separated by a comma. Default="
                  , default_sensor_list, " : ", sep="", end="")
            
            sensor_list_str = input_with_cancel();
    
            if sensor_list_str == "":
                sensor_list = default_sensor_list
                ask_the_question = False
            else:
                sensor_list = []
                for s in sensor_list_str.split(","):
                    try:
                        s = int(s)
                    except:
                        print(s, "not a valid sensor list. Expected format: 1,2,3")
                        ask_the_question = True
                        break
                    else:
                        if s in Cc_tx.VALID_SENSOR_IDS:
                            sensor_list.append(int(s))
                            ask_the_question = False
                        else:
                            print(s, "is not a valid sensor number.")
                            ask_the_question = True
                            break

        for s in sensor_list:
            if s not in self.sensors.keys():
                self.sensors[s] = Sensor()
        
        for s in self.sensors:
            print("SENSOR", s, ":")
            self.sensors[s].update_name(self)