def on_update(self, did, msg): session = Session() device = session.query(Device).filter_by(id=did).first() if device: if device.user_configured: update = pickle.loads(msg[0]) device.interior_temp = update['interior_temp'] device.exterior_temp = update['exterior_temp'] session.commit() session.close() values = {'interior_temp': update['interior_temp'], 'exterior_temp': update['exterior_temp']} rrd = RRD(did, 'device') print(values) print(update['timestamp']) rrd.update(values, timestamp=update['timestamp']) return "updated" else: session.close() return 'device_unconfigured' else: session.close() return 'no_device' return
def update_grainbin_rrd(grainbin, bin_data): device_id = bin_data['grainbin_id'][:-3] grainbin_number = bin_data['bus_number'] values = {} for update in bin_data['data']: values[update['id']] = update['temperature'] sensor = next((x for x in grainbin.sensors if x.id == update['id'])) if sensor: sensor.last_value = update['temperature'] rrd = RRD(device_id, 'grainbin', service_number=grainbin_number) rrd.update(values, timestamp=bin_data['timestamp']) return