dirigera 1.3.0__tar.gz → 1.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dirigera-1.3.0/src/dirigera.egg-info → dirigera-1.4.0}/PKG-INFO +23 -3
- {dirigera-1.3.0 → dirigera-1.4.0}/README.md +20 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/pyproject.toml +3 -3
- dirigera-1.4.0/src/dirigera/devices/adaptive_profile.py +23 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/light.py +12 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/scene.py +1 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/hub/hub.py +10 -0
- {dirigera-1.3.0 → dirigera-1.4.0/src/dirigera.egg-info}/PKG-INFO +23 -3
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera.egg-info/SOURCES.txt +2 -0
- dirigera-1.4.0/src/dirigera.egg-info/requires.txt +7 -0
- dirigera-1.4.0/tests/test_hub_adaptive_profiles.py +63 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_light.py +59 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_scenes.py +68 -0
- dirigera-1.3.0/src/dirigera.egg-info/requires.txt +0 -7
- {dirigera-1.3.0 → dirigera-1.4.0}/LICENSE +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/setup.cfg +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/setup.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/__init__.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/__init__.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/__init__.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/air_purifier.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/base_ikea_model.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/blinds.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/controller.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/device.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/electrical_sensor.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/environment_sensor.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/light_sensor.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/motion_sensor.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/occupancy_sensor.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/open_close_sensor.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/outlet.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/devices/water_sensor.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/hub/__init__.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/hub/abstract_smart_home_hub.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/hub/auth.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera/hub/utils.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera.egg-info/dependency_links.txt +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera.egg-info/entry_points.txt +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/src/dirigera.egg-info/top_level.txt +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_air_purifier.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_blinds.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_controller.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_electrical_sensor.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_environment_sensor.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_hub.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_hub_get_by_name.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_light_sensor.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_motion_sensor.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_occupancy_sensor.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_open_close_sensor.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_outlet.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_utils.py +0 -0
- {dirigera-1.3.0 → dirigera-1.4.0}/tests/test_water_sensor.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dirigera
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.0
|
|
4
4
|
Summary: An unofficial Python client for controlling the IKEA Dirigera Smart Home Hub
|
|
5
5
|
Author-email: Leggin <legginsun@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -39,8 +39,8 @@ Requires-Python: >=3.7
|
|
|
39
39
|
Description-Content-Type: text/markdown
|
|
40
40
|
License-File: LICENSE
|
|
41
41
|
Requires-Dist: requests>=2.22.0
|
|
42
|
-
Requires-Dist: websocket-client>=1.
|
|
43
|
-
Requires-Dist: pydantic>=
|
|
42
|
+
Requires-Dist: websocket-client>=1.4.0
|
|
43
|
+
Requires-Dist: pydantic>=2.0
|
|
44
44
|
Provides-Extra: dev
|
|
45
45
|
Requires-Dist: black; extra == "dev"
|
|
46
46
|
Requires-Dist: pytest; extra == "dev"
|
|
@@ -65,6 +65,7 @@ This repository provides an unofficial Python client for controlling the IKEA Di
|
|
|
65
65
|
- [Capabilities](#capabilities)
|
|
66
66
|
- [Room](#room)
|
|
67
67
|
- [Controlling Lights](#controlling-lights)
|
|
68
|
+
- [Adaptive lighting](#adaptive-lighting)
|
|
68
69
|
- [Controlling Outlets](#controlling-outlets)
|
|
69
70
|
- [Controlling Air Purifier](#controlling-air-purifier)
|
|
70
71
|
- [Controlling Blinds](#controlling-blinds)
|
|
@@ -223,6 +224,9 @@ scene = dirigera_hub.get_scene_by_id(scene_id="1")
|
|
|
223
224
|
# Fetch a scene by its name
|
|
224
225
|
scene = dirigera_hub.get_scene_by_name(scene_name="movie night")
|
|
225
226
|
|
|
227
|
+
# Fetch all adaptive profiles
|
|
228
|
+
profiles = dirigera_hub.get_adaptive_profiles()
|
|
229
|
+
|
|
226
230
|
# Fetch all water sensors registered in the hub
|
|
227
231
|
water_sensors = dirigera_hub.get_water_sensors()
|
|
228
232
|
|
|
@@ -357,6 +361,8 @@ color_hue: Optional[float] = None
|
|
|
357
361
|
color_saturation: Optional[float] = None
|
|
358
362
|
```
|
|
359
363
|
|
|
364
|
+
Additionally the light has an `adaptive_profile` field (`Optional[AdaptiveProfileState]`) with the `id` and `active` state of the adaptive profile the light follows. It is empty (`id` and `active` are `None`) if the light is not in adaptive mode.
|
|
365
|
+
|
|
360
366
|
Available methods for light are:
|
|
361
367
|
|
|
362
368
|
```python
|
|
@@ -380,6 +386,20 @@ light.set_light_color(hue=128, saturation=0.5)
|
|
|
380
386
|
|
|
381
387
|
# Set the startup behavior of the light
|
|
382
388
|
light.set_startup_behaviour(behaviour=StartupEnum.START_OFF)
|
|
389
|
+
|
|
390
|
+
# Let the light follow an adaptive profile (see Adaptive lighting below)
|
|
391
|
+
light.activate_adaptive_profile(profile_id="1")
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### Adaptive lighting
|
|
395
|
+
|
|
396
|
+
Adaptive profiles are created in the IKEA app and define a schedule of light levels and color temperatures over the day. After `activate_adaptive_profile()` the light follows this schedule, the hub interpolates between the entries of the schedule. Changing the light manually, for example by setting the light level, takes it out of adaptive mode again. Call `light.reload()` and check `light.adaptive_profile.active` to see if the light is still in adaptive mode.
|
|
397
|
+
|
|
398
|
+
```python
|
|
399
|
+
profile = dirigera_hub.get_adaptive_profiles()[0] # AdaptiveProfile with id and adaptive_schedule
|
|
400
|
+
light.activate_adaptive_profile(profile_id=profile.id)
|
|
401
|
+
light.reload()
|
|
402
|
+
print(light.adaptive_profile.active) # True
|
|
383
403
|
```
|
|
384
404
|
|
|
385
405
|
## [Controlling Outlets](./src/dirigera/devices/outlet.py)
|
|
@@ -17,6 +17,7 @@ This repository provides an unofficial Python client for controlling the IKEA Di
|
|
|
17
17
|
- [Capabilities](#capabilities)
|
|
18
18
|
- [Room](#room)
|
|
19
19
|
- [Controlling Lights](#controlling-lights)
|
|
20
|
+
- [Adaptive lighting](#adaptive-lighting)
|
|
20
21
|
- [Controlling Outlets](#controlling-outlets)
|
|
21
22
|
- [Controlling Air Purifier](#controlling-air-purifier)
|
|
22
23
|
- [Controlling Blinds](#controlling-blinds)
|
|
@@ -175,6 +176,9 @@ scene = dirigera_hub.get_scene_by_id(scene_id="1")
|
|
|
175
176
|
# Fetch a scene by its name
|
|
176
177
|
scene = dirigera_hub.get_scene_by_name(scene_name="movie night")
|
|
177
178
|
|
|
179
|
+
# Fetch all adaptive profiles
|
|
180
|
+
profiles = dirigera_hub.get_adaptive_profiles()
|
|
181
|
+
|
|
178
182
|
# Fetch all water sensors registered in the hub
|
|
179
183
|
water_sensors = dirigera_hub.get_water_sensors()
|
|
180
184
|
|
|
@@ -309,6 +313,8 @@ color_hue: Optional[float] = None
|
|
|
309
313
|
color_saturation: Optional[float] = None
|
|
310
314
|
```
|
|
311
315
|
|
|
316
|
+
Additionally the light has an `adaptive_profile` field (`Optional[AdaptiveProfileState]`) with the `id` and `active` state of the adaptive profile the light follows. It is empty (`id` and `active` are `None`) if the light is not in adaptive mode.
|
|
317
|
+
|
|
312
318
|
Available methods for light are:
|
|
313
319
|
|
|
314
320
|
```python
|
|
@@ -332,6 +338,20 @@ light.set_light_color(hue=128, saturation=0.5)
|
|
|
332
338
|
|
|
333
339
|
# Set the startup behavior of the light
|
|
334
340
|
light.set_startup_behaviour(behaviour=StartupEnum.START_OFF)
|
|
341
|
+
|
|
342
|
+
# Let the light follow an adaptive profile (see Adaptive lighting below)
|
|
343
|
+
light.activate_adaptive_profile(profile_id="1")
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Adaptive lighting
|
|
347
|
+
|
|
348
|
+
Adaptive profiles are created in the IKEA app and define a schedule of light levels and color temperatures over the day. After `activate_adaptive_profile()` the light follows this schedule, the hub interpolates between the entries of the schedule. Changing the light manually, for example by setting the light level, takes it out of adaptive mode again. Call `light.reload()` and check `light.adaptive_profile.active` to see if the light is still in adaptive mode.
|
|
349
|
+
|
|
350
|
+
```python
|
|
351
|
+
profile = dirigera_hub.get_adaptive_profiles()[0] # AdaptiveProfile with id and adaptive_schedule
|
|
352
|
+
light.activate_adaptive_profile(profile_id=profile.id)
|
|
353
|
+
light.reload()
|
|
354
|
+
print(light.adaptive_profile.active) # True
|
|
335
355
|
```
|
|
336
356
|
|
|
337
357
|
## [Controlling Outlets](./src/dirigera/devices/outlet.py)
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "dirigera"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.4.0"
|
|
8
8
|
description = "An unofficial Python client for controlling the IKEA Dirigera Smart Home Hub"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [{ name = "Leggin", email = "legginsun@gmail.com" }]
|
|
@@ -21,8 +21,8 @@ keywords = [
|
|
|
21
21
|
]
|
|
22
22
|
dependencies = [
|
|
23
23
|
"requests >= 2.22.0",
|
|
24
|
-
"websocket-client >= 1.
|
|
25
|
-
"pydantic >=
|
|
24
|
+
"websocket-client >= 1.4.0",
|
|
25
|
+
"pydantic >= 2.0",
|
|
26
26
|
]
|
|
27
27
|
requires-python = ">=3.7"
|
|
28
28
|
classifiers = [
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from typing import List, Optional
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
from .base_ikea_model import BaseIkeaModel
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class AdaptiveScheduleEntry(BaseIkeaModel):
|
|
8
|
+
start_time: str # "HH:MM"
|
|
9
|
+
light_level: Optional[int] = None
|
|
10
|
+
color_temperature: Optional[int] = None
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AdaptiveProfile(BaseIkeaModel):
|
|
14
|
+
id: str
|
|
15
|
+
name: Optional[str] = None
|
|
16
|
+
adaptive_schedule: List[AdaptiveScheduleEntry] = Field(default_factory=list)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class AdaptiveProfileState(BaseIkeaModel):
|
|
20
|
+
"""The adaptive profile state of a light, empty if the light is not in adaptive mode"""
|
|
21
|
+
|
|
22
|
+
id: Optional[str] = None
|
|
23
|
+
active: Optional[bool] = None
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
from typing import Any, Optional, Dict
|
|
3
|
+
from .adaptive_profile import AdaptiveProfileState
|
|
3
4
|
from .device import Attributes, Device, StartupEnum
|
|
4
5
|
from ..hub.abstract_smart_home_hub import AbstractSmartHomeHub
|
|
5
6
|
|
|
@@ -27,6 +28,7 @@ class LightAttributes(Attributes):
|
|
|
27
28
|
class Light(Device):
|
|
28
29
|
dirigera_client: AbstractSmartHomeHub
|
|
29
30
|
attributes: LightAttributes
|
|
31
|
+
adaptive_profile: Optional[AdaptiveProfileState] = None
|
|
30
32
|
|
|
31
33
|
def reload(self) -> Light:
|
|
32
34
|
data = self.dirigera_client.get(route=f"/devices/{self.id}")
|
|
@@ -115,6 +117,16 @@ class Light(Device):
|
|
|
115
117
|
self.dirigera_client.patch(route=f"/devices/{self.id}", data=data)
|
|
116
118
|
self.attributes.startup_on_off = behaviour
|
|
117
119
|
|
|
120
|
+
def activate_adaptive_profile(self, profile_id: str) -> None:
|
|
121
|
+
"""
|
|
122
|
+
Lets the lamp follow the schedule of the adaptive profile with the given id.
|
|
123
|
+
Changing the lamp manually afterwards (e.g. its light level) takes it out of
|
|
124
|
+
adaptive mode again, call reload() to see the current state.
|
|
125
|
+
"""
|
|
126
|
+
data = [{"adaptiveProfile": {"id": profile_id, "active": True}}]
|
|
127
|
+
self.dirigera_client.patch(route=f"/devices/{self.id}", data=data)
|
|
128
|
+
self.adaptive_profile = AdaptiveProfileState(id=profile_id, active=True)
|
|
129
|
+
|
|
118
130
|
|
|
119
131
|
def dict_to_light(data: Dict[str, Any], dirigera_client: AbstractSmartHomeHub) -> Light:
|
|
120
132
|
return Light(
|
|
@@ -89,6 +89,7 @@ class TriggerDetails(BaseIkeaModel):
|
|
|
89
89
|
click_pattern: Optional[ClickPattern] = None
|
|
90
90
|
device_id: Optional[str] = None
|
|
91
91
|
offset: Optional[int] = None
|
|
92
|
+
duration: Optional[int] = None # seconds, used by end triggers of type "duration"
|
|
92
93
|
type: Optional[str] = None
|
|
93
94
|
|
|
94
95
|
# Deprecated camelCase accessors, kept so existing code reading the old attribute names keeps working.
|
|
@@ -10,6 +10,7 @@ from urllib3.exceptions import InsecureRequestWarning
|
|
|
10
10
|
from .utils import camelize_dict
|
|
11
11
|
from ..devices.device import Device
|
|
12
12
|
from .abstract_smart_home_hub import AbstractSmartHomeHub
|
|
13
|
+
from ..devices.adaptive_profile import AdaptiveProfile
|
|
13
14
|
from ..devices.air_purifier import AirPurifier, dict_to_air_purifier
|
|
14
15
|
from ..devices.light import Light, dict_to_light
|
|
15
16
|
from ..devices.blinds import Blind, dict_to_blind
|
|
@@ -407,6 +408,15 @@ class Hub(AbstractSmartHomeHub):
|
|
|
407
408
|
raise AssertionError(f"No Scene found with name {scene_name}")
|
|
408
409
|
return scenes[0]
|
|
409
410
|
|
|
411
|
+
def get_adaptive_profiles(self) -> List[AdaptiveProfile]:
|
|
412
|
+
"""
|
|
413
|
+
Fetches all adaptive profiles
|
|
414
|
+
"""
|
|
415
|
+
home = self.get("/home")
|
|
416
|
+
return [
|
|
417
|
+
AdaptiveProfile(**profile) for profile in home.get("adaptiveProfiles", [])
|
|
418
|
+
]
|
|
419
|
+
|
|
410
420
|
def get_water_sensors(self) -> List[WaterSensor]:
|
|
411
421
|
"""
|
|
412
422
|
Fetches all water sensors registered in the Hub
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dirigera
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.0
|
|
4
4
|
Summary: An unofficial Python client for controlling the IKEA Dirigera Smart Home Hub
|
|
5
5
|
Author-email: Leggin <legginsun@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -39,8 +39,8 @@ Requires-Python: >=3.7
|
|
|
39
39
|
Description-Content-Type: text/markdown
|
|
40
40
|
License-File: LICENSE
|
|
41
41
|
Requires-Dist: requests>=2.22.0
|
|
42
|
-
Requires-Dist: websocket-client>=1.
|
|
43
|
-
Requires-Dist: pydantic>=
|
|
42
|
+
Requires-Dist: websocket-client>=1.4.0
|
|
43
|
+
Requires-Dist: pydantic>=2.0
|
|
44
44
|
Provides-Extra: dev
|
|
45
45
|
Requires-Dist: black; extra == "dev"
|
|
46
46
|
Requires-Dist: pytest; extra == "dev"
|
|
@@ -65,6 +65,7 @@ This repository provides an unofficial Python client for controlling the IKEA Di
|
|
|
65
65
|
- [Capabilities](#capabilities)
|
|
66
66
|
- [Room](#room)
|
|
67
67
|
- [Controlling Lights](#controlling-lights)
|
|
68
|
+
- [Adaptive lighting](#adaptive-lighting)
|
|
68
69
|
- [Controlling Outlets](#controlling-outlets)
|
|
69
70
|
- [Controlling Air Purifier](#controlling-air-purifier)
|
|
70
71
|
- [Controlling Blinds](#controlling-blinds)
|
|
@@ -223,6 +224,9 @@ scene = dirigera_hub.get_scene_by_id(scene_id="1")
|
|
|
223
224
|
# Fetch a scene by its name
|
|
224
225
|
scene = dirigera_hub.get_scene_by_name(scene_name="movie night")
|
|
225
226
|
|
|
227
|
+
# Fetch all adaptive profiles
|
|
228
|
+
profiles = dirigera_hub.get_adaptive_profiles()
|
|
229
|
+
|
|
226
230
|
# Fetch all water sensors registered in the hub
|
|
227
231
|
water_sensors = dirigera_hub.get_water_sensors()
|
|
228
232
|
|
|
@@ -357,6 +361,8 @@ color_hue: Optional[float] = None
|
|
|
357
361
|
color_saturation: Optional[float] = None
|
|
358
362
|
```
|
|
359
363
|
|
|
364
|
+
Additionally the light has an `adaptive_profile` field (`Optional[AdaptiveProfileState]`) with the `id` and `active` state of the adaptive profile the light follows. It is empty (`id` and `active` are `None`) if the light is not in adaptive mode.
|
|
365
|
+
|
|
360
366
|
Available methods for light are:
|
|
361
367
|
|
|
362
368
|
```python
|
|
@@ -380,6 +386,20 @@ light.set_light_color(hue=128, saturation=0.5)
|
|
|
380
386
|
|
|
381
387
|
# Set the startup behavior of the light
|
|
382
388
|
light.set_startup_behaviour(behaviour=StartupEnum.START_OFF)
|
|
389
|
+
|
|
390
|
+
# Let the light follow an adaptive profile (see Adaptive lighting below)
|
|
391
|
+
light.activate_adaptive_profile(profile_id="1")
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### Adaptive lighting
|
|
395
|
+
|
|
396
|
+
Adaptive profiles are created in the IKEA app and define a schedule of light levels and color temperatures over the day. After `activate_adaptive_profile()` the light follows this schedule, the hub interpolates between the entries of the schedule. Changing the light manually, for example by setting the light level, takes it out of adaptive mode again. Call `light.reload()` and check `light.adaptive_profile.active` to see if the light is still in adaptive mode.
|
|
397
|
+
|
|
398
|
+
```python
|
|
399
|
+
profile = dirigera_hub.get_adaptive_profiles()[0] # AdaptiveProfile with id and adaptive_schedule
|
|
400
|
+
light.activate_adaptive_profile(profile_id=profile.id)
|
|
401
|
+
light.reload()
|
|
402
|
+
print(light.adaptive_profile.active) # True
|
|
383
403
|
```
|
|
384
404
|
|
|
385
405
|
## [Controlling Outlets](./src/dirigera/devices/outlet.py)
|
|
@@ -11,6 +11,7 @@ src/dirigera.egg-info/entry_points.txt
|
|
|
11
11
|
src/dirigera.egg-info/requires.txt
|
|
12
12
|
src/dirigera.egg-info/top_level.txt
|
|
13
13
|
src/dirigera/devices/__init__.py
|
|
14
|
+
src/dirigera/devices/adaptive_profile.py
|
|
14
15
|
src/dirigera/devices/air_purifier.py
|
|
15
16
|
src/dirigera/devices/base_ikea_model.py
|
|
16
17
|
src/dirigera/devices/blinds.py
|
|
@@ -37,6 +38,7 @@ tests/test_controller.py
|
|
|
37
38
|
tests/test_electrical_sensor.py
|
|
38
39
|
tests/test_environment_sensor.py
|
|
39
40
|
tests/test_hub.py
|
|
41
|
+
tests/test_hub_adaptive_profiles.py
|
|
40
42
|
tests/test_hub_get_by_name.py
|
|
41
43
|
tests/test_light.py
|
|
42
44
|
tests/test_light_sensor.py
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from typing import Any, Dict
|
|
2
|
+
import pytest
|
|
3
|
+
from src.dirigera.hub.hub import Hub
|
|
4
|
+
|
|
5
|
+
PROFILE_ID = "19d31644-5fc5-405b-8f0c-b2f0634190f6"
|
|
6
|
+
|
|
7
|
+
# the profile as reported by /home, the hub did not send a name for it
|
|
8
|
+
HOME: Dict[str, Any] = {
|
|
9
|
+
"adaptiveProfiles": [
|
|
10
|
+
{
|
|
11
|
+
"id": PROFILE_ID,
|
|
12
|
+
"adaptiveSchedule": [
|
|
13
|
+
{"startTime": "00:00", "lightLevel": 10, "colorTemperature": 1000},
|
|
14
|
+
{"startTime": "05:00", "lightLevel": 10, "colorTemperature": 1000},
|
|
15
|
+
{"startTime": "08:00", "lightLevel": 90, "colorTemperature": 3600},
|
|
16
|
+
{"startTime": "14:00", "lightLevel": 100, "colorTemperature": 8000},
|
|
17
|
+
{"startTime": "18:00", "lightLevel": 90, "colorTemperature": 2400},
|
|
18
|
+
{"startTime": "20:00", "lightLevel": 80, "colorTemperature": 1800},
|
|
19
|
+
],
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@pytest.fixture(name="hub")
|
|
26
|
+
def fixture_hub() -> Hub:
|
|
27
|
+
return Hub(token="fake-token", ip_address="127.0.0.1")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_get_adaptive_profiles(monkeypatch: pytest.MonkeyPatch, hub: Hub) -> None:
|
|
31
|
+
replies = {"/home": HOME}
|
|
32
|
+
monkeypatch.setattr(Hub, "get", lambda _self, route: replies[route])
|
|
33
|
+
|
|
34
|
+
profiles = hub.get_adaptive_profiles()
|
|
35
|
+
|
|
36
|
+
assert len(profiles) == 1
|
|
37
|
+
assert profiles[0].id == PROFILE_ID
|
|
38
|
+
assert profiles[0].name is None
|
|
39
|
+
schedule = profiles[0].adaptive_schedule
|
|
40
|
+
assert [entry.start_time for entry in schedule] == [
|
|
41
|
+
"00:00",
|
|
42
|
+
"05:00",
|
|
43
|
+
"08:00",
|
|
44
|
+
"14:00",
|
|
45
|
+
"18:00",
|
|
46
|
+
"20:00",
|
|
47
|
+
]
|
|
48
|
+
assert [entry.light_level for entry in schedule] == [10, 10, 90, 100, 90, 80]
|
|
49
|
+
assert [entry.color_temperature for entry in schedule] == [
|
|
50
|
+
1000,
|
|
51
|
+
1000,
|
|
52
|
+
3600,
|
|
53
|
+
8000,
|
|
54
|
+
2400,
|
|
55
|
+
1800,
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_get_adaptive_profiles_without_profiles(
|
|
60
|
+
monkeypatch: pytest.MonkeyPatch, hub: Hub
|
|
61
|
+
) -> None:
|
|
62
|
+
monkeypatch.setattr(Hub, "get", lambda _self, _route: {})
|
|
63
|
+
assert hub.get_adaptive_profiles() == []
|
|
@@ -4,8 +4,11 @@ import pytest
|
|
|
4
4
|
from src.dirigera.hub.abstract_smart_home_hub import FakeDirigeraHub
|
|
5
5
|
from src.dirigera.devices.light import dict_to_light
|
|
6
6
|
from src.dirigera.devices.light import Light
|
|
7
|
+
from src.dirigera.devices.adaptive_profile import AdaptiveProfileState
|
|
7
8
|
from src.dirigera.devices.device import StartupEnum
|
|
8
9
|
|
|
10
|
+
PROFILE_ID = "19d31644-5fc5-405b-8f0c-b2f0634190f6"
|
|
11
|
+
|
|
9
12
|
|
|
10
13
|
@pytest.fixture(name="fake_client")
|
|
11
14
|
def fixture_fake_client() -> FakeDirigeraHub:
|
|
@@ -322,6 +325,62 @@ def test_set_startup_behaviour_toggle(
|
|
|
322
325
|
assert fake_light.attributes.startup_on_off == behaviour
|
|
323
326
|
|
|
324
327
|
|
|
328
|
+
def test_adaptive_profile_is_none_if_hub_does_not_report_it(fake_light: Light) -> None:
|
|
329
|
+
assert fake_light.adaptive_profile is None
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def test_adaptive_profile_empty_if_not_in_adaptive_mode(
|
|
333
|
+
fake_light: Light, fake_client: FakeDirigeraHub
|
|
334
|
+
) -> None:
|
|
335
|
+
data = fake_light.model_dump(by_alias=True, exclude={"dirigera_client"})
|
|
336
|
+
data["adaptiveProfile"] = {}
|
|
337
|
+
light = dict_to_light(data, fake_client)
|
|
338
|
+
assert light.adaptive_profile == AdaptiveProfileState()
|
|
339
|
+
assert light.adaptive_profile is not None
|
|
340
|
+
assert light.adaptive_profile.id is None
|
|
341
|
+
assert light.adaptive_profile.active is None
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def test_adaptive_profile_active(
|
|
345
|
+
fake_light: Light, fake_client: FakeDirigeraHub
|
|
346
|
+
) -> None:
|
|
347
|
+
data = fake_light.model_dump(by_alias=True, exclude={"dirigera_client"})
|
|
348
|
+
data["adaptiveProfile"] = {"id": PROFILE_ID, "active": True}
|
|
349
|
+
light = dict_to_light(data, fake_client)
|
|
350
|
+
assert light.adaptive_profile is not None
|
|
351
|
+
assert light.adaptive_profile.id == PROFILE_ID
|
|
352
|
+
assert light.adaptive_profile.active
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def test_reload_updates_adaptive_profile(
|
|
356
|
+
fake_light: Light, fake_client: FakeDirigeraHub
|
|
357
|
+
) -> None:
|
|
358
|
+
data = fake_light.model_dump(by_alias=True, exclude={"dirigera_client"})
|
|
359
|
+
data["adaptiveProfile"] = {"id": PROFILE_ID, "active": True}
|
|
360
|
+
fake_client.get_action_replys[f"/devices/{fake_light.id}"] = data
|
|
361
|
+
fake_light.reload()
|
|
362
|
+
assert fake_light.adaptive_profile == AdaptiveProfileState(
|
|
363
|
+
id=PROFILE_ID, active=True
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
# the hub reports an empty profile once the light left adaptive mode
|
|
367
|
+
data["adaptiveProfile"] = {}
|
|
368
|
+
fake_light.reload()
|
|
369
|
+
assert fake_light.adaptive_profile == AdaptiveProfileState()
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def test_activate_adaptive_profile(
|
|
373
|
+
fake_light: Light, fake_client: FakeDirigeraHub
|
|
374
|
+
) -> None:
|
|
375
|
+
fake_light.activate_adaptive_profile(PROFILE_ID)
|
|
376
|
+
action = fake_client.patch_actions.pop()
|
|
377
|
+
assert action["route"] == f"/devices/{fake_light.id}"
|
|
378
|
+
assert action["data"] == [{"adaptiveProfile": {"id": PROFILE_ID, "active": True}}]
|
|
379
|
+
assert fake_light.adaptive_profile == AdaptiveProfileState(
|
|
380
|
+
id=PROFILE_ID, active=True
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
|
|
325
384
|
def test_dict_to_light_3rdparty(fake_client: FakeDirigeraHub) -> None:
|
|
326
385
|
data: Dict[str, Any] = {
|
|
327
386
|
"id": "1237-343-2dfa",
|
|
@@ -8,6 +8,7 @@ from src.dirigera.devices.scene import (
|
|
|
8
8
|
dict_to_scene,
|
|
9
9
|
ControllerType,
|
|
10
10
|
ClickPattern,
|
|
11
|
+
EndTriggerEvent,
|
|
11
12
|
Icon,
|
|
12
13
|
Info,
|
|
13
14
|
SceneType,
|
|
@@ -286,3 +287,70 @@ def test_create_scene_posts_camel_case_trigger_details(
|
|
|
286
287
|
},
|
|
287
288
|
}
|
|
288
289
|
]
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def test_trigger_with_duration_end_trigger() -> None:
|
|
293
|
+
trigger = Trigger(
|
|
294
|
+
**{
|
|
295
|
+
"type": "time",
|
|
296
|
+
"disabled": False,
|
|
297
|
+
"trigger": {"days": ["Mon"], "time": "00:00"},
|
|
298
|
+
"endTrigger": {"type": "duration", "trigger": {"duration": 21600}},
|
|
299
|
+
"endTriggerEvent": {"type": "duration", "trigger": {"duration": 21600}},
|
|
300
|
+
}
|
|
301
|
+
)
|
|
302
|
+
assert trigger.end_trigger is not None
|
|
303
|
+
assert trigger.end_trigger.type == "duration"
|
|
304
|
+
assert trigger.end_trigger.trigger.duration == 21600
|
|
305
|
+
assert trigger.end_trigger_event is not None
|
|
306
|
+
assert trigger.end_trigger_event.trigger.duration == 21600
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def test_create_scene_posts_duration_end_trigger(
|
|
310
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
311
|
+
) -> None:
|
|
312
|
+
hub = Hub(token="token", ip_address="127.0.0.1")
|
|
313
|
+
post_actions: List[Dict[str, Any]] = []
|
|
314
|
+
|
|
315
|
+
def fake_post(route: str, data: Optional[Dict[str, Any]] = None) -> Any:
|
|
316
|
+
post_actions.append({"route": route, "data": data})
|
|
317
|
+
return {"id": TEST_ID}
|
|
318
|
+
|
|
319
|
+
def fake_get(_route: str) -> Any:
|
|
320
|
+
return {
|
|
321
|
+
"id": TEST_ID,
|
|
322
|
+
"info": {"name": TEST_NAME, "icon": TEST_ICON},
|
|
323
|
+
"type": "customScene",
|
|
324
|
+
"triggers": [],
|
|
325
|
+
"actions": [],
|
|
326
|
+
"commands": [],
|
|
327
|
+
"createdAt": "2023-08-27T10:28:48.096Z",
|
|
328
|
+
"undoAllowedDuration": 30,
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
monkeypatch.setattr(hub, "post", fake_post)
|
|
332
|
+
monkeypatch.setattr(hub, "get", fake_get)
|
|
333
|
+
|
|
334
|
+
hub.create_scene(
|
|
335
|
+
info=Info(name=TEST_NAME, icon=Icon.SCENES_CLEAN_SPARKLES),
|
|
336
|
+
scene_type=SceneType.CUSTOM_SCENE,
|
|
337
|
+
triggers=[
|
|
338
|
+
Trigger(
|
|
339
|
+
type="time",
|
|
340
|
+
disabled=False,
|
|
341
|
+
trigger=TriggerDetails(days=["Mon"], time="00:00"),
|
|
342
|
+
endTriggerEvent=EndTriggerEvent(
|
|
343
|
+
type="duration", trigger=TriggerDetails(duration=21600)
|
|
344
|
+
),
|
|
345
|
+
)
|
|
346
|
+
],
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
assert post_actions[0]["data"]["triggers"] == [
|
|
350
|
+
{
|
|
351
|
+
"type": "time",
|
|
352
|
+
"disabled": False,
|
|
353
|
+
"trigger": {"days": ["Mon"], "time": "00:00"},
|
|
354
|
+
"endTriggerEvent": {"type": "duration", "trigger": {"duration": 21600}},
|
|
355
|
+
}
|
|
356
|
+
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|