pysmarlaapi 0.1.0__py3-none-any.whl → 0.2.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.

pysmarlaapi/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "0.1.0"
1
+ __version__ = "0.2.1"
2
2
 
3
- from .classes import AuthToken, Connection
4
- from .connection_hub import ConnectionHub
3
+ from .classes import Connection
4
+ from .federwiege import Federwiege
@@ -31,13 +31,13 @@ class ConnectionHub:
31
31
 
32
32
  def __init__(
33
33
  self,
34
- async_loop: asyncio.AbstractEventLoop,
34
+ event_loop: asyncio.AbstractEventLoop,
35
35
  connection: Connection,
36
36
  interval: int = 60,
37
37
  backoff: int = 300,
38
38
  ):
39
39
  self.connection: Connection = connection
40
- self._loop: asyncio.AbstractEventLoop = async_loop
40
+ self._loop = event_loop
41
41
  self._interval = interval
42
42
  self._backoff = backoff
43
43
 
@@ -54,9 +54,9 @@ class ConnectionHub:
54
54
  async def notifycontrollerconnection(self, args):
55
55
  value = args[0]
56
56
  if value == "ControllerConnected":
57
- await self.notify_listeners(1)
57
+ await self.notify_listeners(True)
58
58
  else:
59
- await self.notify_listeners(0)
59
+ await self.notify_listeners(False)
60
60
 
61
61
  def setup(self):
62
62
  self.client = SignalRClient(self.connection.url + "/MobileAppHub", retry_count=1)
@@ -1,2 +1,63 @@
1
- from .services.analyser_service import AnalyserService
2
- from .services.babywiege_service import BabywiegeService
1
+ import asyncio
2
+ import threading
3
+
4
+ from ..classes import Connection
5
+ from ..connection_hub import ConnectionHub
6
+ from .classes import Service
7
+ from .services import AnalyserService, BabywiegeService
8
+
9
+
10
+ class Federwiege:
11
+
12
+ @property
13
+ def running(self):
14
+ return self.hub.running
15
+
16
+ @property
17
+ def connected(self):
18
+ return self.hub.connected
19
+
20
+ async def on_controller_connection_change(self, value):
21
+ self.available = value
22
+ if value:
23
+ self.sync()
24
+
25
+ def __init__(self, event_loop: asyncio.AbstractEventLoop, connection: Connection):
26
+ self.serial_number = connection.token.serialNumber
27
+ self.hub = ConnectionHub(event_loop, connection)
28
+ self.services: dict[str, Service] = {
29
+ "babywiege": BabywiegeService(self.hub),
30
+ "analyser": AnalyserService(self.hub),
31
+ }
32
+
33
+ self.registered = False
34
+ self._lock = threading.Lock()
35
+
36
+ self.available = False
37
+
38
+ def get_service(self, service):
39
+ if service not in self.services:
40
+ return None
41
+ return self.services[service]
42
+
43
+ def connect(self):
44
+ with self._lock:
45
+ if not self.registered:
46
+ return
47
+ self.hub.start()
48
+
49
+ def disconnect(self):
50
+ self.hub.stop()
51
+
52
+ def sync(self):
53
+ for service in self.services.values():
54
+ service.sync()
55
+
56
+ def register(self):
57
+ with self._lock:
58
+ if self.registered:
59
+ return
60
+ self.registered = True
61
+ self.hub.add_listener(self.on_controller_connection_change)
62
+ for service in self.services.values():
63
+ service.register()
@@ -4,10 +4,6 @@ from .property import Property
4
4
 
5
5
  class Service:
6
6
 
7
- async def on_connection_change(self, value):
8
- if value:
9
- self.sync()
10
-
11
7
  def __init__(self, connection_hub: ConnectionHub):
12
8
  self.hub = connection_hub
13
9
  self.registered = False
@@ -20,12 +16,13 @@ class Service:
20
16
  return self.props
21
17
 
22
18
  def get_property(self, key: str):
19
+ if key not in self.props:
20
+ return None
23
21
  return self.props[key]
24
22
 
25
23
  def register(self):
26
24
  for prop in self.props.values():
27
25
  prop.register()
28
- self.hub.add_listener(self.on_connection_change)
29
26
  self.registered = True
30
27
 
31
28
  def sync(self):
@@ -0,0 +1,2 @@
1
+ from .analyser_service import AnalyserService
2
+ from .babywiege_service import BabywiegeService
@@ -8,7 +8,6 @@ class AnalyserService(Service):
8
8
  super().__init__(connection_hub)
9
9
  self.add_property("oscillation", OscillationProperty(self.hub))
10
10
  self.add_property("activity", ActivityProperty(self.hub))
11
- self.register()
12
11
 
13
12
 
14
13
  class OscillationProperty(Property[list[int, int]]):
@@ -9,7 +9,6 @@ class BabywiegeService(Service):
9
9
  self.add_property("swing_active", SwingActiveProperty(self.hub))
10
10
  self.add_property("intensity", IntensityProperty(self.hub))
11
11
  self.add_property("smartmode", SmartModeProperty(self.hub))
12
- self.register()
13
12
 
14
13
 
