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, ())
def set_switches_config(self, data): update_ok = True for switchdata in data: switch = self.power_switches[switchdata['id']] switch.set_name(switchdata['name']) switch.set_power_wattage(switchdata['power_wattage']) switch.set_water_flow(switchdata['water_flow']) update_ok = update_ok and self.config.save_switch(switch.get_data()) if update_ok: self.power_switches = {} self.switch_board = terrariumSwitchboard(self.config,self.toggle_switch) self.power_switches = self.switch_board.switches return update_ok