示例#1
0
def meassure():
    """ Measures the FlowerDevices of all active GrowSessions. Waters if their
    water is under the WaterDevice threshhol.

    Returns:

    """
    if app.config['HARDWARE']:
        from app.hardware import flower_power
    result = []
    for grow_session in GrowSession.get_active():
        result += grow_session.flower_devices
    if len(result) == 0:
        print("Nothing to meassure")
        return
    for flower_device in result:
        if app.config['HARDWARE']:
            data = flower_power.get_flower_data(flower_device.mac)
        else:  # Mock data for development and testing.
            data = dict(Temperature=10.23, Light=100, Water=50.0, Battery=90, Ecb=0.5,
                        EcPorus=0.6, DLI=0.7, Ea=0.8, )
        flower_data = FlowerData.new_flower_data(data, flower_device.id, flower_device.grow_session.id)
        db.session.add(flower_data)
        db.session.commit()
        hub.new_data_point(flower_data)
        new_event("Meassure Flower_device " + flower_device.mac)
        # Check if we have to water.
        for water_device in flower_device.grow_session.water_devices:
            if data['Water'] < water_device.water_threshhold:  # Have to water.
                start_water(water_device.id)
    logging.getLogger().warning("Meassure completed")
示例#2
0
 def make_data_flower_data(self):
     self.db.session.add(GrowSession(name="grow_session", start_date=datetime.now()))
     grow_session = self.db.session.query(GrowSession).first()
     self.db.session.add(FlowerDevice(name="flower",
                                      mac="A0:14:3D:08:B4:90",
                                      grow_session_id=grow_session.id))
     flower_device = self.db.session.query(FlowerDevice).first()
     data = dict(Temperature=10.23, Light=100, Water=50.0, Battery=90, Ecb=0.5,
                 EcPorus=0.6, DLI=0.7, Ea=0.8, )
     self.db.session.add(FlowerData.new_flower_data(data, flower_device.id, flower_device.grow_session.id))
     self.db.session.commit()