2021-06-01 18:31:50 -04:00
|
|
|
"""
|
|
|
|
Sensor module
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
2022-02-21 13:26:14 -05:00
|
|
|
Copyright © 2022 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
2021-06-01 18:31:50 -04:00
|
|
|
"""
|
2022-02-21 13:26:14 -05:00
|
|
|
import uuid
|
2021-06-01 18:31:50 -04:00
|
|
|
|
2022-02-21 13:26:14 -05:00
|
|
|
from city_model_structure.iot.sensor_measure import SensorMeasure
|
|
|
|
from city_model_structure.iot.sensor_type import SensorType
|
2021-06-09 14:23:45 -04:00
|
|
|
|
2021-06-01 19:03:55 -04:00
|
|
|
|
2021-06-01 18:31:50 -04:00
|
|
|
class Sensor:
|
2021-06-02 09:30:01 -04:00
|
|
|
"""
|
|
|
|
Sensor abstract class
|
|
|
|
"""
|
2022-02-21 13:26:14 -05:00
|
|
|
def __init__(self, sensor_id=None, model=None, sensor_type=None, indoor=False, board=None):
|
|
|
|
self._id = sensor_id
|
|
|
|
self._model = model
|
|
|
|
self._type = sensor_type
|
|
|
|
self._indoor = indoor
|
|
|
|
self._board = board
|
|
|
|
self._measures = []
|
2021-06-01 18:31:50 -04:00
|
|
|
|
|
|
|
@property
|
2022-02-21 13:26:14 -05:00
|
|
|
def id(self):
|
2021-06-01 18:31:50 -04:00
|
|
|
"""
|
2022-02-21 13:26:14 -05:00
|
|
|
Get the sensor id a random uuid will be assigned if no ID was provided to the constructor
|
|
|
|
:return: Id
|
2021-06-01 18:31:50 -04:00
|
|
|
"""
|
2022-02-21 13:26:14 -05:00
|
|
|
if self._id is None:
|
|
|
|
self._id = uuid.uuid4()
|
|
|
|
return self._id
|
2021-06-01 18:31:50 -04:00
|
|
|
|
|
|
|
@property
|
2022-02-21 13:26:14 -05:00
|
|
|
def type(self) -> SensorType:
|
2021-06-01 18:31:50 -04:00
|
|
|
"""
|
|
|
|
Get sensor type
|
2022-02-21 13:26:14 -05:00
|
|
|
:return: SensorTypeEnum or Error
|
2021-06-01 18:31:50 -04:00
|
|
|
"""
|
2022-02-21 13:26:14 -05:00
|
|
|
if self._type is None:
|
|
|
|
raise ValueError('Unknown sensor type')
|
2021-06-01 18:31:50 -04:00
|
|
|
return self._type
|
|
|
|
|
|
|
|
@property
|
2022-02-21 13:26:14 -05:00
|
|
|
def model(self):
|
2021-06-01 18:31:50 -04:00
|
|
|
"""
|
2022-02-21 13:26:14 -05:00
|
|
|
Get sensor model is any
|
|
|
|
:return: str or None
|
2021-06-01 18:31:50 -04:00
|
|
|
"""
|
2022-02-21 13:26:14 -05:00
|
|
|
return self._model
|
2021-06-01 18:31:50 -04:00
|
|
|
|
|
|
|
@property
|
2022-02-21 13:26:14 -05:00
|
|
|
def board(self):
|
2021-06-01 18:31:50 -04:00
|
|
|
"""
|
2022-02-21 13:26:14 -05:00
|
|
|
Get sensor board if any
|
|
|
|
:return: str or None
|
2021-06-01 18:31:50 -04:00
|
|
|
"""
|
2022-02-21 13:26:14 -05:00
|
|
|
return self._model
|
2021-06-01 18:31:50 -04:00
|
|
|
|
2022-02-21 13:26:14 -05:00
|
|
|
@property
|
|
|
|
def indoor(self):
|
2021-06-01 18:31:50 -04:00
|
|
|
"""
|
2022-02-21 13:26:14 -05:00
|
|
|
Get is the sensor it's located indoor or outdoor
|
|
|
|
:return: boolean
|
2021-06-01 18:31:50 -04:00
|
|
|
"""
|
2022-02-21 13:26:14 -05:00
|
|
|
return self._indoor
|
2021-06-01 18:31:50 -04:00
|
|
|
|
|
|
|
@property
|
2022-02-21 13:26:14 -05:00
|
|
|
def measures(self) -> [SensorMeasure]:
|
2021-08-26 09:19:38 -04:00
|
|
|
"""
|
2021-09-01 09:39:27 -04:00
|
|
|
Raises not implemented error
|
2021-08-26 09:19:38 -04:00
|
|
|
"""
|
2022-02-21 13:26:14 -05:00
|
|
|
return self._measures
|