File: event.py

package info (click to toggle)
python-ring-doorbell 0.9.13-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 972 kB
  • sloc: python: 4,764; makefile: 14
file content (45 lines) | stat: -rw-r--r-- 1,035 bytes parent folder | download | duplicates (2)
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
"""Module for ring events."""

from __future__ import annotations

from dataclasses import dataclass
from typing import Any, NamedTuple


@dataclass
class RingEvent:
    """Class for ring events."""

    id: int
    doorbot_id: int
    device_name: str
    device_kind: str
    now: float
    expires_in: float
    kind: str
    state: str
    is_update: bool = False

    def __getitem__(self, key: str) -> Any:
        """Get a value by string."""
        return getattr(self, key)

    def get(self, key: str) -> Any | None:
        """Get a value by string and return None if not present."""
        return getattr(self, key) if hasattr(self, key) else None

    def get_key(self) -> RingEventKey:
        """Return the identificationkey for the event."""
        return RingEventKey(self.id, self.doorbot_id, self.kind, self.now)


class RingEventKey(NamedTuple):
    """Class to identify an event.

    Used for determining if messages are updates to events.
    """

    id: int
    doorbot_id: int
    kind: str
    now: float