Esempio n. 1
0
    def __load_webcams(self, data=None):
        # Load Webcams, with ID as index
        starttime = time.time()
        reloading = data is not None

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

        webcam_config = (self.config.get_webcams() if not reloading else data)
        if not reloading:
            self.webcams = {}

        seen_webcams = []
        for webcamdata in webcam_config:
            if webcamdata['id'] is None or webcamdata[
                    'id'] == 'None' or webcamdata['id'] not in self.webcams:
                # New switch (add)
                width = 640
                height = 480
                archive = False
                if 'resolution_width' in webcamdata and 'resolution_height' in webcamdata:
                    width = webcamdata['resolution_width']
                    height = webcamdata['resolution_height']

                if 'archive' in webcamdata:
                    archive = webcamdata['archive']

                webcam = terrariumWebcam(None, webcamdata['location'],
                                         webcamdata['name'],
                                         webcamdata['rotation'], width, height,
                                         archive)
                self.webcams[webcam.get_id()] = webcam
            else:
                # Existing switch
                webcam = self.webcams[webcamdata['id']]
                # Should not be able to change setings
                #door.set_hardware_type(doordata['hardwaretype'])
                webcam.set_location(webcamdata['location'])
                webcam.set_name(webcamdata['name'])

            webcam.set_rotation(webcamdata['rotation'])

            if 'resolution_width' in webcamdata and 'resolution_height' in webcamdata:
                webcam.set_resolution(webcamdata['resolution_width'],
                                      webcamdata['resolution_height'])

            if 'archive' in webcamdata:
                webcam.set_archive(webcamdata['archive'])

            seen_webcams.append(webcam.get_id())

        if reloading:
            for webcam_id in set(self.webcams) - set(seen_webcams):
                # clean up old deleted switches
                del (self.webcams[webcam_id])

        logger.info(
            'Done %s terrariumPI webcams. Found %d webcams in %.3f seconds' %
            ('reloading' if reloading else 'loading', len(
                self.webcams), time.time() - starttime))
Esempio n. 2
0
  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, ())
Esempio n. 3
0
    def __load_webcams(self, reloading=False):
        # Load Webcams, with ID as index
        starttime = time.time()
        logger.info('%s terrariumPI webcams' %
                    ('Reloading' if reloading else 'Loading', ))
        webcams_config = self.config.get_webcams()
        self.webcams = {}
        for webcam_id in webcams_config:
            webcam = terrariumWebcam(webcams_config[webcam_id]['id'],
                                     webcams_config[webcam_id]['location'],
                                     webcams_config[webcam_id]['name'],
                                     webcams_config[webcam_id]['rotation'])
            self.webcams[webcam.get_id()] = webcam

        logger.info(
            'Done %s terrariumPI webcams. Found %d webcams in %.3f seconds' %
            ('reloading' if reloading else 'loading', len(
                self.webcams), time.time() - starttime))
Esempio n. 4
0
  def set_webcams_config(self, data):
    update_ok = True
    for webcamdata in data:

      if webcamdata['id'] == '' or webcamdata['id'] not in self.webcams:
        # Create new one
        if webcamdata['location'] != '':
          webcam = terrariumWebcam(None,webcamdata['location'],webcamdata['name'],webcamdata['rotation'])
          self.webcams[webcam.get_id()] = webcam
      else:
        webcam = self.webcams[webcamdata['id']]
        webcam.set_name(webcamdata['name'])
        webcam.set_location(webcamdata['location'])
        webcam.set_rotation(webcamdata['rotation'])

      update_ok = update_ok and self.config.save_webcam(webcam.get_data())

    return update_ok
Esempio n. 5
0
  def set_webcams_config(self, data):
    new_webcams = {}
    for webcamdata in data:
      if webcamdata['id'] is None or webcamdata['id'] == 'None' or webcamdata['id'] not in self.webcams:
        # New webcam (add)
        webcam = terrariumWebcam(None,webcamdata['location'],webcamdata['name'])
      else:
        # Existing webcam
        webcam = self.webcams[webcamdata['id']]

      webcam.set_location(webcamdata['location'])
      webcam.set_name(webcamdata['name'])
      webcam.set_rotation(webcamdata['rotation'])

      new_webcams[webcam.get_id()] = webcam

    self.webcams = new_webcams
    if self.config.save_webcams(self.webcams):
      self.__load_webcams(True)
      return True

    return False