Beispiel #1
0
  def __upgrade_config(self,to_version):
    # Set minimal version to 3.0.0
    current_version = 300
    new_version = int(to_version.replace('.',''))
    if int(self.get_system()['version'].replace('.','')) >= current_version:
      current_version = int(self.get_system()['version'].replace('.',''))

    if not current_version < new_version:
      logger.info('Configuration is up to date')
    else:
      logger.info('Configuration is out of date. Running updates from %s to %s' % (current_version,new_version))
      for version in xrange(current_version+1,new_version+1):
        if version == 300:
          logger.info('Updating configuration file to version: %s' % (version,))
          # Upgrade: Move temperature indicator from weather to system
          temperature_indicator = self.__get_config('weather')
          if 'temperature' in temperature_indicator:
            self.__config.set('terrariumpi', 'temperature_indicator', str(temperature_indicator['temperature']))
            self.__config.remove_option('weather','temperature')

          # Upgrade: Change profile image path to new path and config location
          data = self.__get_config('terrariumpi')
          if 'image' in data and '/static/images/gecko.jpg' == data['image']:
            self.__config.set('profile', 'image', '/static/images/profile_image.jpg')
            self.__config.remove_option('terrariumpi','image')

          # Upgrade: Change profile name path to new config location
          data = self.__get_config('terrariumpi')
          if 'person' in data:
            self.__config.set('profile', 'name', data['person'])
            self.__config.remove_option('terrariumpi','person')

          # Upgrade: Remove default available languages variable
          data = self.__get_config('terrariumpi')
          if 'available_languages' in data:
            self.__config.remove_option('terrariumpi','available_languages')

        elif version == 310:
          logger.info('Updating configuration file to version: %s' % (version,))
          # Upgrade: Rename active_language to just language
          data = self.__get_config('terrariumpi')
          if 'active_language' in data:
            self.__config.set('terrariumpi', 'language', data['active_language'])
            self.__config.remove_option('terrariumpi','active_language')

          # Update the GPIO pinnumbering for PWM dimmers and DHT like sensors
          for section in self.__config.sections():
            if section[:6] == 'sensor':
              sensor_data = self.__get_config(section)
              if 'dht' in sensor_data['hardwaretype'] or 'am2302' == sensor_data['hardwaretype']:
                self.__config.set(section, 'address', str(terrariumUtils.to_BOARD_port_number(sensor_data['address'])))

            if section[:6] == 'switch':
              switch_data = self.__get_config(section)
              if 'pwm-dimmer' == switch_data['hardwaretype']:
                self.__config.set(section, 'address', str(terrariumUtils.to_BOARD_port_number(switch_data['address'])))

        elif version == 312:
          logger.info('Updating configuration file to version: %s' % (version,))
          data = self.__get_config('terrariumpi')
          if 'soundcard' in data and data['soundcard'] == '0':
            self.__config.set('terrariumpi', 'soundcard', 'bcm2835 ALSA')

      # Update version number
      self.__config.set('terrariumpi', 'version', str(to_version))
      self.__save_config()
      self.__config.read(terrariumConfig.CUSTOM_CONFIG)
      logger.info('Updated configuration. Set version to: %s' % (to_version,))
