enhomie 0.2.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.
- enhomie-0.2.0/LICENSE +21 -0
- enhomie-0.2.0/MANIFEST.in +4 -0
- enhomie-0.2.0/PKG-INFO +111 -0
- enhomie-0.2.0/README.md +97 -0
- enhomie-0.2.0/enhomie/__init__.py +29 -0
- enhomie-0.2.0/enhomie/builtins/__init__.py +19 -0
- enhomie-0.2.0/enhomie/builtins/params.py +71 -0
- enhomie-0.2.0/enhomie/builtins/test/__init__.py +6 -0
- enhomie-0.2.0/enhomie/builtins/test/test_params.py +47 -0
- enhomie-0.2.0/enhomie/builtins/test/test_when.py +65 -0
- enhomie-0.2.0/enhomie/builtins/when.py +95 -0
- enhomie-0.2.0/enhomie/config/__init__.py +17 -0
- enhomie-0.2.0/enhomie/config/config.py +95 -0
- enhomie-0.2.0/enhomie/config/params.py +68 -0
- enhomie-0.2.0/enhomie/config/test/__init__.py +16 -0
- enhomie-0.2.0/enhomie/config/test/test_config.py +55 -0
- enhomie-0.2.0/enhomie/conftest.py +290 -0
- enhomie-0.2.0/enhomie/homie/__init__.py +31 -0
- enhomie-0.2.0/enhomie/homie/desire.py +340 -0
- enhomie-0.2.0/enhomie/homie/group.py +259 -0
- enhomie-0.2.0/enhomie/homie/homie.py +734 -0
- enhomie-0.2.0/enhomie/homie/params.py +113 -0
- enhomie-0.2.0/enhomie/homie/scene.py +279 -0
- enhomie-0.2.0/enhomie/homie/test/__init__.py +16 -0
- enhomie-0.2.0/enhomie/homie/test/test_desire.py +129 -0
- enhomie-0.2.0/enhomie/homie/test/test_group.py +110 -0
- enhomie-0.2.0/enhomie/homie/test/test_homie.py +215 -0
- enhomie-0.2.0/enhomie/homie/test/test_scene.py +130 -0
- enhomie-0.2.0/enhomie/homie/test/test_when.py +69 -0
- enhomie-0.2.0/enhomie/homie/when.py +151 -0
- enhomie-0.2.0/enhomie/philipshue/__init__.py +25 -0
- enhomie-0.2.0/enhomie/philipshue/bridge.py +489 -0
- enhomie-0.2.0/enhomie/philipshue/device.py +395 -0
- enhomie-0.2.0/enhomie/philipshue/params.py +80 -0
- enhomie-0.2.0/enhomie/philipshue/test/__init__.py +36 -0
- enhomie-0.2.0/enhomie/philipshue/test/test_bridge.py +255 -0
- enhomie-0.2.0/enhomie/philipshue/test/test_device.py +153 -0
- enhomie-0.2.0/enhomie/philipshue/test/test_when.py +157 -0
- enhomie-0.2.0/enhomie/philipshue/when.py +113 -0
- enhomie-0.2.0/enhomie/py.typed +0 -0
- enhomie-0.2.0/enhomie/ubiquiti/__init__.py +25 -0
- enhomie-0.2.0/enhomie/ubiquiti/client.py +369 -0
- enhomie-0.2.0/enhomie/ubiquiti/params.py +76 -0
- enhomie-0.2.0/enhomie/ubiquiti/router.py +447 -0
- enhomie-0.2.0/enhomie/ubiquiti/test/__init__.py +16 -0
- enhomie-0.2.0/enhomie/ubiquiti/test/test_client.py +198 -0
- enhomie-0.2.0/enhomie/ubiquiti/test/test_router.py +177 -0
- enhomie-0.2.0/enhomie/ubiquiti/test/test_when.py +130 -0
- enhomie-0.2.0/enhomie/ubiquiti/when.py +108 -0
- enhomie-0.2.0/enhomie/version.txt +1 -0
- enhomie-0.2.0/enhomie.egg-info/PKG-INFO +111 -0
- enhomie-0.2.0/enhomie.egg-info/SOURCES.txt +57 -0
- enhomie-0.2.0/enhomie.egg-info/dependency_links.txt +1 -0
- enhomie-0.2.0/enhomie.egg-info/requires.txt +2 -0
- enhomie-0.2.0/enhomie.egg-info/top_level.txt +1 -0
- enhomie-0.2.0/pyproject.toml +34 -0
- enhomie-0.2.0/reqs-install.txt +2 -0
- enhomie-0.2.0/setup.cfg +28 -0
enhomie-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Enasis Network
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
enhomie-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: enhomie
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Enasis Network Homie Automate
|
|
5
|
+
License: MIT
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: encommon
|
|
13
|
+
Requires-Dist: enconnect
|
|
14
|
+
|
|
15
|
+
# Enasis Network Homie Automate
|
|
16
|
+
|
|
17
|
+
> :children_crossing: This project has not released its first major version.
|
|
18
|
+
|
|
19
|
+
Define desired scenes for groups using flexible conditional plugins.
|
|
20
|
+
|
|
21
|
+
[](https://github.com/enasisnetwork/enhomie/actions)<br>
|
|
22
|
+
[](https://codecov.io/gh/enasisnetwork/enhomie)<br>
|
|
23
|
+
[](https://enhomie.readthedocs.io)<br>
|
|
24
|
+
[](https://pypi.org/project/enhomie)<br>
|
|
25
|
+
[](https://pypi.org/project/enhomie)
|
|
26
|
+
|
|
27
|
+
## Configuration example
|
|
28
|
+
Some basic configuration examples. See next section for more documentation.
|
|
29
|
+
- [Homie Desires](enhomie/homie/test/samples/desires.yml)
|
|
30
|
+
- [Homie Groups](enhomie/homie/test/samples/groups.yml)
|
|
31
|
+
- [Homie Scenes](enhomie/homie/test/samples/scenes.yml)
|
|
32
|
+
- [Philips Hue Bridges](enhomie/philipshue/test/samples/bridges.yml)
|
|
33
|
+
- [Philips Hue Devices](enhomie/philipshue/test/samples/devices.yml)
|
|
34
|
+
- [Ubiquiti Routers](enhomie/ubiquiti/test/samples/routers.yml)
|
|
35
|
+
- [Ubiquiti Clients](enhomie/ubiquiti/test/samples/clients.yml)
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
Documentation is on [Read the Docs](https://enhomie.readthedocs.io).
|
|
39
|
+
Should you venture into the sections below you will be able to use the
|
|
40
|
+
`sphinx` recipe to build documention in the `docs/html` directory.
|
|
41
|
+
|
|
42
|
+
## Short-term future goals
|
|
43
|
+
- Encrypting the values in the configuration files.
|
|
44
|
+
- Deploying `enhomie` via the `sdmt` project.
|
|
45
|
+
- Ability to send email when scene change is made.
|
|
46
|
+
- Requires `enconnect.stmp.Compose` class.
|
|
47
|
+
- Requires `scene_set` to be idempotent.
|
|
48
|
+
|
|
49
|
+
## Long-term future goals
|
|
50
|
+
- CRUD for groups and scenes in Philips Hue bridges.
|
|
51
|
+
- Listener that can perform some basic actions.
|
|
52
|
+
- Plugin using light level from Philips Hue devices.
|
|
53
|
+
- Plugin checks current scene active for groups.
|
|
54
|
+
|
|
55
|
+
## Additional scripts
|
|
56
|
+
- [dumper.py](desired.py) is useful for setting desired scenes.
|
|
57
|
+
- [dumper.py](dumper.py) is useful for dumping configuration.
|
|
58
|
+
- [scener.py](scener.py) is useful for setting scene on groups.
|
|
59
|
+
|
|
60
|
+
## Useful and related links
|
|
61
|
+
- https://ubntwiki.com/products/software/unifi-controller/api
|
|
62
|
+
|
|
63
|
+
## Installing the package
|
|
64
|
+
Installing stable from the PyPi repository
|
|
65
|
+
```
|
|
66
|
+
pip install enhomie
|
|
67
|
+
```
|
|
68
|
+
Installing latest from GitHub repository
|
|
69
|
+
```
|
|
70
|
+
pip install git+https://github.com/enasisnetwork/enhomie
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Quick start for local development
|
|
74
|
+
Start by cloning the repository to your local machine.
|
|
75
|
+
```
|
|
76
|
+
git clone https://github.com/enasisnetwork/enhomie.git
|
|
77
|
+
```
|
|
78
|
+
Set up the Python virtual environments expected by the Makefile.
|
|
79
|
+
```
|
|
80
|
+
make -s venv-create
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Execute the linters and tests
|
|
84
|
+
The comprehensive approach is to use the `check` recipe. This will stop on
|
|
85
|
+
any failure that is encountered.
|
|
86
|
+
```
|
|
87
|
+
make -s check
|
|
88
|
+
```
|
|
89
|
+
However you can run the linters in a non-blocking mode.
|
|
90
|
+
```
|
|
91
|
+
make -s linters-pass
|
|
92
|
+
```
|
|
93
|
+
And finally run the various tests to validate the code and produce coverage
|
|
94
|
+
information found in the `htmlcov` folder in the root of the project.
|
|
95
|
+
```
|
|
96
|
+
make -s pytest
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Build and upload to PyPi
|
|
100
|
+
Build the package.
|
|
101
|
+
```
|
|
102
|
+
make -s pypackage
|
|
103
|
+
```
|
|
104
|
+
Upload to the test PyPi.
|
|
105
|
+
```
|
|
106
|
+
make -s pypi-upload-test
|
|
107
|
+
```
|
|
108
|
+
Upload to the prod PyPi.
|
|
109
|
+
```
|
|
110
|
+
make -s pypi-upload-prod
|
|
111
|
+
```
|
enhomie-0.2.0/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Enasis Network Homie Automate
|
|
2
|
+
|
|
3
|
+
> :children_crossing: This project has not released its first major version.
|
|
4
|
+
|
|
5
|
+
Define desired scenes for groups using flexible conditional plugins.
|
|
6
|
+
|
|
7
|
+
[](https://github.com/enasisnetwork/enhomie/actions)<br>
|
|
8
|
+
[](https://codecov.io/gh/enasisnetwork/enhomie)<br>
|
|
9
|
+
[](https://enhomie.readthedocs.io)<br>
|
|
10
|
+
[](https://pypi.org/project/enhomie)<br>
|
|
11
|
+
[](https://pypi.org/project/enhomie)
|
|
12
|
+
|
|
13
|
+
## Configuration example
|
|
14
|
+
Some basic configuration examples. See next section for more documentation.
|
|
15
|
+
- [Homie Desires](enhomie/homie/test/samples/desires.yml)
|
|
16
|
+
- [Homie Groups](enhomie/homie/test/samples/groups.yml)
|
|
17
|
+
- [Homie Scenes](enhomie/homie/test/samples/scenes.yml)
|
|
18
|
+
- [Philips Hue Bridges](enhomie/philipshue/test/samples/bridges.yml)
|
|
19
|
+
- [Philips Hue Devices](enhomie/philipshue/test/samples/devices.yml)
|
|
20
|
+
- [Ubiquiti Routers](enhomie/ubiquiti/test/samples/routers.yml)
|
|
21
|
+
- [Ubiquiti Clients](enhomie/ubiquiti/test/samples/clients.yml)
|
|
22
|
+
|
|
23
|
+
## Documentation
|
|
24
|
+
Documentation is on [Read the Docs](https://enhomie.readthedocs.io).
|
|
25
|
+
Should you venture into the sections below you will be able to use the
|
|
26
|
+
`sphinx` recipe to build documention in the `docs/html` directory.
|
|
27
|
+
|
|
28
|
+
## Short-term future goals
|
|
29
|
+
- Encrypting the values in the configuration files.
|
|
30
|
+
- Deploying `enhomie` via the `sdmt` project.
|
|
31
|
+
- Ability to send email when scene change is made.
|
|
32
|
+
- Requires `enconnect.stmp.Compose` class.
|
|
33
|
+
- Requires `scene_set` to be idempotent.
|
|
34
|
+
|
|
35
|
+
## Long-term future goals
|
|
36
|
+
- CRUD for groups and scenes in Philips Hue bridges.
|
|
37
|
+
- Listener that can perform some basic actions.
|
|
38
|
+
- Plugin using light level from Philips Hue devices.
|
|
39
|
+
- Plugin checks current scene active for groups.
|
|
40
|
+
|
|
41
|
+
## Additional scripts
|
|
42
|
+
- [dumper.py](desired.py) is useful for setting desired scenes.
|
|
43
|
+
- [dumper.py](dumper.py) is useful for dumping configuration.
|
|
44
|
+
- [scener.py](scener.py) is useful for setting scene on groups.
|
|
45
|
+
|
|
46
|
+
## Useful and related links
|
|
47
|
+
- https://ubntwiki.com/products/software/unifi-controller/api
|
|
48
|
+
|
|
49
|
+
## Installing the package
|
|
50
|
+
Installing stable from the PyPi repository
|
|
51
|
+
```
|
|
52
|
+
pip install enhomie
|
|
53
|
+
```
|
|
54
|
+
Installing latest from GitHub repository
|
|
55
|
+
```
|
|
56
|
+
pip install git+https://github.com/enasisnetwork/enhomie
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick start for local development
|
|
60
|
+
Start by cloning the repository to your local machine.
|
|
61
|
+
```
|
|
62
|
+
git clone https://github.com/enasisnetwork/enhomie.git
|
|
63
|
+
```
|
|
64
|
+
Set up the Python virtual environments expected by the Makefile.
|
|
65
|
+
```
|
|
66
|
+
make -s venv-create
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Execute the linters and tests
|
|
70
|
+
The comprehensive approach is to use the `check` recipe. This will stop on
|
|
71
|
+
any failure that is encountered.
|
|
72
|
+
```
|
|
73
|
+
make -s check
|
|
74
|
+
```
|
|
75
|
+
However you can run the linters in a non-blocking mode.
|
|
76
|
+
```
|
|
77
|
+
make -s linters-pass
|
|
78
|
+
```
|
|
79
|
+
And finally run the various tests to validate the code and produce coverage
|
|
80
|
+
information found in the `htmlcov` folder in the root of the project.
|
|
81
|
+
```
|
|
82
|
+
make -s pytest
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Build and upload to PyPi
|
|
86
|
+
Build the package.
|
|
87
|
+
```
|
|
88
|
+
make -s pypackage
|
|
89
|
+
```
|
|
90
|
+
Upload to the test PyPi.
|
|
91
|
+
```
|
|
92
|
+
make -s pypi-upload-test
|
|
93
|
+
```
|
|
94
|
+
Upload to the prod PyPi.
|
|
95
|
+
```
|
|
96
|
+
make -s pypi-upload-prod
|
|
97
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Functions and routines associated with Enasis Network Homie Automate.
|
|
3
|
+
|
|
4
|
+
This file is part of Enasis Network software eco-system. Distribution
|
|
5
|
+
is permitted, for more information consult the project license file.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
from os import environ
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
PROJECT = Path(__file__).parent
|
|
16
|
+
WORKSPACE = PROJECT.parents[2]
|
|
17
|
+
|
|
18
|
+
VERSION = (
|
|
19
|
+
PROJECT
|
|
20
|
+
.joinpath('version.txt')
|
|
21
|
+
.read_text(encoding='utf-8')
|
|
22
|
+
.splitlines()[0].strip())
|
|
23
|
+
|
|
24
|
+
__version__ = VERSION
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
ENPYRWS = (
|
|
29
|
+
environ.get('ENPYRWS') == '1')
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Functions and routines associated with Enasis Network Homie Automate.
|
|
3
|
+
|
|
4
|
+
This file is part of Enasis Network software eco-system. Distribution
|
|
5
|
+
is permitted, for more information consult the project license file.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
from .params import WhenTimePeriodParams
|
|
11
|
+
from .when import chck_time_period
|
|
12
|
+
from .when import when_time_period
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
'WhenTimePeriodParams',
|
|
18
|
+
'chck_time_period',
|
|
19
|
+
'when_time_period']
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Functions and routines associated with Enasis Network Homie Automate.
|
|
3
|
+
|
|
4
|
+
This file is part of Enasis Network software eco-system. Distribution
|
|
5
|
+
is permitted, for more information consult the project license file.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
from typing import Any
|
|
11
|
+
from typing import Optional
|
|
12
|
+
|
|
13
|
+
from encommon.times import Times
|
|
14
|
+
|
|
15
|
+
from pydantic import BaseModel
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class WhenTimePeriodParams(BaseModel, extra='forbid'):
|
|
20
|
+
"""
|
|
21
|
+
Process and validate the Homie configuration parameters.
|
|
22
|
+
|
|
23
|
+
:param start: Determine the start for the desired period.
|
|
24
|
+
:param stop: Determine the ending for the desired period.
|
|
25
|
+
:param tzname: Name of the timezone associated to period.
|
|
26
|
+
:param data: Keyword arguments passed to Pydantic model.
|
|
27
|
+
Parameter is picked up by autodoc, please ignore.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
start: Optional[str] = None
|
|
31
|
+
stop: Optional[str] = None
|
|
32
|
+
tzname: str = 'UTC'
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def __init__(
|
|
36
|
+
self,
|
|
37
|
+
**data: Any,
|
|
38
|
+
) -> None:
|
|
39
|
+
"""
|
|
40
|
+
Initialize instance for class using provided parameters.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
start = data.get('start')
|
|
44
|
+
stop = data.get('stop')
|
|
45
|
+
tzname = data.get('tzname')
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if start is not None:
|
|
49
|
+
start = Times(
|
|
50
|
+
source=start,
|
|
51
|
+
tzname=tzname)
|
|
52
|
+
|
|
53
|
+
if stop is not None:
|
|
54
|
+
stop = Times(
|
|
55
|
+
source=stop,
|
|
56
|
+
tzname=tzname)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if (start and stop
|
|
60
|
+
and stop <= start):
|
|
61
|
+
stop = stop.shift('+1d')
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if start is not None:
|
|
65
|
+
data['start'] = start.simple
|
|
66
|
+
|
|
67
|
+
if stop is not None:
|
|
68
|
+
data['stop'] = stop.simple
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
super().__init__(**data)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Functions and routines associated with Enasis Network Homie Automate.
|
|
3
|
+
|
|
4
|
+
This file is part of Enasis Network software eco-system. Distribution
|
|
5
|
+
is permitted, for more information consult the project license file.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
from encommon.times import Times
|
|
11
|
+
|
|
12
|
+
from ..params import WhenTimePeriodParams
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_WhenTimePeriodParams() -> None:
|
|
17
|
+
"""
|
|
18
|
+
Perform various tests associated with relevant routines.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
anchor = Times('now')
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
start = anchor.shift('-1h@s')
|
|
25
|
+
stop = anchor.shift('+1h@s')
|
|
26
|
+
|
|
27
|
+
when = WhenTimePeriodParams(
|
|
28
|
+
start=start,
|
|
29
|
+
stop=stop)
|
|
30
|
+
|
|
31
|
+
assert when.start and when.stop
|
|
32
|
+
|
|
33
|
+
assert when.start == start
|
|
34
|
+
assert when.stop == stop
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
start = anchor.shift('-1h@s')
|
|
38
|
+
stop = anchor.shift('-2h@s')
|
|
39
|
+
|
|
40
|
+
when = WhenTimePeriodParams(
|
|
41
|
+
start=start,
|
|
42
|
+
stop=stop)
|
|
43
|
+
|
|
44
|
+
assert when.start and when.stop
|
|
45
|
+
|
|
46
|
+
assert when.start == start
|
|
47
|
+
assert when.stop >= start
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Functions and routines associated with Enasis Network Homie Automate.
|
|
3
|
+
|
|
4
|
+
This file is part of Enasis Network software eco-system. Distribution
|
|
5
|
+
is permitted, for more information consult the project license file.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
from typing import TYPE_CHECKING
|
|
11
|
+
|
|
12
|
+
from ..params import WhenTimePeriodParams
|
|
13
|
+
from ...homie import HomieWhen
|
|
14
|
+
from ...homie import HomieWhenParams
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from ...homie import Homie
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_when_time_period(
|
|
22
|
+
homie: 'Homie',
|
|
23
|
+
) -> None:
|
|
24
|
+
"""
|
|
25
|
+
Perform various tests associated with relevant routines.
|
|
26
|
+
|
|
27
|
+
:param homie: Primary class instance for Homie Automate.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
time_period = (
|
|
32
|
+
WhenTimePeriodParams(
|
|
33
|
+
start='+2d'))
|
|
34
|
+
|
|
35
|
+
params = HomieWhenParams(
|
|
36
|
+
time_period=time_period)
|
|
37
|
+
|
|
38
|
+
when = HomieWhen(homie, params)
|
|
39
|
+
|
|
40
|
+
assert when.outcome is False
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
time_period = (
|
|
44
|
+
WhenTimePeriodParams(
|
|
45
|
+
start='-2d'))
|
|
46
|
+
|
|
47
|
+
params = HomieWhenParams(
|
|
48
|
+
time_period=time_period)
|
|
49
|
+
|
|
50
|
+
when = HomieWhen(homie, params)
|
|
51
|
+
|
|
52
|
+
assert when.outcome is True
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
time_period = (
|
|
56
|
+
WhenTimePeriodParams(
|
|
57
|
+
start='-2d',
|
|
58
|
+
stop='-1d'))
|
|
59
|
+
|
|
60
|
+
params = HomieWhenParams(
|
|
61
|
+
time_period=time_period)
|
|
62
|
+
|
|
63
|
+
when = HomieWhen(homie, params)
|
|
64
|
+
|
|
65
|
+
assert when.outcome is False
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Functions and routines associated with Enasis Network Homie Automate.
|
|
3
|
+
|
|
4
|
+
This file is part of Enasis Network software eco-system. Distribution
|
|
5
|
+
is permitted, for more information consult the project license file.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
from typing import Optional
|
|
11
|
+
from typing import TYPE_CHECKING
|
|
12
|
+
|
|
13
|
+
from encommon.times import Times
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from ..homie import HomieWhen
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def when_time_period(
|
|
21
|
+
when: 'HomieWhen',
|
|
22
|
+
) -> bool:
|
|
23
|
+
"""
|
|
24
|
+
Return the boolean indicating whether condition matched.
|
|
25
|
+
|
|
26
|
+
:param when: Primary class instance for the conditonal.
|
|
27
|
+
:returns: Boolean indicating whether condition matched.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
params = (
|
|
31
|
+
when.params.time_period)
|
|
32
|
+
|
|
33
|
+
assert params is not None
|
|
34
|
+
|
|
35
|
+
start = params.start
|
|
36
|
+
stop = params.stop
|
|
37
|
+
tzname = params.tzname
|
|
38
|
+
|
|
39
|
+
anchor = Times(tzname=tzname)
|
|
40
|
+
|
|
41
|
+
assert (
|
|
42
|
+
start is not None
|
|
43
|
+
or stop is not None)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
_start: Optional[Times] = (
|
|
47
|
+
Times(start)
|
|
48
|
+
if start is not None
|
|
49
|
+
else None)
|
|
50
|
+
|
|
51
|
+
_stop: Optional[Times] = (
|
|
52
|
+
Times(stop)
|
|
53
|
+
if stop is not None
|
|
54
|
+
else None)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
matched = True
|
|
58
|
+
|
|
59
|
+
if (_start is not None
|
|
60
|
+
and anchor < _start):
|
|
61
|
+
matched = False
|
|
62
|
+
|
|
63
|
+
if (_stop is not None
|
|
64
|
+
and anchor > _stop):
|
|
65
|
+
matched = False
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
return matched
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def chck_time_period(
|
|
73
|
+
when: 'HomieWhen',
|
|
74
|
+
) -> None:
|
|
75
|
+
"""
|
|
76
|
+
Return the boolean indicating whether conditional valid.
|
|
77
|
+
|
|
78
|
+
:param when: Primary class instance for the conditonal.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
params = (
|
|
82
|
+
when.params.time_period)
|
|
83
|
+
|
|
84
|
+
assert params is not None
|
|
85
|
+
|
|
86
|
+
start = params.start
|
|
87
|
+
stop = params.stop
|
|
88
|
+
tzname = params.tzname
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if start is not None:
|
|
92
|
+
Times(start, tzname=tzname)
|
|
93
|
+
|
|
94
|
+
if stop is not None:
|
|
95
|
+
Times(stop, tzname=tzname)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Functions and routines associated with Enasis Network Homie Automate.
|
|
3
|
+
|
|
4
|
+
This file is part of Enasis Network software eco-system. Distribution
|
|
5
|
+
is permitted, for more information consult the project license file.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
from .config import Config
|
|
11
|
+
from .params import Params
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
'Config',
|
|
17
|
+
'Params']
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Functions and routines associated with Enasis Network Homie Automate.
|
|
3
|
+
|
|
4
|
+
This file is part of Enasis Network software eco-system. Distribution
|
|
5
|
+
is permitted, for more information consult the project license file.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
from contextlib import suppress
|
|
11
|
+
from typing import Optional
|
|
12
|
+
|
|
13
|
+
from encommon.config import Config as _Config
|
|
14
|
+
from encommon.types import merge_dicts
|
|
15
|
+
from encommon.utils.common import PATHABLE
|
|
16
|
+
|
|
17
|
+
from .params import Params
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Config(_Config):
|
|
22
|
+
"""
|
|
23
|
+
Contain the configurations from the arguments and files.
|
|
24
|
+
|
|
25
|
+
:param files: Complete or relative path to config files.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
files: Optional[PATHABLE] = None,
|
|
32
|
+
) -> None:
|
|
33
|
+
"""
|
|
34
|
+
Initialize instance for class using provided parameters.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
super().__init__(
|
|
38
|
+
files=files,
|
|
39
|
+
model=Params)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def params(
|
|
44
|
+
self,
|
|
45
|
+
) -> Params:
|
|
46
|
+
"""
|
|
47
|
+
Return the Pydantic model containing the configuration.
|
|
48
|
+
|
|
49
|
+
.. warning::
|
|
50
|
+
This method completely overrides the parent but is
|
|
51
|
+
based on that code, would be unfortunate if upstream
|
|
52
|
+
changes meant this breaks or breaks something else.
|
|
53
|
+
|
|
54
|
+
:returns: Pydantic model containing the configuration.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
params = self.__params
|
|
58
|
+
|
|
59
|
+
if isinstance(params, Params):
|
|
60
|
+
return params
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
merged = self.files.merged
|
|
64
|
+
|
|
65
|
+
merge_dicts(
|
|
66
|
+
dict1=merged,
|
|
67
|
+
dict2=self.cargs,
|
|
68
|
+
force=True)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
update_params = False
|
|
72
|
+
|
|
73
|
+
with suppress(AttributeError):
|
|
74
|
+
|
|
75
|
+
_merged = self.paths.merged
|
|
76
|
+
|
|
77
|
+
for _merge in _merged.values():
|
|
78
|
+
|
|
79
|
+
merge_dicts(
|
|
80
|
+
dict1=merged,
|
|
81
|
+
dict2=_merge,
|
|
82
|
+
force=False)
|
|
83
|
+
|
|
84
|
+
update_params = True
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
params = self.model(**merged)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
if update_params is True:
|
|
91
|
+
self.__params = params
|
|
92
|
+
|
|
93
|
+
assert isinstance(params, Params)
|
|
94
|
+
|
|
95
|
+
return params
|