PyPlumIO 0.4.1__py3-none-any.whl → 0.4.2__py3-none-any.whl
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.
- {PyPlumIO-0.4.1.dist-info → PyPlumIO-0.4.2.dist-info}/METADATA +1 -1
- {PyPlumIO-0.4.1.dist-info → PyPlumIO-0.4.2.dist-info}/RECORD +9 -9
- pyplumio/_version.py +2 -2
- pyplumio/const.py +2 -0
- pyplumio/filters.py +63 -27
- pyplumio/helpers/typing.py +9 -1
- {PyPlumIO-0.4.1.dist-info → PyPlumIO-0.4.2.dist-info}/LICENSE +0 -0
- {PyPlumIO-0.4.1.dist-info → PyPlumIO-0.4.2.dist-info}/WHEEL +0 -0
- {PyPlumIO-0.4.1.dist-info → PyPlumIO-0.4.2.dist-info}/top_level.txt +0 -0
@@ -1,10 +1,10 @@
|
|
1
1
|
pyplumio/__init__.py,sha256=HZuhLA98rflVEU5cc2-UpboDSJUW1e6Eocfdok9MHZM,1273
|
2
2
|
pyplumio/__main__.py,sha256=j8fh3P6yGwB1qumdUlW8X22-DOwisdo4IcUEmlYPGbM,497
|
3
|
-
pyplumio/_version.py,sha256=
|
3
|
+
pyplumio/_version.py,sha256=MHz4IpMPBfgMjF4EUb11AphGoLXSC-lOtHXxzKzJNjk,160
|
4
4
|
pyplumio/connection.py,sha256=ABeJFbnqTq89i5J1TRR2sdQeRrq1Pewdi_TaDjzSOOI,5494
|
5
|
-
pyplumio/const.py,sha256=
|
5
|
+
pyplumio/const.py,sha256=qCsgmv-uIjLBae46AlMMPPHxag301LJaRTUo9NLmU2M,3039
|
6
6
|
pyplumio/exceptions.py,sha256=cpLGRl9db6cU1Z6WXhQ7yl1V7Te193QymWiOoRF8KAI,798
|
7
|
-
pyplumio/filters.py,sha256=
|
7
|
+
pyplumio/filters.py,sha256=MM3l67Iq0Xm2aZRPkAOAxoeaMT3cTsF-vL95Sid4GTM,6548
|
8
8
|
pyplumio/protocol.py,sha256=h90uhCcqscukJ0GVX6rYv_LH5UsE2om87ZXo3EWZ77s,6223
|
9
9
|
pyplumio/stream.py,sha256=n1dae3oKnnU0XWsVgzVszXPdVXkYChdw-bUTKcHr05s,3738
|
10
10
|
pyplumio/util.py,sha256=oKKO9eJmrmXf0XHZG5P4fGR_R1jMSU_BAXU82ZnDS8Y,2603
|
@@ -25,7 +25,7 @@ pyplumio/helpers/parameter.py,sha256=4PxOQg0jFAPwrdQkwLXjaey-CgDCGsNCcglldk2zwm4
|
|
25
25
|
pyplumio/helpers/schedule.py,sha256=pbKRqcU48IRrEKZQOncBQkz_WExxjtDDHZ3x-MHpVIg,4077
|
26
26
|
pyplumio/helpers/task_manager.py,sha256=fhqbSNaInoWXL3YjkFe_sCgh8suOwRnufqWBrXIgPeM,1026
|
27
27
|
pyplumio/helpers/timeout.py,sha256=az12syvMGhTxzeiLGZIcJYG6MI4t6LCZeZyt6viRh04,846
|
28
|
-
pyplumio/helpers/typing.py,sha256=
|
28
|
+
pyplumio/helpers/typing.py,sha256=wDy-TLxLAF_jrw8QW5g4EZpbV8unRYqH_VO8s6VnIYE,557
|
29
29
|
pyplumio/helpers/uid.py,sha256=Gt1l9gs-RMummmpfu5IoRokGurxRzJeWZrfwiyeGR9c,1044
|
30
30
|
pyplumio/structures/__init__.py,sha256=imqgigigBkwDpHKLwiLTrAh0vqaYcvnm8Y5676uT07Y,1482
|
31
31
|
pyplumio/structures/alerts.py,sha256=_AIsA_Uvp2xm8JiQ7a3jt7VuZWcFiNHYtZTOHBAFIkQ,2644
|
@@ -53,8 +53,8 @@ pyplumio/structures/statuses.py,sha256=BeSOabFIewiUBxAXgsuxzjRi4Zl-_O2qDbn61w7Dt
|
|
53
53
|
pyplumio/structures/temperatures.py,sha256=lPRYCCciaGTBU_ShWwz_bWHvsfIRL3n16CnTbZK9iC4,2298
|
54
54
|
pyplumio/structures/thermostat_parameters.py,sha256=M-VpUb7z-0rsES-PqUKpdmWP8TcV9IACkS6yPx4ivqo,6399
|
55
55
|
pyplumio/structures/thermostat_sensors.py,sha256=yU5F2KXnpOMyHSdAfoIY6JmEIlSYMf05qmyvN0F4A5c,2236
|
56
|
-
PyPlumIO-0.4.
|
57
|
-
PyPlumIO-0.4.
|
58
|
-
PyPlumIO-0.4.
|
59
|
-
PyPlumIO-0.4.
|
60
|
-
PyPlumIO-0.4.
|
56
|
+
PyPlumIO-0.4.2.dist-info/LICENSE,sha256=g56wJgobsehVtkJD8MhM6isAnsdOUmRPv7fIaXI4Joo,1067
|
57
|
+
PyPlumIO-0.4.2.dist-info/METADATA,sha256=8iQtMCrvNMnHyiN7p0q3XjcSR6sbljW4FEQJ3rjF0Eo,4792
|
58
|
+
PyPlumIO-0.4.2.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
59
|
+
PyPlumIO-0.4.2.dist-info/top_level.txt,sha256=kNBz9UPPkPD9teDn3U_sEy5LjzwLm9KfADCXtBlbw8A,9
|
60
|
+
PyPlumIO-0.4.2.dist-info/RECORD,,
|
pyplumio/_version.py
CHANGED
pyplumio/const.py
CHANGED
pyplumio/filters.py
CHANGED
@@ -4,34 +4,70 @@ from __future__ import annotations
|
|
4
4
|
from abc import ABC, abstractmethod
|
5
5
|
import math
|
6
6
|
import time
|
7
|
-
from typing import Any, Final
|
7
|
+
from typing import Any, Final, SupportsFloat, SupportsIndex, overload
|
8
8
|
|
9
|
+
from pyplumio.const import UNDEFINED
|
9
10
|
from pyplumio.helpers.parameter import Parameter
|
10
|
-
from pyplumio.helpers.typing import EventCallbackType
|
11
|
+
from pyplumio.helpers.typing import EventCallbackType, SupportsSubtraction
|
11
12
|
|
12
13
|
TOLERANCE: Final = 0.1
|
13
14
|
|
14
15
|
|
15
|
-
|
16
|
+
@overload
|
17
|
+
def _significantly_changed(old: Parameter, new: Parameter) -> bool:
|
18
|
+
"""Check if parameter is significantly changed."""
|
19
|
+
|
20
|
+
|
21
|
+
@overload
|
22
|
+
def _significantly_changed(
|
23
|
+
old: SupportsFloat | SupportsIndex, new: SupportsFloat | SupportsIndex
|
24
|
+
) -> bool:
|
25
|
+
"""Check if float value is significantly changed."""
|
26
|
+
|
27
|
+
|
28
|
+
def _significantly_changed(old, new) -> bool:
|
16
29
|
"""Check if value is significantly changed."""
|
17
|
-
if
|
30
|
+
if old == UNDEFINED:
|
18
31
|
return True
|
19
32
|
|
33
|
+
if isinstance(old, Parameter) and old.is_changed:
|
34
|
+
return True
|
35
|
+
|
36
|
+
if isinstance(old, Parameter) and isinstance(new, Parameter):
|
37
|
+
return (
|
38
|
+
old.value != new.value
|
39
|
+
or old.min_value != new.min_value
|
40
|
+
or old.max_value != new.max_value
|
41
|
+
)
|
42
|
+
|
20
43
|
try:
|
21
|
-
return not math.isclose(
|
44
|
+
return not math.isclose(old, new, abs_tol=TOLERANCE)
|
22
45
|
except TypeError:
|
23
46
|
pass
|
24
47
|
|
25
|
-
return
|
48
|
+
return old != new
|
49
|
+
|
50
|
+
|
51
|
+
@overload
|
52
|
+
def _diffence_between(old: list, new: list) -> list:
|
53
|
+
"""Return the difference between lists."""
|
26
54
|
|
27
55
|
|
28
|
-
|
56
|
+
@overload
|
57
|
+
def _diffence_between(old: SupportsSubtraction, new: SupportsSubtraction) -> list:
|
58
|
+
"""Return the difference between lists."""
|
59
|
+
|
60
|
+
|
61
|
+
def _diffence_between(old, new):
|
29
62
|
"""Return the difference between values."""
|
30
|
-
if
|
31
|
-
return
|
63
|
+
if old == UNDEFINED:
|
64
|
+
return None
|
65
|
+
|
66
|
+
if isinstance(old, list) and isinstance(new, list):
|
67
|
+
return [x for x in new if x not in old]
|
32
68
|
|
33
|
-
if hasattr(
|
34
|
-
return
|
69
|
+
if hasattr(old, "__sub__") and hasattr(new, "__sub__"):
|
70
|
+
return new - old
|
35
71
|
|
36
72
|
return None
|
37
73
|
|
@@ -40,12 +76,12 @@ class Filter(ABC):
|
|
40
76
|
"""Represents base for value callback modifiers."""
|
41
77
|
|
42
78
|
_callback: Any
|
43
|
-
_value: Any
|
79
|
+
_value: Any = UNDEFINED
|
44
80
|
|
45
81
|
def __init__(self, callback: EventCallbackType):
|
46
82
|
"""Initialize new Filter object."""
|
47
83
|
self._callback = callback
|
48
|
-
self._value =
|
84
|
+
self._value = UNDEFINED
|
49
85
|
|
50
86
|
def __eq__(self, other) -> bool:
|
51
87
|
"""Compare debounced callbacks."""
|
@@ -59,21 +95,21 @@ class Filter(ABC):
|
|
59
95
|
|
60
96
|
@abstractmethod
|
61
97
|
async def __call__(self, new_value):
|
62
|
-
"""Set new value for the callback."""
|
98
|
+
"""Set a new value for the callback."""
|
63
99
|
|
64
100
|
|
65
101
|
class _OnChange(Filter):
|
66
102
|
"""Provides changed functionality to the callback."""
|
67
103
|
|
68
104
|
async def __call__(self, new_value):
|
69
|
-
"""Set new value for the callback."""
|
105
|
+
"""Set a new value for the callback."""
|
70
106
|
if _significantly_changed(self._value, new_value):
|
71
107
|
self._value = new_value
|
72
108
|
return await self._callback(new_value)
|
73
109
|
|
74
110
|
|
75
111
|
def on_change(callback: EventCallbackType) -> _OnChange:
|
76
|
-
"""Helper for change callback filter."""
|
112
|
+
"""Helper for a change callback filter."""
|
77
113
|
return _OnChange(callback)
|
78
114
|
|
79
115
|
|
@@ -90,20 +126,20 @@ class _Debounce(Filter):
|
|
90
126
|
self._min_calls = min_calls
|
91
127
|
|
92
128
|
async def __call__(self, new_value):
|
93
|
-
"""Set new value for the callback."""
|
129
|
+
"""Set a new value for the callback."""
|
94
130
|
if _significantly_changed(self._value, new_value):
|
95
131
|
self._calls += 1
|
96
132
|
else:
|
97
133
|
self._calls = 0
|
98
134
|
|
99
|
-
if self.
|
135
|
+
if self._value == UNDEFINED or self._calls >= self._min_calls:
|
100
136
|
self._value = new_value
|
101
137
|
self._calls = 0
|
102
138
|
return await self._callback(new_value)
|
103
139
|
|
104
140
|
|
105
141
|
def debounce(callback: EventCallbackType, min_calls) -> _Debounce:
|
106
|
-
"""Helper method for debounce callback filter."""
|
142
|
+
"""Helper method for a debounce callback filter."""
|
107
143
|
return _Debounce(callback, min_calls)
|
108
144
|
|
109
145
|
|
@@ -120,7 +156,7 @@ class _Throttle(Filter):
|
|
120
156
|
self._timeout = seconds
|
121
157
|
|
122
158
|
async def __call__(self, new_value):
|
123
|
-
"""
|
159
|
+
"""Set a new value for the callback."""
|
124
160
|
current_timestamp = time.monotonic()
|
125
161
|
if (
|
126
162
|
self._last_called is None
|
@@ -131,7 +167,7 @@ class _Throttle(Filter):
|
|
131
167
|
|
132
168
|
|
133
169
|
def throttle(callback: EventCallbackType, seconds: float) -> _Throttle:
|
134
|
-
"""Helper method for throttle callback filter."""
|
170
|
+
"""Helper method for a throttle callback filter."""
|
135
171
|
return _Throttle(callback, seconds)
|
136
172
|
|
137
173
|
|
@@ -139,16 +175,16 @@ class _Delta(Filter):
|
|
139
175
|
"""Provides ability to pass call difference to the callback."""
|
140
176
|
|
141
177
|
async def __call__(self, new_value):
|
142
|
-
"""
|
143
|
-
|
144
|
-
|
178
|
+
"""Set new value for the callback."""
|
179
|
+
if _significantly_changed(self._value, new_value):
|
180
|
+
old_value = self._value
|
145
181
|
self._value = new_value
|
146
182
|
if (difference := _diffence_between(old_value, new_value)) is not None:
|
147
183
|
return await self._callback(difference)
|
148
184
|
|
149
185
|
|
150
186
|
def delta(callback: EventCallbackType) -> _Delta:
|
151
|
-
"""Helper method for delta callback filter."""
|
187
|
+
"""Helper method for a delta callback filter."""
|
152
188
|
return _Delta(callback)
|
153
189
|
|
154
190
|
|
@@ -168,7 +204,7 @@ class _Aggregate(Filter):
|
|
168
204
|
self._sum = 0.0
|
169
205
|
|
170
206
|
async def __call__(self, new_value):
|
171
|
-
"""Set new value for the callback."""
|
207
|
+
"""Set a new value for the callback."""
|
172
208
|
current_timestamp = time.monotonic()
|
173
209
|
try:
|
174
210
|
self._sum += new_value
|
@@ -185,5 +221,5 @@ class _Aggregate(Filter):
|
|
185
221
|
|
186
222
|
|
187
223
|
def aggregate(callback: EventCallbackType, seconds: float) -> _Aggregate:
|
188
|
-
"""Helper method for total callback filter."""
|
224
|
+
"""Helper method for a total callback filter."""
|
189
225
|
return _Aggregate(callback, seconds)
|
pyplumio/helpers/typing.py
CHANGED
@@ -2,9 +2,17 @@
|
|
2
2
|
from __future__ import annotations
|
3
3
|
|
4
4
|
from collections.abc import Awaitable, Callable
|
5
|
-
from typing import Any, Literal, Union
|
5
|
+
from typing import Any, Literal, Protocol, Union
|
6
6
|
|
7
7
|
ParameterDataType = tuple[int, int, int]
|
8
8
|
ParameterValueType = Union[int, float, bool, Literal["off"], Literal["on"]]
|
9
9
|
EventDataType = dict[Union[str, int], Any]
|
10
10
|
EventCallbackType = Callable[[Any], Awaitable[Any]]
|
11
|
+
UndefinedType = Literal["undefined"]
|
12
|
+
|
13
|
+
|
14
|
+
class SupportsSubtraction(Protocol):
|
15
|
+
"""Supports subtraction operation."""
|
16
|
+
|
17
|
+
def __sub__(self, other):
|
18
|
+
"""Subtracts a value."""
|
File without changes
|
File without changes
|
File without changes
|