Beispiel #2
0
    def __upgrade_config(self, to_version):
        # Set minimal version to 3.0.0
        current_version = 300
        new_version = int(to_version.replace('.', ''))
        if int(self.get_system()['version'].replace('.',
                                                    '')) >= current_version:
            current_version = int(self.get_system()['version'].replace(
                '.', ''))

        if not current_version < new_version:
            logger.info('Configuration is up to date')
        else:
            logger.info(
                'Configuration is out of date. Running updates from %s to %s' %
                (current_version, new_version))
            for version in range(current_version + 1, new_version + 1):
                if version == 300:
                    logger.info('Updating configuration file to version: %s' %
                                (version, ))
                    # Upgrade: Move temperature indicator from weather to system
                    temperature_indicator = self.__get_config('weather')
                    if 'temperature' in temperature_indicator:
                        self.__config.set(
                            'terrariumpi', 'temperature_indicator',
                            str(temperature_indicator['temperature']))
                        self.__config.remove_option('weather', 'temperature')

                    # Upgrade: Change profile image path to new path and config location
                    data = self.__get_config('terrariumpi')
                    if 'image' in data and '/static/images/gecko.jpg' == data[
                            'image']:
                        self.__config.set('profile', 'image',
                                          '/static/images/profile_image.jpg')
                        self.__config.remove_option('terrariumpi', 'image')

                    # Upgrade: Change profile name path to new config location
                    data = self.__get_config('terrariumpi')
                    if 'person' in data:
                        self.__config.set('profile', 'name', data['person'])
                        self.__config.remove_option('terrariumpi', 'person')

                    # Upgrade: Remove default available languages variable
                    data = self.__get_config('terrariumpi')
                    if 'available_languages' in data:
                        self.__config.remove_option('terrariumpi',
                                                    'available_languages')

                elif version == 310:
                    logger.info('Updating configuration file to version: %s' %
                                (version, ))
                    # Upgrade: Rename active_language to just language
                    data = self.__get_config('terrariumpi')
                    if 'active_language' in data:
                        self.__config.set('terrariumpi', 'language',
                                          data['active_language'])
                        self.__config.remove_option('terrariumpi',
                                                    'active_language')

                    # Update the GPIO pinnumbering for PWM dimmers and DHT like sensors
                    for section in self.__config.sections():
                        if section[:6] == 'sensor':
                            sensor_data = self.__get_config(section)
                            if 'dht' in sensor_data[
                                    'hardwaretype'] or 'am2302' == sensor_data[
                                        'hardwaretype']:
                                self.__config.set(
                                    section, 'address',
                                    str(
                                        terrariumUtils.to_BOARD_port_number(
                                            sensor_data['address'])))

                        if section[:6] == 'switch':
                            switch_data = self.__get_config(section)
                            if 'pwm-dimmer' == switch_data['hardwaretype']:
                                self.__config.set(
                                    section, 'address',
                                    str(
                                        terrariumUtils.to_BOARD_port_number(
                                            switch_data['address'])))

                elif version == 312:
                    logger.info('Updating configuration file to version: %s' %
                                (version, ))
                    data = self.__get_config('terrariumpi')
                    if 'soundcard' in data and data['soundcard'] == '0':
                        self.__config.set('terrariumpi', 'soundcard',
                                          'bcm2835 ALSA')

                elif version == 330:
                    logger.info('Updating configuration file to version: %s' %
                                (version, ))
                    for section in self.__config.sections():
                        if section[:8] == 'playlist':
                            playlist_data = self.__get_config(section)
                            self.__config.set(
                                section, 'start',
                                str(
                                    datetime.datetime.fromtimestamp(
                                        float(
                                            playlist_data['start'])).strftime(
                                                '%H:%M')))
                            self.__config.set(
                                section, 'stop',
                                str(
                                    datetime.datetime.fromtimestamp(
                                        float(playlist_data['stop'])).strftime(
                                            '%H:%M')))

                        if section == 'environment':
                            environment_data = self.__get_config(section)
                            self.__config.set(
                                section, 'light_on',
                                str(
                                    datetime.datetime.fromtimestamp(
                                        float(environment_data['light_on'])).
                                    strftime('%H:%M')))
                            self.__config.set(
                                section, 'light_off',
                                str(
                                    datetime.datetime.fromtimestamp(
                                        float(environment_data['light_off'])).
                                    strftime('%H:%M')))
                            self.__config.set(
                                section, 'heater_on',
                                str(
                                    datetime.datetime.fromtimestamp(
                                        float(environment_data['heater_on'])).
                                    strftime('%H:%M')))
                            self.__config.set(
                                section, 'heater_off',
                                str(
                                    datetime.datetime.fromtimestamp(
                                        float(environment_data['heater_off'])).
                                    strftime('%H:%M')))
                            self.__config.set(
                                section, 'cooler_on',
                                str(
                                    datetime.datetime.fromtimestamp(
                                        float(environment_data['cooler_on'])).
                                    strftime('%H:%M')))
                            self.__config.set(
                                section, 'cooler_off',
                                str(
                                    datetime.datetime.fromtimestamp(
                                        float(environment_data['cooler_off'])).
                                    strftime('%H:%M')))

                elif version == 351:
                    logger.info('Updating configuration file to version: %s' %
                                (version, ))
                    for section in self.__config.sections():
                        if section[:6] == 'webcam':
                            data = self.__get_config(section)
                            if 'archive' in data:
                                self.__config.set(
                                    section, 'archive',
                                    'motion' if terrariumUtils.is_true(
                                        data['archive']) else 'disabled')

                elif version == 360:
                    logger.info('Updating configuration file to version: %s' %
                                (version, ))
                    for section in self.__config.sections():
                        if section == 'environment':
                            data = self.__get_config(section)
                            newdata = {}

                            if 'temperature_mode' not in newdata:
                                newdata[
                                    'temperature_mode'] = 'weatherinverse' if data[
                                        'cooler_mode'] == 'weather' else data[
                                            'cooler_mode']

                            if 'cooler_night_difference' in data:
                                newdata[
                                    'temperature_day_night_difference'] = data[
                                        'cooler_night_difference']
                            if 'cooler_night_source' in data:
                                newdata['temperature_day_night_source'] = data[
                                    'cooler_night_source']
                            if 'cooler_sensors' in data:
                                newdata['temperature_sensors'] = data[
                                    'cooler_sensors']

                            if 'cooler_night_enabled' in data:
                                newdata[
                                    'temperature_alarm_max_light_state'] = 'ignore' if terrariumUtils.is_true(
                                        data['cooler_night_enabled']) else 'on'

                            if 'cooler_power_switches' in data:
                                newdata[
                                    'temperature_alarm_max_powerswitches'] = data[
                                        'cooler_power_switches']

                            if 'cooler_settle_timeout' in data:
                                newdata['temperature_alarm_max_settle'] = data[
                                    'cooler_settle_timeout']

                            if 'cooler_off_duration' in data:
                                newdata[
                                    'temperature_alarm_max_timer_off'] = data[
                                        'cooler_off_duration']

                            if 'cooler_on_duration' in data:
                                newdata[
                                    'temperature_alarm_max_timer_on'] = data[
                                        'cooler_on_duration']

                            if 'cooler_on' in data:
                                newdata[
                                    'temperature_alarm_max_timer_start'] = data[
                                        'cooler_on']

                            if 'cooler_off' in data:
                                newdata[
                                    'temperature_alarm_max_timer_stop'] = data[
                                        'cooler_off']

                            if 'temperature_mode' not in newdata or 'disabled' == newdata[
                                    'temperature_mode']:
                                newdata[
                                    'temperature_mode'] = 'weatherinverse' if data[
                                        'heater_mode'] == 'weather' else data[
                                            'heater_mode']

                            if 'heater_night_difference' in data:
                                if 'temperature_day_night_difference' in newdata and terrariumUtils.is_float(
                                        newdata[
                                            'temperature_day_night_difference']
                                ):
                                    newdata['temperature_day_night_difference'] = (
                                        float(newdata[
                                            'temperature_day_night_difference']
                                              ) +
                                        float(data['heater_night_difference'])
                                    ) / 2.0
                                else:
                                    newdata[
                                        'temperature_day_night_difference'] = data[
                                            'heater_night_difference']

                            if 'heater_night_source' in data and (
                                    'temperature_day_night_source'
                                    not in newdata
                                    or newdata['temperature_day_night_source']
                                    == ''):
                                newdata['temperature_day_night_source'] = data[
                                    'heater_night_source']

                            if 'heater_sensors' in data:
                                if 'temperature_sensors' in newdata and newdata[
                                        'temperature_sensors'] != '':
                                    newdata[
                                        'temperature_sensors'] += ',' + data[
                                            'heater_sensors']
                                else:
                                    newdata['temperature_sensors'] = data[
                                        'heater_sensors']

                            if 'heater_day_enabled' in data:
                                newdata[
                                    'temperature_alarm_min_light_state'] = 'ignore' if terrariumUtils.is_true(
                                        data['heater_day_enabled']) else 'off'

                            if 'heater_power_switches' in data:
                                newdata[
                                    'temperature_alarm_min_powerswitches'] = data[
                                        'heater_power_switches']

                            if 'heater_settle_timeout' in data:
                                newdata['temperature_alarm_min_settle'] = data[
                                    'heater_settle_timeout']

                            if 'heater_off_duration' in data:
                                newdata[
                                    'temperature_alarm_min_timer_off'] = data[
                                        'heater_off_duration']

                            if 'heater_on_duration' in data:
                                newdata[
                                    'temperature_alarm_min_timer_on'] = data[
                                        'heater_on_duration']

                            if 'heater_on' in data:
                                newdata[
                                    'temperature_alarm_min_timer_start'] = data[
                                        'heater_on']

                            if 'heater_off' in data:
                                newdata[
                                    'temperature_alarm_min_timer_stop'] = data[
                                        'heater_off']

                            if 'light_mode' in data:
                                newdata['light_mode'] = data['light_mode']

                            if 'light_min_hours' in data:
                                newdata['light_min_hours'] = data[
                                    'light_min_hours']

                            if 'light_max_hours' in data:
                                newdata['light_max_hours'] = data[
                                    'light_max_hours']

                            if 'light_hours_shift' in data:
                                newdata['light_hours_shift'] = data[
                                    'light_hours_shift']

                            if 'light_power_switches' in data:
                                newdata[
                                    'light_alarm_min_powerswitches'] = data[
                                        'light_power_switches']

                            if 'light_on' in data:
                                newdata['light_alarm_min_timer_start'] = data[
                                    'light_on']

                            if 'light_off' in data:
                                newdata['light_alarm_min_timer_stop'] = data[
                                    'light_off']

                            if 'light_on_duration' in data:
                                newdata['light_alarm_min_timer_on'] = data[
                                    'light_on_duration']

                            if 'light_off_duration' in data:
                                newdata['light_alarm_min_timer_off'] = data[
                                    'light_off_duration']

                            newdata['light_alarm_min_settle'] = 10
                            newdata['light_alarm_max_settle'] = 10

                            if 'moisture_mode' in data:
                                newdata['moisture_mode'] = data[
                                    'moisture_mode']

                            if 'moisture_sensors' in data:
                                newdata['moisture_sensors'] = data[
                                    'moisture_sensors']

                            if 'moisture_power_switches' in data:
                                newdata[
                                    'moisture_alarm_min_powerswitches'] = data[
                                        'moisture_power_switches']

                            if 'moisture_on' in data:
                                newdata[
                                    'moisture_alarm_min_timer_start'] = data[
                                        'moisture_on']

                            if 'moisture_off' in data:
                                newdata[
                                    'moisture_alarm_min_timer_stop'] = data[
                                        'moisture_off']

                            if 'moisture_on_duration' in data:
                                newdata['moisture_alarm_min_timer_on'] = data[
                                    'moisture_on_duration']

                            if 'moisture_off_duration' in data:
                                newdata['moisture_alarm_min_timer_off'] = data[
                                    'moisture_off_duration']

                            if 'moisture_spray_duration' in data:
                                newdata[
                                    'moisture_alarm_min_duration_on'] = data[
                                        'moisture_spray_duration']

                            if 'moisture_spray_timeout' in data:
                                newdata['moisture_alarm_min_settle'] = data[
                                    'moisture_spray_timeout']

                            if 'moisture_night_enabled' in data:
                                newdata[
                                    'moisture_alarm_min_light_state'] = 'ignore' if terrariumUtils.is_true(
                                        data['moisture_night_enabled']
                                    ) else 'on'

                            if 'ph_mode' in data:
                                newdata['ph_mode'] = data['ph_mode']

                            if 'ph_sensors' in data:
                                newdata['ph_sensors'] = data['ph_sensors']

                            if 'ph_power_switches' in data:
                                newdata['ph_alarm_min_powerswitches'] = data[
                                    'ph_power_switches']

                            if 'ph_on' in data:
                                newdata['ph_alarm_min_timer_start'] = data[
                                    'ph_on']

                            if 'ph_off' in data:
                                newdata['ph_alarm_min_timer_stop'] = data[
                                    'ph_off']

                            if 'ph_on_duration' in data:
                                newdata['ph_alarm_min_timer_on'] = data[
                                    'ph_on_duration']

                            if 'ph_off_duration' in data:
                                newdata['ph_alarm_min_timer_off'] = data[
                                    'ph_off_duration']

                            if 'ph_settle_timeout' in data:
                                newdata['ph_alarm_min_settle'] = data[
                                    'ph_settle_timeout']

                            if 'ph_day_enabled' in data:
                                newdata[
                                    'ph_alarm_min_light_state'] = 'ignore' if terrariumUtils.is_true(
                                        data['ph_day_enabled']) else 'on'

                            if 'sprayer_mode' in data:
                                newdata['humidity_mode'] = data['sprayer_mode']

                            if 'sprayer_sensors' in data:
                                newdata['humidity_sensors'] = data[
                                    'sprayer_sensors']

                            if 'sprayer_power_switches' in data:
                                newdata[
                                    'humidity_alarm_min_powerswitches'] = data[
                                        'sprayer_power_switches']

                            if 'sprayer_on' in data:
                                newdata[
                                    'humidity_alarm_min_timer_start'] = data[
                                        'sprayer_on']

                            if 'sprayer_off' in data:
                                newdata[
                                    'humidity_alarm_min_timer_stop'] = data[
                                        'sprayer_off']

                            if 'sprayer_on_duration' in data:
                                newdata['humidity_alarm_min_timer_on'] = data[
                                    'sprayer_on_duration']

                            if 'sprayer_off_duration' in data:
                                newdata['humidity_alarm_min_timer_off'] = data[
                                    'sprayer_off_duration']

                            if 'sprayer_spray_duration' in data:
                                newdata[
                                    'humidity_alarm_min_duration_on'] = data[
                                        'sprayer_spray_duration']

                            if 'sprayer_spray_timeout' in data:
                                newdata['humidity_alarm_min_settle'] = data[
                                    'sprayer_spray_timeout']

                            if 'sprayer_night_enabled' in data:
                                newdata[
                                    'humidity_alarm_min_light_state'] = 'ignore' if terrariumUtils.is_true(
                                        data['sprayer_night_enabled']
                                    ) else 'on'

                            newdata['humidity_alarm_min_door_state'] = 'closed'

                            if 'watertank_mode' in data:
                                newdata['watertank_mode'] = data[
                                    'watertank_mode']

                            if 'watertank_sensors' in data:
                                newdata['watertank_sensors'] = data[
                                    'watertank_sensors']

                            if 'watertank_height' in data:
                                newdata['watertank_height'] = data[
                                    'watertank_height']

                            if 'watertank_volume' in data:
                                newdata['watertank_volume'] = data[
                                    'watertank_volume']

                            if 'watertank_power_switches' in data:
                                newdata[
                                    'watertank_alarm_min_powerswitches'] = data[
                                        'watertank_power_switches']

                            if 'watertank_on' in data:
                                newdata[
                                    'watertank_alarm_min_timer_start'] = data[
                                        'watertank_on']

                            if 'watertank_off' in data:
                                newdata[
                                    'watertank_alarm_min_timer_stop'] = data[
                                        'watertank_off']

                            if 'watertank_on_duration' in data:
                                newdata['watertank_alarm_min_timer_on'] = data[
                                    'watertank_on_duration']

                            if 'watertank_off_duration' in data:
                                newdata[
                                    'watertank_alarm_min_timer_off'] = data[
                                        'watertank_off_duration']

                            if 'watertank_pump_duration' in data:
                                newdata[
                                    'watertank_alarm_min_duration_on'] = data[
                                        'watertank_pump_duration']

                            self.save_environment(newdata)
                            break

                elif version == 385:
                    logger.info('Updating configuration file to version: %s' %
                                (version, ))

                    windspeed_indicator = self.__get_config('weather').get(
                        'windspeed')
                    if windspeed_indicator is None:
                        windspeed_indicator = self.__get_config(
                            'terrariumpi').get('windspeed_indicator')
                        if windspeed_indicator is None:
                            windspeed_indicator = 'kmh'

                    self.__config.set('terrariumpi', 'windspeed_indicator',
                                      windspeed_indicator)
                    self.__config.remove_option('weather', 'windspeed')

                elif version == 393:
                    logger.info('Updating configuration file to version: %s' %
                                (version, ))
                    # Only change IDs of sensors that can be scanned
                    collector_update_sql = ''
                    sensor_rename_list = {}
                    for section in self.__config.sections():
                        if section[:6] == 'sensor':
                            data = self.__get_config(section)
                            if data['hardwaretype'] in [
                                    'w1', 'owfs', 'miflora'
                            ]:
                                old_id = data['id']
                                new_id = md5(
                                    (data['hardwaretype'] + data['address'] +
                                     data['type']).encode()).hexdigest()

                                if old_id != new_id:
                                    if old_id not in sensor_rename_list:
                                        sensor_rename_list[old_id] = new_id

                                    data['id'] = new_id
                                    new_section = 'sensor' + new_id
                                    if not self.__config.has_section(
                                            new_section):
                                        self.__config.add_section(new_section)

                                    keys = list(data.keys())
                                    keys.sort()
                                    for setting in keys:
                                        if setting in ['firmware', 'battery']:
                                            continue

                                        self.__config.set(
                                            new_section, str(setting),
                                            str(data[setting]))

                                    # Clear any existing new data (should not happen)
                                    collector_update_sql += 'DELETE FROM sensor_data WHERE id = \'{}\';\n'.format(
                                        new_id)
                                    # Rename the sensor ID in the database
                                    collector_update_sql += 'UPDATE sensor_data SET id = \'{}\' WHERE id = \'{}\';\n'.format(
                                        new_id, old_id)

                                    self.__config.remove_section(section)

                    # Update environment sensor settings
                    environment = self.__get_config('environment')
                    keys = list(environment.keys())
                    for setting in keys:
                        if '_sensors' in setting:
                            for old_id in sensor_rename_list:
                                environment[setting] = environment[
                                    setting].replace(
                                        old_id, sensor_rename_list[old_id])

                            self.__config.set('environment', str(setting),
                                              str(environment[setting]))

                    if '' != collector_update_sql:
                        config_ok = self.__save_config()
                        if config_ok:
                            self.__reload_config()

                            with open(
                                    '.collector.update.{}.sql'.format(version),
                                    'w') as sql_file:
                                sql_file.write(collector_update_sql.strip())

            # Update version number
            self.__config.set('terrariumpi', 'version', str(to_version))
            self.__save_config()
            self.__config.read(terrariumConfig.CUSTOM_CONFIG)
            logger.info('Updated configuration. Set version to: %s' %
                        (to_version, ))
Beispiel #3
0
  def __upgrade_config(self,to_version):
    # Set minimal version to 3.0.0
    current_version = 300
    new_version = int(to_version.replace('.',''))
    if int(self.get_system()['version'].replace('.','')) >= current_version:
      current_version = int(self.get_system()['version'].replace('.',''))

    if not current_version < new_version:
      logger.info('Configuration is up to date')
    else:
      logger.info('Configuration is out of date. Running updates from %s to %s' % (current_version,new_version))
      for version in range(current_version+1,new_version+1):
        if version == 300:
          logger.info('Updating configuration file to version: %s' % (version,))
          # Upgrade: Move temperature indicator from weather to system
          temperature_indicator = self.__get_config('weather')
          if 'temperature' in temperature_indicator:
            self.__config.set('terrariumpi', 'temperature_indicator', str(temperature_indicator['temperature']))
            self.__config.remove_option('weather','temperature')

          # Upgrade: Change profile image path to new path and config location
          data = self.__get_config('terrariumpi')
          if 'image' in data and '/static/images/gecko.jpg' == data['image']:
            self.__config.set('profile', 'image', '/static/images/profile_image.jpg')
            self.__config.remove_option('terrariumpi','image')

          # Upgrade: Change profile name path to new config location
          data = self.__get_config('terrariumpi')
          if 'person' in data:
            self.__config.set('profile', 'name', data['person'])
            self.__config.remove_option('terrariumpi','person')

          # Upgrade: Remove default available languages variable
          data = self.__get_config('terrariumpi')
          if 'available_languages' in data:
            self.__config.remove_option('terrariumpi','available_languages')

        elif version == 310:
          logger.info('Updating configuration file to version: %s' % (version,))
          # Upgrade: Rename active_language to just language
          data = self.__get_config('terrariumpi')
          if 'active_language' in data:
            self.__config.set('terrariumpi', 'language', data['active_language'])
            self.__config.remove_option('terrariumpi','active_language')

          # Update the GPIO pinnumbering for PWM dimmers and DHT like sensors
          for section in self.__config.sections():
            if section[:6] == 'sensor':
              sensor_data = self.__get_config(section)
              if 'dht' in sensor_data['hardwaretype'] or 'am2302' == sensor_data['hardwaretype']:
                self.__config.set(section, 'address', str(terrariumUtils.to_BOARD_port_number(sensor_data['address'])))

            if section[:6] == 'switch':
              switch_data = self.__get_config(section)
              if 'pwm-dimmer' == switch_data['hardwaretype']:
                self.__config.set(section, 'address', str(terrariumUtils.to_BOARD_port_number(switch_data['address'])))

        elif version == 312:
          logger.info('Updating configuration file to version: %s' % (version,))
          data = self.__get_config('terrariumpi')
          if 'soundcard' in data and data['soundcard'] == '0':
            self.__config.set('terrariumpi', 'soundcard', 'bcm2835 ALSA')

        elif version == 330:
          logger.info('Updating configuration file to version: %s' % (version,))
          for section in self.__config.sections():
            if section[:8] == 'playlist':
              playlist_data = self.__get_config(section)
              self.__config.set(section, 'start', str(datetime.datetime.fromtimestamp(float(playlist_data['start'])).strftime('%H:%M')))
              self.__config.set(section, 'stop',  str(datetime.datetime.fromtimestamp(float(playlist_data['stop'])).strftime('%H:%M')))

            if section == 'environment':
              environment_data = self.__get_config(section)
              self.__config.set(section, 'light_on',  str(datetime.datetime.fromtimestamp(float(environment_data['light_on'])).strftime('%H:%M')))
              self.__config.set(section, 'light_off', str(datetime.datetime.fromtimestamp(float(environment_data['light_off'])).strftime('%H:%M')))
              self.__config.set(section, 'heater_on',  str(datetime.datetime.fromtimestamp(float(environment_data['heater_on'])).strftime('%H:%M')))
              self.__config.set(section, 'heater_off', str(datetime.datetime.fromtimestamp(float(environment_data['heater_off'])).strftime('%H:%M')))
              self.__config.set(section, 'cooler_on',  str(datetime.datetime.fromtimestamp(float(environment_data['cooler_on'])).strftime('%H:%M')))
              self.__config.set(section, 'cooler_off', str(datetime.datetime.fromtimestamp(float(environment_data['cooler_off'])).strftime('%H:%M')))

        elif version == 351:
          logger.info('Updating configuration file to version: %s' % (version,))
          for section in self.__config.sections():
            if section[:6] == 'webcam':
              data = self.__get_config(section)
              if 'archive' in data:
                self.__config.set(section, 'archive', 'motion' if terrariumUtils.is_true(data['archive']) else 'disabled')

        elif version == 360:
          logger.info('Updating configuration file to version: %s' % (version,))
          for section in self.__config.sections():
            if section == 'environment':
              data = self.__get_config(section)
              newdata = {}

              if 'temperature_mode' not in newdata:
                newdata['temperature_mode'] = 'weatherinverse' if data['cooler_mode'] == 'weather' else data['cooler_mode']

              if 'cooler_night_difference' in data:
                newdata['temperature_day_night_difference'] = data['cooler_night_difference']
              if 'cooler_night_source' in data:
                newdata['temperature_day_night_source'] = data['cooler_night_source']
              if 'cooler_sensors' in data:
                newdata['temperature_sensors'] = data['cooler_sensors']

              if 'cooler_night_enabled' in data:
                newdata['temperature_alarm_max_light_state'] = 'ignore' if terrariumUtils.is_true(data['cooler_night_enabled']) else 'on'

              if 'cooler_power_switches' in data:
                newdata['temperature_alarm_max_powerswitches'] = data['cooler_power_switches']

              if 'cooler_settle_timeout' in data:
                newdata['temperature_alarm_max_settle'] = data['cooler_settle_timeout']

              if 'cooler_off_duration' in data:
                newdata['temperature_alarm_max_timer_off'] = data['cooler_off_duration']

              if 'cooler_on_duration' in data:
                newdata['temperature_alarm_max_timer_on'] = data['cooler_on_duration']

              if 'cooler_on' in data:
                newdata['temperature_alarm_max_timer_start'] = data['cooler_on']

              if 'cooler_off' in data:
                newdata['temperature_alarm_max_timer_stop'] = data['cooler_off']


              if 'temperature_mode' not in newdata or 'disabled' == newdata['temperature_mode']:
                newdata['temperature_mode'] = 'weatherinverse' if data['heater_mode'] == 'weather' else data['heater_mode']

              if 'heater_night_difference' in data:
                if 'temperature_day_night_difference' in newdata and terrariumUtils.is_float(newdata['temperature_day_night_difference']):
                  newdata['temperature_day_night_difference'] = (float(newdata['temperature_day_night_difference']) + float(data['heater_night_difference'])) / 2.0
                else:
                  newdata['temperature_day_night_difference'] = data['heater_night_difference']

              if 'heater_night_source' in data and ('temperature_day_night_source' not in newdata or newdata['temperature_day_night_source'] == ''):
                newdata['temperature_day_night_source'] = data['heater_night_source']

              if 'heater_sensors' in data:
                if 'temperature_sensors' in newdata and newdata['temperature_sensors'] != '':
                  newdata['temperature_sensors'] += ',' + data['heater_sensors']
                else:
                  newdata['temperature_sensors'] = data['heater_sensors']

              if 'heater_day_enabled' in data:
                newdata['temperature_alarm_min_light_state'] = 'ignore' if terrariumUtils.is_true(data['heater_day_enabled']) else 'off'

              if 'heater_power_switches' in data:
                newdata['temperature_alarm_min_powerswitches'] = data['heater_power_switches']

              if 'heater_settle_timeout' in data:
                newdata['temperature_alarm_min_settle'] = data['heater_settle_timeout']

              if 'heater_off_duration' in data:
                newdata['temperature_alarm_min_timer_off'] = data['heater_off_duration']

              if 'heater_on_duration' in data:
                newdata['temperature_alarm_min_timer_on'] = data['heater_on_duration']

              if 'heater_on' in data:
                newdata['temperature_alarm_min_timer_start'] = data['heater_on']

              if 'heater_off' in data:
                newdata['temperature_alarm_min_timer_stop'] = data['heater_off']


              if 'light_mode' in data:
                newdata['light_mode'] = data['light_mode']

              if 'light_min_hours' in data:
                newdata['light_min_hours'] = data['light_min_hours']

              if 'light_max_hours' in data:
                newdata['light_max_hours'] = data['light_max_hours']

              if 'light_hours_shift' in data:
                newdata['light_hours_shift'] = data['light_hours_shift']

              if 'light_power_switches' in data:
                newdata['light_alarm_min_powerswitches'] = data['light_power_switches']

              if 'light_on' in data:
                newdata['light_alarm_min_timer_start'] = data['light_on']

              if 'light_off' in data:
                newdata['light_alarm_min_timer_stop'] = data['light_off']

              if 'light_on_duration' in data:
                newdata['light_alarm_min_timer_on'] = data['light_on_duration']

              if 'light_off_duration' in data:
                newdata['light_alarm_min_timer_off'] = data['light_off_duration']

              newdata['light_alarm_min_settle'] = 10
              newdata['light_alarm_max_settle'] = 10


              if 'moisture_mode' in data:
                newdata['moisture_mode'] = data['moisture_mode']

              if 'moisture_sensors' in data:
                newdata['moisture_sensors'] = data['moisture_sensors']

              if 'moisture_power_switches' in data:
                newdata['moisture_alarm_min_powerswitches'] = data['moisture_power_switches']

              if 'moisture_on' in data:
                newdata['moisture_alarm_min_timer_start'] = data['moisture_on']

              if 'moisture_off' in data:
                newdata['moisture_alarm_min_timer_stop'] = data['moisture_off']

              if 'moisture_on_duration' in data:
                newdata['moisture_alarm_min_timer_on'] = data['moisture_on_duration']

              if 'moisture_off_duration' in data:
                newdata['moisture_alarm_min_timer_off'] = data['moisture_off_duration']

              if 'moisture_spray_duration' in data:
                newdata['moisture_alarm_min_duration_on'] = data['moisture_spray_duration']

              if 'moisture_spray_timeout' in data:
                newdata['moisture_alarm_min_settle'] = data['moisture_spray_timeout']

              if 'moisture_night_enabled' in data:
                newdata['moisture_alarm_min_light_state'] = 'ignore' if terrariumUtils.is_true(data['moisture_night_enabled']) else 'on'


              if 'ph_mode' in data:
                newdata['ph_mode'] = data['ph_mode']

              if 'ph_sensors' in data:
                newdata['ph_sensors'] = data['ph_sensors']

              if 'ph_power_switches' in data:
                newdata['ph_alarm_min_powerswitches'] = data['ph_power_switches']

              if 'ph_on' in data:
                newdata['ph_alarm_min_timer_start'] = data['ph_on']

              if 'ph_off' in data:
                newdata['ph_alarm_min_timer_stop'] = data['ph_off']

              if 'ph_on_duration' in data:
                newdata['ph_alarm_min_timer_on'] = data['ph_on_duration']

              if 'ph_off_duration' in data:
                newdata['ph_alarm_min_timer_off'] = data['ph_off_duration']

              if 'ph_settle_timeout' in data:
                newdata['ph_alarm_min_settle'] = data['ph_settle_timeout']

              if 'ph_day_enabled' in data:
                newdata['ph_alarm_min_light_state'] = 'ignore' if terrariumUtils.is_true(data['ph_day_enabled']) else 'on'


              if 'sprayer_mode' in data:
                newdata['humidity_mode'] = data['sprayer_mode']

              if 'sprayer_sensors' in data:
                newdata['humidity_sensors'] = data['sprayer_sensors']

              if 'sprayer_power_switches' in data:
                newdata['humidity_alarm_min_powerswitches'] = data['sprayer_power_switches']

              if 'sprayer_on' in data:
                newdata['humidity_alarm_min_timer_start'] = data['sprayer_on']

              if 'sprayer_off' in data:
                newdata['humidity_alarm_min_timer_stop'] = data['sprayer_off']

              if 'sprayer_on_duration' in data:
                newdata['humidity_alarm_min_timer_on'] = data['sprayer_on_duration']

              if 'sprayer_off_duration' in data:
                newdata['humidity_alarm_min_timer_off'] = data['sprayer_off_duration']

              if 'sprayer_spray_duration' in data:
                newdata['humidity_alarm_min_duration_on'] = data['sprayer_spray_duration']

              if 'sprayer_spray_timeout' in data:
                newdata['humidity_alarm_min_settle'] = data['sprayer_spray_timeout']

              if 'sprayer_night_enabled' in data:
                newdata['humidity_alarm_min_light_state'] = 'ignore' if terrariumUtils.is_true(data['sprayer_night_enabled']) else 'on'

              newdata['humidity_alarm_min_door_state'] = 'closed'


              if 'watertank_mode' in data:
                newdata['watertank_mode'] = data['watertank_mode']

              if 'watertank_sensors' in data:
                newdata['watertank_sensors'] = data['watertank_sensors']

              if 'watertank_height' in data:
                newdata['watertank_height'] = data['watertank_height']

              if 'watertank_volume' in data:
                newdata['watertank_volume'] = data['watertank_volume']

              if 'watertank_power_switches' in data:
                newdata['watertank_alarm_min_powerswitches'] = data['watertank_power_switches']

              if 'watertank_on' in data:
                newdata['watertank_alarm_min_timer_start'] = data['watertank_on']

              if 'watertank_off' in data:
                newdata['watertank_alarm_min_timer_stop'] = data['watertank_off']

              if 'watertank_on_duration' in data:
                newdata['watertank_alarm_min_timer_on'] = data['watertank_on_duration']

              if 'watertank_off_duration' in data:
                newdata['watertank_alarm_min_timer_off'] = data['watertank_off_duration']

              if 'watertank_pump_duration' in data:
                newdata['watertank_alarm_min_duration_on'] = data['watertank_pump_duration']

              self.save_environment(newdata)
              break

        elif version == 385:
          logger.info('Updating configuration file to version: %s' % (version,))

          windspeed_indicator = self.__get_config('weather').get('windspeed')
          if windspeed_indicator is None:
            windspeed_indicator = self.__get_config('terrariumpi').get('windspeed_indicator')
            if windspeed_indicator is None:
                windspeed_indicator = 'kmh'

          self.__config.set('terrariumpi', 'windspeed_indicator',  windspeed_indicator)
          self.__config.remove_option('weather','windspeed')

      # Update version number
      self.__config.set('terrariumpi', 'version', str(to_version))
      self.__save_config()
      self.__config.read(terrariumConfig.CUSTOM_CONFIG)
      logger.info('Updated configuration. Set version to: %s' % (to_version,))