15
14
  class SwingActiveProperty(Property[bool]):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pysmarlaapi
3
- Version: 0.1.0
3
+ Version: 0.2.1
4
4
  Summary: Swing2Sleep Smarla API via websocket with signalr protocol
5
5
  Author-email: Robin Lintermann <robin.lintermann@explicatis.com>
6
6
  Requires-Python: >=3.11.9
@@ -0,0 +1,15 @@
1
+ pysmarlaapi/__init__.py,sha256=bHJSpTFoTKf3KeNsCiFVLdNERSeIBY6Ly5PTLHudnVQ,94
2
+ pysmarlaapi/classes/__init__.py,sha256=4F4LRzLQtj6AmzrXn74iHEZl-YElpMkb7MhEGkab504,71
3
+ pysmarlaapi/classes/auth_token.py,sha256=FgLkZ0xPETfh1ZMQfWhwW6tkPnqFYeHhDUBLBFbauwA,663
4
+ pysmarlaapi/classes/connection.py,sha256=vNh9vG4xAewl2gmkducwSd3u7osjYw5gwtZTZ48rqVo,1291
5
+ pysmarlaapi/connection_hub/__init__.py,sha256=6bLOH7cY_AyZwsMLKlFEA-kwmhKCI4pb0aLrflgfWdQ,4600
6
+ pysmarlaapi/federwiege/__init__.py,sha256=6Hk_Oqrk8AKoomNGdq3o-2pBW6E8ejvKArAc0DdOBGw,1743
7
+ pysmarlaapi/federwiege/classes/__init__.py,sha256=1cCe3iToaNmbUfy_7PynoPenNHtVcKC03rFc4ADqnbE,62
8
+ pysmarlaapi/federwiege/classes/property.py,sha256=YZnpw0cD2NUPnlWo6TBjOzNTWcSJG1tvArXs1dRT6dY,1084
9
+ pysmarlaapi/federwiege/classes/service.py,sha256=J_4WjL0SyyxwlvBp-zpO9EaXNUUcTnOLoPfSdU1FrjA,771
10
+ pysmarlaapi/federwiege/services/__init__.py,sha256=F_54VQIYWAZaGm2ITzCJeG7G-6ARW2PfWvqaut56WN8,96
11
+ pysmarlaapi/federwiege/services/analyser_service.py,sha256=tQb6ijNlrtbz4igH7awdoBnOVHu4TO6SPJmMW5yeT3A,1340
12
+ pysmarlaapi/federwiege/services/babywiege_service.py,sha256=SJFPAsZaf4nSRmt6ojJq-9MtWqk1MdtcaPzBmTN3H0Y,2167
13
+ pysmarlaapi-0.2.1.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
14
+ pysmarlaapi-0.2.1.dist-info/METADATA,sha256=7P3-L0UgSh5bXHX4io29JTT6Qaaw3dWil_7QdF-hwBI,763
15
+ pysmarlaapi-0.2.1.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- pysmarlaapi/__init__.py,sha256=znC1d_F9YF0NBjawoeGmtVz7GxsTaECIFihco71pctE,112
2
- pysmarlaapi/classes/__init__.py,sha256=4F4LRzLQtj6AmzrXn74iHEZl-YElpMkb7MhEGkab504,71
3
- pysmarlaapi/classes/auth_token.py,sha256=FgLkZ0xPETfh1ZMQfWhwW6tkPnqFYeHhDUBLBFbauwA,663
4
- pysmarlaapi/classes/connection.py,sha256=vNh9vG4xAewl2gmkducwSd3u7osjYw5gwtZTZ48rqVo,1291
5
- pysmarlaapi/connection_hub/__init__.py,sha256=U76wUkXHjAgzZNuJKS8ZFRwIskPIkCW1HdI1_SLlGs0,4620
6
- pysmarlaapi/federwiege/__init__.py,sha256=-zzqsip6li-QPsUJv-wEoqLpUzHHN9gbUYACRAc_wSg,114
7
- pysmarlaapi/federwiege/classes/__init__.py,sha256=1cCe3iToaNmbUfy_7PynoPenNHtVcKC03rFc4ADqnbE,62
8
- pysmarlaapi/federwiege/classes/property.py,sha256=YZnpw0cD2NUPnlWo6TBjOzNTWcSJG1tvArXs1dRT6dY,1084
9
- pysmarlaapi/federwiege/classes/service.py,sha256=wZcfq4xVXu_LKojcZALs63n5le9ekx0sEYT8nHKJKbU,865
10
- pysmarlaapi/federwiege/services/analyser_service.py,sha256=RoY5gv_DxUb9W9oucmPGJgOmoy9zn_uHmNyZX2P_wOY,1365
11
- pysmarlaapi/federwiege/services/babywiege_service.py,sha256=qHZjkQK7vmHK0vVmtXrdAsTh9vdAAbuwOQfKLF6ltyQ,2192
12
- pysmarlaapi-0.1.0.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
13
- pysmarlaapi-0.1.0.dist-info/METADATA,sha256=W1W63qwrvPtAh-Rfw0LUuqF-Ch-h9i9TneuQdxbr8tQ,763
14
- pysmarlaapi-0.1.0.dist-info/RECORD,,