예제 #1
0
 def post(self, userId):
     data = json.loads(self.request.body.decode("utf-8"))
     sensor = Sensor(None, data['type'], 0, [])
     sensor.name = data['name']
     sensor.gis = (data['lat'], data['lng'])
     sensor_id = self.__sensors_repo.create(sensor)
     self.__users_repo.add_sensor_id(userId, str(sensor_id))
     self.set_status(201)
예제 #2
0
    def get_sensors(self) -> List[Sensor]:
        sensors_data = self.get(self.__REDIS_SENSORS_KEY)
        sensors = []
        for sensor_data in sensors_data:
            sensor = Sensor(sensor_data['id'], sensor_data['type'],
                            sensor_data['location'], sensor_data['value'])
            if 'name' in sensor_data:
                sensor.name = sensor_data['name']
            if 'communication_code' in sensor_data:
                sensor.communication_code = sensor_data['communication_code']
            else:
                sensor.communication_code = (False, False)
            if 'last_updated' in sensor_data:
                sensor.last_updated = sensor_data['last_updated']
            else:
                sensor.last_updated = 0
            sensors.append(sensor)

        return sensors