• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sdb9696 / python-ring-doorbell / 6148597193

11 Sep 2023 03:29PM UTC coverage: 66.139%. First build
6148597193

push

github

sdb9696
Add motion detection enabled switch

33 of 33 new or added lines in 4 files covered. (100.0%)

418 of 632 relevant lines covered (66.14%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.01
/ring_doorbell/stickup_cam.py
1
# coding: utf-8
2
# vim:sw=4:ts=4:et:
3
"""Python Ring Doorbell wrapper."""
1✔
4
import logging
1✔
5

6
from ring_doorbell import RingDoorBell
1✔
7
from ring_doorbell.const import (
1✔
8
    LIGHTS_ENDPOINT,
9
    MSG_ALLOWED_VALUES,
10
    MSG_VOL_OUTBOUND,
11
    FLOODLIGHT_CAM_KINDS,
12
    FLOODLIGHT_CAM_PRO_KINDS,
13
    INDOOR_CAM_KINDS,
14
    SPOTLIGHT_CAM_BATTERY_KINDS,
15
    SPOTLIGHT_CAM_WIRED_KINDS,
16
    STICKUP_CAM_KINDS,
17
    STICKUP_CAM_BATTERY_KINDS,
18
    STICKUP_CAM_WIRED_KINDS,
19
    SIREN_DURATION_MIN,
20
    SIREN_DURATION_MAX,
21
    SIREN_ENDPOINT,
22
    HEALTH_DOORBELL_ENDPOINT,
23
)
24

25
_LOGGER = logging.getLogger(__name__)
1✔
26

27

28
class RingStickUpCam(RingDoorBell):
1✔
29
    """Implementation for RingStickUpCam."""
30

31
    @property
1✔
32
    def family(self):
1✔
33
        """Return Ring device family type."""
34
        return "stickup_cams"
1✔
35

36
    def update_health_data(self):
1✔
37
        """Update health attrs."""
38
        self._health_attrs = (
×
39
            self._ring.query(HEALTH_DOORBELL_ENDPOINT.format(self.id))
40
            .json()
41
            .get("device_health", {})
42
        )
43

44
    @property
1✔
45
    def model(self):
1✔
46
        """Return Ring device model name."""
47
        if self.kind in FLOODLIGHT_CAM_KINDS:
1✔
48
            return "Floodlight Cam"
1✔
49
        if self.kind in FLOODLIGHT_CAM_PRO_KINDS:
×
50
            return "Floodlight Cam Pro"
×
51
        if self.kind in INDOOR_CAM_KINDS:
×
52
            return "Indoor Cam"
×
53
        if self.kind in SPOTLIGHT_CAM_BATTERY_KINDS:
×
54
            return "Spotlight Cam {}".format(
×
55
                self._attrs.get("ring_cam_setup_flow", "battery").title()
56
            )
57
        if self.kind in SPOTLIGHT_CAM_WIRED_KINDS:
×
58
            return "Spotlight Cam {}".format(
×
59
                self._attrs.get("ring_cam_setup_flow", "wired").title()
60
            )
61
        if self.kind in STICKUP_CAM_KINDS:
×
62
            return "Stick Up Cam"
×
63
        if self.kind in STICKUP_CAM_BATTERY_KINDS:
×
64
            return "Stick Up Cam Battery"
×
65
        if self.kind in STICKUP_CAM_WIRED_KINDS:
×
66
            return "Stick Up Cam Wired"
×
67
        _LOGGER.error("Unknown kind: %s", self.kind)
×
68
        return None
×
69

70
    def has_capability(self, capability):
1✔
71
        """Return if device has specific capability."""
72
        if capability == "battery":
1✔
73
            return self.kind in (
1✔
74
                SPOTLIGHT_CAM_BATTERY_KINDS
75
                + STICKUP_CAM_KINDS
76
                + STICKUP_CAM_BATTERY_KINDS
77
            )
78
        if capability == "light":
1✔
79
            return self.kind in (
1✔
80
                FLOODLIGHT_CAM_KINDS
81
                + FLOODLIGHT_CAM_PRO_KINDS
82
                + SPOTLIGHT_CAM_BATTERY_KINDS
83
                + SPOTLIGHT_CAM_WIRED_KINDS
84
            )
85
        if capability == "siren":
×
86
            return self.kind in (
×
87
                FLOODLIGHT_CAM_KINDS
88
                + FLOODLIGHT_CAM_PRO_KINDS
89
                + INDOOR_CAM_KINDS
90
                + SPOTLIGHT_CAM_BATTERY_KINDS
91
                + SPOTLIGHT_CAM_WIRED_KINDS
92
                + STICKUP_CAM_BATTERY_KINDS
93
                + STICKUP_CAM_WIRED_KINDS
94
            )
95
        if capability == "motion_detection":
×
96
            return self.kind in (
×
97
                FLOODLIGHT_CAM_KINDS
98
                + FLOODLIGHT_CAM_PRO_KINDS
99
                + INDOOR_CAM_KINDS
100
                + SPOTLIGHT_CAM_BATTERY_KINDS
101
                + SPOTLIGHT_CAM_WIRED_KINDS
102
                + STICKUP_CAM_BATTERY_KINDS
103
                + STICKUP_CAM_WIRED_KINDS
104
            )
105
        return False
×
106

107
    @property
1✔
108
    def lights(self):
1✔
109
        """Return lights status."""
110
        return self._attrs.get("led_status")
1✔
111

112
    @lights.setter
1✔
113
    def lights(self, state):
1✔
114
        """Control the lights."""
115
        values = ["on", "off"]
1✔
116
        if state not in values:
1✔
117
            _LOGGER.error("%s", MSG_ALLOWED_VALUES.format(", ".join(values)))
×
118
            return False
×
119

120
        url = LIGHTS_ENDPOINT.format(self.id, state)
1✔
121
        self._ring.query(url, method="PUT")
1✔
122
        self._ring.update_devices()
1✔
123
        return True
1✔
124

125
    @property
1✔
126
    def siren(self):
1✔
127
        """Return siren status."""
128
        if self._attrs.get("siren_status"):
1✔
129
            return self._attrs.get("siren_status").get("seconds_remaining")
1✔
130
        return None
×
131

132
    @siren.setter
1✔
133
    def siren(self, duration):
1✔
134
        """Control the siren."""
135
        if not (
1✔
136
            (isinstance(duration, int))
137
            and (SIREN_DURATION_MIN <= duration <= SIREN_DURATION_MAX)
138
        ):
139
            _LOGGER.error(
×
140
                "%s", MSG_VOL_OUTBOUND.format(SIREN_DURATION_MIN, SIREN_DURATION_MAX)
141
            )
142
            return False
×
143

144
        if duration > 0:
1✔
145
            state = "on"
1✔
146
            params = {"duration": duration}
1✔
147
        else:
148
            state = "off"
1✔
149
            params = {}
1✔
150
        url = SIREN_ENDPOINT.format(self.id, state)
1✔
151
        self._ring.query(url, extra_params=params, method="PUT")
1✔
152
        self._ring.update_devices()
1✔
153
        return True
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc