def handleBatteryUpdate(item): device = Device.get_device(item['device_id']) if not device: device = Device(item['device_id'], item['recorded_at']) db.session.add(device) battery_status = item['data']['value'] recorded_at = item['recorded_at'] return device.update_battery_status(battery_status, recorded_at)
def handleLocationUpdate(item): device = Device.get_device(item['device_id']) if not device: device = Device(item['device_id'], item['recorded_at']) db.session.add(device) recorded_at = item['recorded_at'] data = item['data'] geometry = data['geometry'] location_type = geometry['type'] longitude = geometry['coordinates'][0] latitude = geometry['coordinates'][1] altitude = geometry['coordinates'][2] return device.update_location(location_type, longitude, latitude, altitude, recorded_at)
def handleDeviceUserUpdate(device_user, device_id): device = Device.get_device(device_id) if not device: raise Exception('This device id does not exist') return device.update_device_user(device_user)
def get(self, device_id): device = Device.get_device(device_id) return json.loads(device_schema.dumps(device)), 200