Skip to content

Sensor

Bases: Base

Represents a Sensor.

This ORM class represents a sensor along with its metadata.

Attributes:

Name Type Description
name

The name of the sensor

manufacturer

The name of the sensor's manufacturer

tags

dict attribute which represents any other tags which are not explicitly defined

Source code in edam/reader/models/sensor.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Sensor(Base):
    """
    Represents a Sensor.

    This ORM class represents a sensor along with its metadata.

    Attributes:
        name: The name of the sensor
        manufacturer: The name of the sensor's manufacturer
        tags: dict attribute which represents any other tags which are not
            explicitly defined
    """
    __tablename__ = "Sensor"
    id = Column(Integer, primary_key=True)
    name = Column(String(60))
    manufacturer = Column(String(60))
    _tags = Column('tags', String(500))

    abstract_observable_id = Column(
        Integer, ForeignKey('AbstractObservable.id'))
    abstract_observable = relationship("AbstractObservable",
                                       back_populates="sensors")

    junctions = relationship("Junction", back_populates="sensor")

    def update(self, new_values: dict):
        update_existing(self, new_values, logger)

    def __init__(self, name: str = None, manufacturer: str = None,
                 abstract_observable_id: int = None,
                 tags: dict = None):
        self.name = name
        self.manufacturer = manufacturer
        self.abstract_observable_id = abstract_observable_id
        self.tags = tags

    @hybrid_property
    def tags(self):
        return json.loads(self._tags)

    @tags.setter
    def tags(self, value):
        self._tags = json.dumps(value)

    def __repr__(self):
        return f'<{self.__class__.__name__} {self.name} with id {self.id!r}>'