pysmarlaapi 0.5.1__py3-none-any.whl → 0.6.1__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.

Potentially problematic release.


This version of pysmarlaapi might be problematic. Click here for more details.

@@ -1,46 +1,46 @@
1
- import asyncio
2
- from typing import Generic, TypeVar
3
-
4
- from ...connection_hub import ConnectionHub
5
-
6
- _VT = TypeVar("_VT")
7
-
8
-
9
- class Property(Generic[_VT]):
10
-
11
- def __init__(self, hub: ConnectionHub):
12
- self.hub = hub
13
- self.value: _VT = None
14
- self.listeners = set()
15
- self.lock = asyncio.Lock()
16
-
17
- async def add_listener(self, listener):
18
- async with self.lock:
19
- self.listeners.add(listener)
20
-
21
- async def remove_listener(self, listener):
22
- async with self.lock:
23
- self.listeners.remove(listener)
24
-
25
- async def notify_listeners(self, value):
26
- async with self.lock:
27
- for listener in self.listeners:
28
- await listener(value)
29
-
30
- def get(self) -> _VT:
31
- return self.value
32
-
33
- def set(self, new_value: _VT, push=True):
34
- if push:
35
- self.push(new_value)
36
- else:
37
- self.value = new_value
38
-
39
- def push(self, value: _VT):
40
- pass
41
-
42
- def pull(self):
43
- pass
44
-
45
- def register(self):
46
- pass
1
+ import asyncio
2
+ from typing import Generic, TypeVar
3
+
4
+ from ...connection_hub import ConnectionHub
5
+
6
+ _VT = TypeVar("_VT")
7
+
8
+
9
+ class Property(Generic[_VT]):
10
+
11
+ def __init__(self, hub: ConnectionHub):
12
+ self.hub = hub
13
+ self.value: _VT = None
14
+ self.listeners = set()
15
+ self.lock = asyncio.Lock()
16
+
17
+ async def add_listener(self, listener):
18
+ async with self.lock:
19
+ self.listeners.add(listener)
20
+
21
+ async def remove_listener(self, listener):
22
+ async with self.lock:
23
+ self.listeners.remove(listener)
24
+
25
+ async def notify_listeners(self, value):
26
+ async with self.lock:
27
+ for listener in self.listeners:
28
+ await listener(value)
29
+
30
+ def get(self) -> _VT:
31
+ return self.value
32
+
33
+ def set(self, new_value: _VT, push=True):
34
+ if push:
35
+ self.push(new_value)
36
+ else:
37
+ self.value = new_value
38
+
39
+ def push(self, value: _VT):
40
+ pass
41
+
42
+ def pull(self):
43
+ pass
44
+
45
+ def register(self):
46
+ pass
@@ -1,28 +1,28 @@
1
- from .property import Property
2
-
3
-
4
- class Service:
5
-
6
- def __init__(self):
7
- self.registered = False
8
- self.props: dict[str, Property] = {}
9
-
10
- def add_property(self, key: str, prop: Property):
11
- self.props[key] = prop
12
-
13
- def get_properties(self):
14
- return self.props
15
-
16
- def get_property(self, key: str):
17
- if key not in self.props:
18
- return None
19
- return self.props[key]
20
-
21
- def register(self):
22
- for prop in self.props.values():
23
- prop.register()
24
- self.registered = True
25
-
26
- def sync(self):
27
- for prop in self.props.values():
28
- prop.pull()
1
+ from .property import Property
2
+
3
+
4
+ class Service:
5
+
6
+ def __init__(self):
7
+ self.registered = False
8
+ self.props: dict[str, Property] = {}
9
+
10
+ def add_property(self, key: str, prop: Property):
11
+ self.props[key] = prop
12
+
13
+ def get_properties(self):
14
+ return self.props
15
+
16
+ def get_property(self, key: str):
17
+ if key not in self.props:
18
+ return None
19
+ return self.props[key]
20
+
21
+ def register(self):
22
+ for prop in self.props.values():
23
+ prop.register()
24
+ self.registered = True
25
+
26
+ def sync(self):
27
+ for prop in self.props.values():
28
+ prop.pull()
@@ -1,3 +1,3 @@
1
- from .analyser_service import AnalyserService
2
- from .babywiege_service import BabywiegeService
3
- from .info_service import InfoService
1
+ from .analyser_service import AnalyserService
2
+ from .babywiege_service import BabywiegeService
3
+ from .info_service import InfoService
@@ -1,65 +1,65 @@
1
- from ...connection_hub import ConnectionHub
2
- from ..classes import Property, Service
3
-
4
-
5
- class AnalyserService(Service):
6
-
7
- def __init__(self, hub: ConnectionHub):
8
- super().__init__()
9
- self.add_property("oscillation", OscillationProperty(hub))
10
- self.add_property("activity", ActivityProperty(hub))
11
- self.add_property("swing_count", SwingCountProperty(hub))
12
-
13
-
14
- class OscillationProperty(Property[list[int, int]]):
15
-
16
- async def on_callback(self, args):
17
- value = args[0]["value"]
18
- self.set(value, push=False)
19
- await self.notify_listeners(value)
20
-
21
- def __init__(self, hub: ConnectionHub):
22
- super().__init__(hub)
23
- self.value = [0, 0]
24
-
25
- def pull(self):
26
- self.hub.send_serialized_data("GetOscillation")
27
-
28
- def register(self):
29
- self.hub.client.on("GetOscillationCallback", self.on_callback)
30
-
31
-
32
- class ActivityProperty(Property[int]):
33
-
34
- async def on_callback(self, args):
35
- value = args[0]["value"]
36
- self.set(value, push=False)
37
- await self.notify_listeners(value)
38
-
39
- def __init__(self, hub: ConnectionHub):
40
- super().__init__(hub)
41
- self.value = 0
42
-
43
- def pull(self):
44
- self.hub.send_serialized_data("GetActivity")
45
-
46
- def register(self):
47
- self.hub.client.on("GetActivityCallback", self.on_callback)
48
-
49
-
50
- class SwingCountProperty(Property[int]):
51
-
52
- async def on_callback(self, args):
53
- value = args[0]["value"]
54
- self.set(value, push=False)
55
- await self.notify_listeners(value)
56
-
57
- def __init__(self, hub: ConnectionHub):
58
- super().__init__(hub)
59
- self.value = 0
60
-
61
- def pull(self):
62
- self.hub.send_serialized_data("GetSwingCount")
63
-
64
- def register(self):
65
- self.hub.client.on("GetSwingCountCallback", self.on_callback)
1
+ from ...connection_hub import ConnectionHub
2
+ from ..classes import Property, Service
3
+
4
+
5
+ class AnalyserService(Service):
6
+
7
+ def __init__(self, hub: ConnectionHub):
8
+ super().__init__()
9
+ self.add_property("oscillation", OscillationProperty(hub))
10
+ self.add_property("activity", ActivityProperty(hub))
11
+ self.add_property("swing_count", SwingCountProperty(hub))
12
+
13
+
14
+ class OscillationProperty(Property[list[int, int]]):
15
+
16
+ async def on_callback(self, args):
17
+ value = args[0]["value"]
18
+ self.set(value, push=False)
19
+ await self.notify_listeners(value)
20
+
21
+ def __init__(self, hub: ConnectionHub):
22
+ super().__init__(hub)
23
+ self.value = [0, 0]
24
+
25
+ def pull(self):
26
+ self.hub.send_serialized_data("GetOscillation")
27
+
28
+ def register(self):
29
+ self.hub.client.on("GetOscillationCallback", self.on_callback)
30
+
31
+
32
+ class ActivityProperty(Property[int]):
33
+
34
+ async def on_callback(self, args):
35
+ value = args[0]["value"]
36
+ self.set(value, push=False)
37
+ await self.notify_listeners(value)
38
+
39
+ def __init__(self, hub: ConnectionHub):
40
+ super().__init__(hub)
41
+ self.value = 0
42
+
43
+ def pull(self):
44
+ self.hub.send_serialized_data("GetActivity")
45
+
46
+ def register(self):
47
+ self.hub.client.on("GetActivityCallback", self.on_callback)
48
+
49
+
50
+ class SwingCountProperty(Property[int]):
51
+
52
+ async def on_callback(self, args):
53
+ value = args[0]["value"]
54
+ self.set(value, push=False)
55
+ await self.notify_listeners(value)
56
+
57
+ def __init__(self, hub: ConnectionHub):
58
+ super().__init__(hub)
59
+ self.value = 0
60
+
61
+ def pull(self):
62
+ self.hub.send_serialized_data("GetSwingCount")
63
+
64
+ def register(self):
65
+ self.hub.client.on("GetSwingCountCallback", self.on_callback)
@@ -1,74 +1,74 @@
1
- from ...connection_hub import ConnectionHub
2
- from ..classes import Property, Service
3
-
4
-
5
- class BabywiegeService(Service):
6
-
7
- def __init__(self, hub: ConnectionHub):
8
- super().__init__()
9
- self.add_property("swing_active", SwingActiveProperty(hub))
10
- self.add_property("intensity", IntensityProperty(hub))
11
- self.add_property("smartmode", SmartModeProperty(hub))
12
-
13
-
14
- class SwingActiveProperty(Property[bool]):
15
-
16
- async def on_callback(self, args):
17
- value = args[0]["value"]
18
- self.set(value, push=False)
19
- await self.notify_listeners(value)
20
-
21
- def __init__(self, hub: ConnectionHub):
22
- super().__init__(hub)
23
- self.value = False
24
-
25
- def pull(self):
26
- self.hub.send_serialized_data("GetSwingActive")
27
-
28
- def push(self, value: bool):
29
- self.hub.send_serialized_data("SetSwingActive", value)
30
-
31
- def register(self):
32
- self.hub.client.on("GetSwingActiveCallback", self.on_callback)
33
-
34
-
35
- class IntensityProperty(Property[int]):
36
-
37
- async def on_callback(self, args):
38
- value = args[0]["value"]
39
- self.set(value, push=False)
40
- await self.notify_listeners(value)
41
-
42
- def __init__(self, hub: ConnectionHub):
43
- super().__init__(hub)
44
- self.value = 0
45
-
46
- def pull(self):
47
- self.hub.send_serialized_data("GetIntensity")
48
-
49
- def push(self, value: int):
50
- self.hub.send_serialized_data("SetIntensity", value)
51
-
52
- def register(self):
53
- self.hub.client.on("GetIntensityCallback", self.on_callback)
54
-
55
-
56
- class SmartModeProperty(Property[bool]):
57
-
58
- async def on_callback(self, args):
59
- value = args[0]["value"]
60
- self.set(value, push=False)
61
- await self.notify_listeners(value)
62
-
63
- def __init__(self, hub: ConnectionHub):
64
- super().__init__(hub)
65
- self.value = False
66
-
67
- def pull(self):
68
- self.hub.send_serialized_data("GetSmartMode")
69
-
70
- def push(self, value: bool):
71
- self.hub.send_serialized_data("SetSmartMode", value)
72
-
73
- def register(self):
74
- self.hub.client.on("GetSmartModeCallback", self.on_callback)
1
+ from ...connection_hub import ConnectionHub
2
+ from ..classes import Property, Service
3
+
4
+
5
+ class BabywiegeService(Service):
6
+
7
+ def __init__(self, hub: ConnectionHub):
8
+ super().__init__()
9
+ self.add_property("swing_active", SwingActiveProperty(hub))
10
+ self.add_property("intensity", IntensityProperty(hub))
11
+ self.add_property("smartmode", SmartModeProperty(hub))
12
+
13
+
14
+ class SwingActiveProperty(Property[bool]):
15
+
16
+ async def on_callback(self, args):
17
+ value = args[0]["value"]
18
+ self.set(value, push=False)
19
+ await self.notify_listeners(value)
20
+
21
+ def __init__(self, hub: ConnectionHub):
22
+ super().__init__(hub)
23
+ self.value = False
24
+
25
+ def pull(self):
26
+ self.hub.send_serialized_data("GetSwingActive")
27
+
28
+ def push(self, value: bool):
29
+ self.hub.send_serialized_data("SetSwingActive", value)
30
+
31
+ def register(self):
32
+ self.hub.client.on("GetSwingActiveCallback", self.on_callback)
33
+
34
+
35
+ class IntensityProperty(Property[int]):
36
+
37
+ async def on_callback(self, args):
38
+ value = args[0]["value"]
39
+ self.set(value, push=False)
40
+ await self.notify_listeners(value)
41
+
42
+ def __init__(self, hub: ConnectionHub):
43
+ super().__init__(hub)
44
+ self.value = 0
45
+
46
+ def pull(self):
47
+ self.hub.send_serialized_data("GetIntensity")
48
+
49
+ def push(self, value: int):
50
+ self.hub.send_serialized_data("SetIntensity", value)
51
+
52
+ def register(self):
53
+ self.hub.client.on("GetIntensityCallback", self.on_callback)
54
+
55
+
56
+ class SmartModeProperty(Property[bool]):
57
+
58
+ async def on_callback(self, args):
59
+ value = args[0]["value"]
60
+ self.set(value, push=False)
61
+ await self.notify_listeners(value)
62
+
63
+ def __init__(self, hub: ConnectionHub):
64
+ super().__init__(hub)
65
+ self.value = False
66
+
67
+ def pull(self):
68
+ self.hub.send_serialized_data("GetSmartMode")
69
+
70
+ def push(self, value: bool):
71
+ self.hub.send_serialized_data("SetSmartMode", value)
72
+
73
+ def register(self):
74
+ self.hub.client.on("GetSmartModeCallback", self.on_callback)
@@ -1,46 +1,46 @@
1
- from ...connection_hub import ConnectionHub
2
- from ..classes import Property, Service
3
-
4
-
5
- class InfoService(Service):
6
-
7
- def __init__(self, hub: ConnectionHub):
8
- super().__init__()
9
- self.add_property("display_name", DisplayNameProperty(hub))
10
- self.add_property("version", VersionProperty(hub))
11
-
12
-
13
- class DisplayNameProperty(Property[str]):
14
-
15
- async def on_callback(self, args):
16
- value = args[0]["value"]
17
- self.set(value, push=False)
18
- await self.notify_listeners(value)
19
-
20
- def __init__(self, hub: ConnectionHub):
21
- super().__init__(hub)
22
- self.value = "Smarla"
23
-
24
- def pull(self):
25
- self.hub.send_serialized_data("GetDisplayName")
26
-
27
- def register(self):
28
- self.hub.client.on("GetDisplayNameCallback", self.on_callback)
29
-
30
-
31
- class VersionProperty(Property[str]):
32
-
33
- async def on_callback(self, args):
34
- value = args[0]["value"]
35
- self.set(value, push=False)
36
- await self.notify_listeners(value)
37
-
38
- def __init__(self, hub: ConnectionHub):
39
- super().__init__(hub)
40
- self.value = "1.0.0"
41
-
42
- def pull(self):
43
- self.hub.send_serialized_data("GetVersion")
44
-
45
- def register(self):
46
- self.hub.client.on("GetVersionCallback", self.on_callback)
1
+ from ...connection_hub import ConnectionHub
2
+ from ..classes import Property, Service
3
+
4
+
5
+ class InfoService(Service):
6
+
7
+ def __init__(self, hub: ConnectionHub):
8
+ super().__init__()
9
+ self.add_property("display_name", DisplayNameProperty(hub))
10
+ self.add_property("version", VersionProperty(hub))
11
+
12
+
13
+ class DisplayNameProperty(Property[str]):
14
+
15
+ async def on_callback(self, args):
16
+ value = args[0]["value"]
17
+ self.set(value, push=False)
18
+ await self.notify_listeners(value)
19
+
20
+ def __init__(self, hub: ConnectionHub):
21
+ super().__init__(hub)
22
+ self.value = "Smarla"
23
+
24
+ def pull(self):
25
+ self.hub.send_serialized_data("GetDisplayName")
26
+
27
+ def register(self):
28
+ self.hub.client.on("GetDisplayNameCallback", self.on_callback)
29
+
30
+
31
+ class VersionProperty(Property[str]):
32
+
33
+ async def on_callback(self, args):
34
+ value = args[0]["value"]
35
+ self.set(value, push=False)
36
+ await self.notify_listeners(value)
37
+
38
+ def __init__(self, hub: ConnectionHub):
39
+ super().__init__(hub)
40
+ self.value = "1.0.0"
41
+
42
+ def pull(self):
43
+ self.hub.send_serialized_data("GetVersion")
44
+
45
+ def register(self):
46
+ self.hub.client.on("GetVersionCallback", self.on_callback)
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pysmarlaapi
3
- Version: 0.5.1
3
+ Version: 0.6.1
4
4
  Summary: Swing2Sleep Smarla API
