File: v2.py

package info (click to toggle)
simplisafe-python 2024.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,268 kB
  • sloc: python: 5,252; sh: 50; makefile: 19
file content (79 lines) | stat: -rw-r--r-- 2,216 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""Define a v2 (old) SimpliSafe sensor."""
from typing import cast

from simplipy.device import Device, DeviceTypes
from simplipy.errors import SimplipyError


class SensorV2(Device):
    """A V2 (old) sensor.

    Note that this class shouldn't be instantiated directly; it will be
    instantiated as appropriate via :meth:`simplipy.API.async_get_systems`.
    """

    @property
    def data(self) -> int:
        """Return the sensor's current data flag (currently not understood).

        Returns:
            The current data flag.
        """
        return cast(int, self._system.sensor_data[self._serial]["sensorData"])

    @property
    def error(self) -> bool:
        """Return the sensor's error status.

        Returns:
            The current error status.
        """
        return cast(bool, self._system.sensor_data[self._serial]["error"])

    @property
    def low_battery(self) -> bool:
        """Return whether the sensor's battery is low.

        Returns:
            The current low battery status.
        """
        return cast(
            bool, self._system.sensor_data[self._serial].get("battery", "ok") != "ok"
        )

    @property
    def settings(self) -> bool:
        """Return the sensor's settings.

        Returns:
            The current settings.
        """
        return cast(bool, self._system.sensor_data[self._serial]["setting"])

    @property
    def trigger_instantly(self) -> bool:
        """Return whether the sensor will trigger instantly.

        Returns:
            The "instant trigger" settings.
        """
        return cast(bool, self._system.sensor_data[self._serial]["instant"])

    @property
    def triggered(self) -> bool:
        """Return whether the sensor has been triggered.

        Returns:
            The triggered status.

        Raises:
            SimplipyError: Raised when the state can't be determined.
        """
        if self.type == DeviceTypes.ENTRY:
            return cast(
                bool,
                self._system.sensor_data[self._serial].get("entryStatus", "closed")
                == "open",
            )

        raise SimplipyError(f"Cannot determine triggered state for sensor: {self.name}")