File: device_helper.py

package info (click to toggle)
python-boschshcpy 0.2.92-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 268 kB
  • sloc: python: 3,343; makefile: 4; sh: 4
file content (303 lines) | stat: -rw-r--r-- 10,389 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
from __future__ import annotations

import logging
import typing

from .api import SHCAPI
from .device import SHCDevice
from .models_impl import (
    SUPPORTED_MODELS,
    SHCBatteryDevice,
    SHCCamera360,
    SHCCameraEyes,
    SHCClimateControl,
    SHCHeatingCircuit,
    SHCLight,
    SHCMotionDetector,
    SHCShutterContact,
    SHCShutterContact2,
    SHCShutterContact2Plus,
    SHCShutterControl,
    SHCMicromoduleBlinds,
    SHCMicromoduleRelay,
    SHCMicromoduleShutterControl,
    SHCLightControl,
    SHCLightSwitch,
    SHCLightSwitchBSM,
    SHCPresenceSimulationSystem,
    SHCSmartPlug,
    SHCSmartPlugCompact,
    SHCSmokeDetector,
    SHCSmokeDetectionSystem,
    SHCThermostat,
    SHCRoomThermostat2,
    SHCTwinguard,
    SHCUniversalSwitch,
    SHCWallThermostat,
    SHCWaterLeakageSensor,
    SHCMicromoduleDimmer,
    build,
)

logger = logging.getLogger("boschshcpy")


