def __load_sensors(self, data=None):
        # Load Sensors, with ID as index
        starttime = time.time()
        reloading = data is not None

        logger.info('%s terrariumPI sensors' %
                    ('Reloading' if reloading else 'Loading', ))

        sensor_config = (self.config.get_sensors() if not reloading else data)
        if not reloading:
            self.sensors = {}

        seen_sensors = []
        for sensor in terrariumSensor.scan(self.config.get_owfs_port(),
                                           self.get_temperature_indicator):
            self.sensors[sensor.get_id()] = sensor

        for sensordata in sensor_config:
            if sensordata['id'] is None or sensordata[
                    'id'] == 'None' or sensordata['id'] not in self.sensors:
                # New sensor (add)
                sensor = terrariumSensor(None, sensordata['hardwaretype'],
                                         sensordata['type'],
                                         sensordata['address'],
                                         sensordata['name'],
                                         self.get_temperature_indicator)

                self.sensors[sensor.get_id()] = sensor
            else:
                # Existing sensor
                sensor = self.sensors[sensordata['id']]
                # Should not be able to change setings
                #sensor.set_hardware_type(sensordata['hardwaretype'])
                sensor.set_type(sensordata['type'],
                                self.get_temperature_indicator)
                sensor.set_address(sensordata['address'])
                sensor.set_name(sensordata['name'])

            sensor.set_alarm_min(sensordata['alarm_min'])
            sensor.set_alarm_max(sensordata['alarm_max'])
            sensor.set_limit_min(sensordata['limit_min'])
            sensor.set_limit_max(sensordata['limit_max'])

            seen_sensors.append(sensor.get_id())

        if reloading:
            for sensor_id in set(self.sensors) - set(seen_sensors):
                # clean up old deleted sensors
                del (self.sensors[sensor_id])

            self.environment.set_sensors(self.sensors)

        logger.info(
            'Done %s terrariumPI sensors. Found %d sensors in %.3f seconds' %
            ('reloading' if reloading else 'loading', len(
                self.sensors), time.time() - starttime))
Exemple #2
0
  def __load_sensors(self,reloading = False):
    # Load Sensors, with ID as index
    starttime = time.time()
    logger.info('%s terrariumPI temperature/humidity sensors' % ('Reloading' if reloading else 'Loading'),)
    self.sensors = {}
    for sensor in terrariumSensor.scan(self.config.get_owfs_port(), self.config.get_sensors(), self.get_temperature_indicator):
      self.sensors[sensor.get_id()] = sensor

    if reloading:
      self.environment.set_sensors(self.sensors)

    logger.info('Done %s terrariumPI temperature/humidity sensors. Found %d sensors in %.3f seconds' % ('reloading' if reloading else 'loading',
                                                                                                        len(self.sensors),
                                                                                                        time.time()-starttime))
  def __init__(self):
    # List of queues for websocket communication
    self.subscribed_queues = []
    # Default power usage for a PI
    self.pi_power_wattage = 5

    self.switch_board = None #TODO: Fix proper
    self.environment = None

    # Load config
    self.config = terrariumConfig()
    self.set_authentication(self.config.get_admin(),self.config.get_password())

    # Load data collector for historical data
    self.collector = terrariumCollector()

    # Set the Pi power usage (including usb devices directly on the PI)
    self.pi_power_wattage = float(self.config.get_pi_power_wattage())

    # Load Weather part
    self.weather = terrariumWeather(self.config.get_weather_location(),
                                    self.config.get_weather_windspeed(),
                                    self.config.get_weather_temperature(),
                                    self.get_weather)

    # Load Powerswitches part
    self.power_switches = {}
    self.switch_board = terrariumSwitchboard(self.config,self.toggle_switch)
    self.power_switches = self.switch_board.switches

    # Load Door part
    self.door_sensor = terrariumDoor(self.config.get_door_pin(),self.door_status)

    # Load Sensors, with ID as index
    self.sensors = {}
    for sensor in terrariumSensor.scan(self.config.get_1wire_port(), self.config.get_sensors()):
      self.sensors[sensor.get_id()] = sensor

    # Load the environment system. This will controll the lights, sprayer and heaters
    self.environment = terrariumEnvironment(self.sensors, self.power_switches, self.door_sensor, self.weather, self.config)

    # Load webcams from config
    self.webcams = {}
    webcams = self.config.get_webcams()
    for webcamid in webcams:
      self.webcams[webcams[webcamid]['id']] = terrariumWebcam(webcams[webcamid]['id'],webcams[webcamid]['location'],webcams[webcamid]['name'],webcams[webcamid]['rotation'])

    # Start system update loop
    thread.start_new_thread(self.__engine_loop, ())