5
5
  Author-email: Robin Lintermann <robin.lintermann@explicatis.com>
6
6
  Requires-Python: >=3.11
7
7
  Description-Content-Type: text/markdown
8
- Classifier: License :: OSI Approved :: Apache Software License
8
+ License-Expression: Apache-2.0
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Programming Language :: Python :: 3.11
11
11
  Classifier: Programming Language :: Python :: 3.12
@@ -0,0 +1,17 @@
1
+ pysmarlaapi/__init__.py,sha256=yNKZr7r7WRjPRW0y0QTvScy-Ab__LYxvuLAOoTSOBFg,90
2
+ pysmarlaapi/classes/__init__.py,sha256=N-ZV3Id_t5ciovUlPUGCk5SLLiMUonRoQZWpfOU4ZsM,69
3
+ pysmarlaapi/classes/auth_token.py,sha256=dpo0lBT9Advm3Iyxu-fT9sq078U2OxgXXBuF5gbBZkM,942
4
+ pysmarlaapi/classes/connection.py,sha256=kFwdZeKqgCV9VgVyvEIaPwLp8zsnbnDJRYbeFWvcxZA,1295
5
+ pysmarlaapi/connection_hub/__init__.py,sha256=4GwcybM2cr5vCfusGy4UhAKz-uwPyRHMOzWc9bP0WRo,4436
6
+ pysmarlaapi/federwiege/__init__.py,sha256=A32w5oaBI8huZBWnbaG90lAl3oF7EqH2LdaCa9ay6L4,1741
7
+ pysmarlaapi/federwiege/classes/__init__.py,sha256=DFJJVOKpra40S4ZX_oq2RyMazg6Nx0c8hoPggmj1bXA,60
8
+ pysmarlaapi/federwiege/classes/property.py,sha256=kTVbaGbWmmku5GmVq0mtWF8uSA7G8oHakyZ_LOO9h3c,1028
9
+ pysmarlaapi/federwiege/classes/service.py,sha256=Y0OQxtQLaHp4qY8Vthj0zRroPoYTiD2WA9ZR96teZTo,632
10
+ pysmarlaapi/federwiege/services/__init__.py,sha256=bJuOsk0lw9WWxB1NZodRTL8Pm_Ra8CuTCxNh33WzxkQ,132
11
+ pysmarlaapi/federwiege/services/analyser_service.py,sha256=y02j4cNvRAblBa1pTlJi1u1_7c3vV4xMj9uHe_vwV38,1789
12
+ pysmarlaapi/federwiege/services/babywiege_service.py,sha256=8hCu-uFAcT_G0F5oUD3EqYzb02L2bE5mVF72NrunEpc,2070
13
+ pysmarlaapi/federwiege/services/info_service.py,sha256=03a4eZFAL1zaIaWo1e-a_Zm2wVl0RuFLm2rTS7ABJIQ,1248
14
+ pysmarlaapi-0.6.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
15
+ pysmarlaapi-0.6.1.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
16
+ pysmarlaapi-0.6.1.dist-info/METADATA,sha256=Prwn4nY8OUfvvhUvS2jrL9V5SrOXXdWEhBopklbVM-k,1106
17
+ pysmarlaapi-0.6.1.dist-info/RECORD,,