class SHCDeviceHelper:
    def __init__(self, api: SHCAPI) -> None:
        self._api = api
        self._devices_by_model: dict[str, dict[str, SHCDevice]] = {}
        for model in SUPPORTED_MODELS:
            self._devices_by_model[model] = {}

    def device_init(self, raw_device, device_services) -> SHCDevice:
        device_id = raw_device["id"]
        device_model = raw_device["deviceModel"]
        device = []
        if device_model in SUPPORTED_MODELS:
            device = build(
                api=self._api,
                raw_device=raw_device,
                raw_device_services=device_services,
            )
            self._devices_by_model[device_model][device_id] = device
        else:
            device = SHCDevice(
                api=self._api,
                raw_device=raw_device,
                raw_device_services=device_services,
            )

        return device

    @property
    def shutter_contacts(self) -> typing.Sequence[SHCShutterContact]:
        devices = []
        if "SWD" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["SWD"].values())
        return devices

    @property
    def shutter_contacts2(self) -> typing.Sequence[SHCShutterContact2]:
        devices = []
        if "SWD2" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["SWD2"].values())
        if "SWD2_PLUS" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["SWD2_PLUS"].values())
        return devices

    @property
    def shutter_controls(self) -> typing.Sequence[SHCShutterControl]:
        devices = []
        if "BBL" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["BBL"].values())
        return devices

    @property
    def micromodule_shutter_controls(
        self,
    ) -> typing.Sequence[SHCMicromoduleShutterControl]:
        devices = []
        if "MICROMODULE_SHUTTER" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["MICROMODULE_SHUTTER"].values())
        if "MICROMODULE_AWNING" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["MICROMODULE_AWNING"].values())
        return devices

    @property
    def micromodule_blinds(
        self,
    ) -> typing.Sequence[SHCMicromoduleBlinds]:
        devices = []
        if "MICROMODULE_BLINDS" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["MICROMODULE_BLINDS"].values())
        return devices

    @property
    def micromodule_relays(
        self,
    ) -> typing.Sequence[SHCMicromoduleRelay]:
        devices = []
        if "MICROMODULE_RELAY" in SUPPORTED_MODELS:
            for relay in self._devices_by_model["MICROMODULE_RELAY"].values():
                if relay.relay_type == SHCMicromoduleRelay.RelayType.SWITCH:
                    devices.extend([relay])
        return devices

    @property
    def micromodule_impulse_relays(
        self,
    ) -> typing.Sequence[SHCMicromoduleRelay]:
        devices = []
        if "MICROMODULE_RELAY" in SUPPORTED_MODELS:
            for relay in self._devices_by_model["MICROMODULE_RELAY"].values():
                if relay.relay_type == SHCMicromoduleRelay.RelayType.BUTTON:
                    devices.extend([relay])
        return devices

    @property
    def light_switches_bsm(self) -> typing.Sequence[SHCLightSwitchBSM]:
        devices = []
        if "BSM" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["BSM"].values())
        return devices

    @property
    def micromodule_light_attached(self) -> typing.Sequence[SHCLightSwitch]:
        devices = []
        if "MICROMODULE_LIGHT_ATTACHED" in SUPPORTED_MODELS:
            devices.extend(
                self._devices_by_model["MICROMODULE_LIGHT_ATTACHED"].values()
            )
        return devices

    @property
    def micromodule_light_controls(self) -> typing.Sequence[SHCLightControl]:
        devices = []
        if "MICROMODULE_LIGHT_CONTROL" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["MICROMODULE_LIGHT_CONTROL"].values())
        return devices

    @property
    def smart_plugs(self) -> typing.Sequence[SHCSmartPlug]:
        if "PSM" not in SUPPORTED_MODELS:
            return []
        return list(self._devices_by_model["PSM"].values())

    @property
    def smart_plugs_compact(self) -> typing.Sequence[SHCSmartPlugCompact]:
        if "PLUG_COMPACT" not in SUPPORTED_MODELS:
            return []
        return list(self._devices_by_model["PLUG_COMPACT"].values())

    @property
    def smoke_detectors(self) -> typing.Sequence[SHCSmokeDetector]:
        devices = []
        if "SD" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["SD"].values())
        if "SMOKE_DETECTOR2" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["SMOKE_DETECTOR2"].values())
        return devices

    @property
    def climate_controls(self) -> typing.Sequence[SHCClimateControl]:
        if "ROOM_CLIMATE_CONTROL" not in SUPPORTED_MODELS:
            return []
        return list(self._devices_by_model["ROOM_CLIMATE_CONTROL"].values())

    @property
    def thermostats(self) -> typing.Sequence[SHCThermostat]:
        devices = []
        if "TRV" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["TRV"].values())
        if "TRV_GEN2" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["TRV_GEN2"].values())
        return devices

    @property
    def wallthermostats(self) -> typing.Sequence[SHCWallThermostat]:
        devices = []
        if "THB" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["THB"].values())
        if "BWTH" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["BWTH"].values())
        if "BWTH24" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["BWTH24"].values())
        return devices

    @property
    def roomthermostats(self) -> typing.Sequence[SHCRoomThermostat2]:
        devices = []
        if "RTH2_BAT" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["RTH2_BAT"].values())
        if "RTH2_230" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["RTH2_230"].values())
        return devices

    @property
    def motion_detectors(self) -> typing.Sequence[SHCMotionDetector]:
        if "MD" not in SUPPORTED_MODELS:
            return []
        return list(self._devices_by_model["MD"].values())

    @property
    def twinguards(self) -> typing.Sequence[SHCTwinguard]:
        if "TWINGUARD" not in SUPPORTED_MODELS:
            return []
        return list(self._devices_by_model["TWINGUARD"].values())

    @property
    def universal_switches(self) -> typing.Sequence[SHCUniversalSwitch]:
        devices = []
        if "WRC2" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["WRC2"].values())
        if "SWITCH2" in SUPPORTED_MODELS:
            devices.extend(self._devices_by_model["SWITCH2"].values())
        return devices

    @property
    def camera_eyes(self) -> typing.Sequence[SHCCameraEyes]:
        if "CAMERA_EYES" not in SUPPORTED_MODELS:
            return []
        return list(self._devices_by_model["CAMERA_EYES"].values())

    @property
    def camera_360(self) -> typing.Sequence[SHCCamera360]:
        if "CAMERA_360" not in SUPPORTED_MODELS:
            return []
        return list(self._devices_by_model["CAMERA_360"].values())

    @property
    def ledvance_lights(self) -> typing.Sequence[SHCLight]:
        if "LEDVANCE_LIGHT" not in SUPPORTED_MODELS:
            return []
        return list(self._devices_by_model["LEDVANCE_LIGHT"].values())

    @property
    def hue_lights(self) -> typing.Sequence[SHCLight]:
        if "HUE_LIGHT" not in SUPPORTED_MODELS:
            return []
        return list(self._devices_by_model["HUE_LIGHT"].values())

    @property
    def water_leakage_detectors(self) -> typing.Sequence[SHCWaterLeakageSensor]:
        if "WLS" not in SUPPORTED_MODELS:
            return []
        return list(self._devices_by_model["WLS"].values())

    @property
    def presence_simulation_system(
        self,
    ) -> SHCPresenceSimulationSystem:
        if "PRESENCE_SIMULATION_SERVICE" not in SUPPORTED_MODELS:
            return None
        return (
            self._devices_by_model["PRESENCE_SIMULATION_SERVICE"][
                "presenceSimulationService"
            ]
            if "presenceSimulationService"
            in self._devices_by_model["PRESENCE_SIMULATION_SERVICE"]
            else None
        )

    @property
    def smoke_detection_system(self) -> SHCSmokeDetectionSystem:
        if "SMOKE_DETECTION_SYSTEM" not in SUPPORTED_MODELS:
            return None
        return (
            self._devices_by_model["SMOKE_DETECTION_SYSTEM"]["smokeDetectionSystem"]
            if "smokeDetectionSystem"
            in self._devices_by_model["SMOKE_DETECTION_SYSTEM"]
            else None
        )

    @property
    def heating_circuits(self) -> typing.Sequence[SHCHeatingCircuit]:
        if "HEATING_CIRCUIT" not in SUPPORTED_MODELS:
            return []
        return list(self._devices_by_model["HEATING_CIRCUIT"].values())

    @property
    def micromodule_dimmers(self) -> typing.Sequence[SHCMicromoduleDimmer]:
        if "MICROMODULE_DIMMER" not in SUPPORTED_MODELS:
            return []
        return list(self._devices_by_model["MICROMODULE_DIMMER"].values())