pysmarlaapi 0.1.0__py3-none-any.whl → 0.2.0__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.0"
2
2
 
3
- from .classes import AuthToken, Connection
4
- from .connection_hub import ConnectionHub
3
+ from .classes import Connection
4
+ from .federwiege import Federwiege
@@ -1,3 +1,5 @@
1
+ import asyncio
2
+
1
3
  import aiohttp
2
4
  import jsonpickle
3
5
 
@@ -6,7 +8,10 @@ from . import AuthToken
6
8
 
7
9
  class Connection:
8
10
 
9
- def __init__(self, url: str, token: AuthToken = None, token_str=None, token_json=None):
11
+ def __init__(
12
+ self, event_loop: asyncio.AbstractEventLoop, url: str, token: AuthToken = None, token_str=None, token_json=None
13
+ ):
14
+ self.event_loop = event_loop
10
15
  self.url = url
11
16
  if token is not None:
12
17
  self.token = token
@@ -31,13 +31,12 @@ class ConnectionHub:
31
31
 
32
32
  def __init__(
33
33
  self,
34
- async_loop: asyncio.AbstractEventLoop,
35
34
  connection: Connection,
36
35
  interval: int = 60,
37
36
  backoff: int = 300,
38
37
  ):
39
38
  self.connection: Connection = connection
40
- self._loop: asyncio.AbstractEventLoop = async_loop
39
+ self._loop: asyncio.AbstractEventLoop = self.connection.event_loop
41
40
  self._interval = interval
42
41
  self._backoff = backoff
43
42
 
@@ -54,9 +53,9 @@ class ConnectionHub:
54
53
  async def notifycontrollerconnection(self, args):
55
54
  value = args[0]
56
55
  if value == "ControllerConnected":
57
- await self.notify_listeners(1)
56
+ await self.notify_listeners(True)
58
57
  else:
59
- await self.notify_listeners(0)
58
+ await self.notify_listeners(False)
60
59
 
61
60
  def setup(self):
62
61
  self.client = SignalRClient(self.connection.url + "/MobileAppHub", retry_count=1)
@@ -1,2 +1,62 @@
1
- from .services.analyser_service import AnalyserService
2
- from .services.babywiege_service import BabywiegeService
1
+ import threading
2
+
3
+ from ..classes import Connection
4
+ from ..connection_hub import ConnectionHub
5
+ from .classes import Service
6
+ from .services import AnalyserService, BabywiegeService
7
+
8
+
9
+ class Federwiege:
10
+
11
+ @property
12
+ def running(self):
13
+ return self.hub.running
14
+
15
+ @property
16
+ def connected(self):
17
+ return self.hub.connected
18
+
19
+ async def on_controller_connection_change(self, value):
20
+ self.available = value
21
+ if value:
22
+ self.sync()
23
+
24
+ def __init__(self, connection: Connection):
25
+ self.serial_number = connection.token.serialNumber
26
+ self.hub = ConnectionHub(connection)
27
+ self.services: dict[str, Service] = {
28
+ "babywiege": BabywiegeService(self.hub),
29
+ "analyser": AnalyserService(self.hub),
30
+ }
31
+
32
+ self.registered = False
33
+ self._lock = threading.Lock()
34
+
35
+ self.available = False
36
+
37
+ def get_service(self, service):
38
+ if service not in self.services:
39
+ return None
40
+ return self.services[service]
41
+
42
+ def connect(self):
43
+ with self._lock:
44
+ if not self.registered:
45
+ return
46
+ self.hub.start()
47
+
48
+ def disconnect(self):
49
+ self.hub.stop()
50
+
51
+ def sync(self):
52
+ for service in self.services.values():
53
+ service.sync()
54
+
55
+ def register(self):
56
+ with self._lock:
57
+ if self.registered:
58
+ return
59
+ self.registered = True
60
+ self.hub.add_listener(self.on_controller_connection_change)
61
+ for service in self.services.values():
62
+ 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.0
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=i45rOL2uYBjAHltN282RAZVC16RoTLHoGGdHZbZfMlY,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=tjcSmuUgCns0YRCB0WxFLtMYQujDInIlQs0FyigUO1k,1402
5
+ pysmarlaapi/connection_hub/__init__.py,sha256=h20zSrb60nmiKC-oR91mkQal1yZbNko6IVTslDBppNg,4595
6
+ pysmarlaapi/federwiege/__init__.py,sha256=YfhO-Vg25e_dbUrMJUhTEloFtwLyoRPyw2Af8h66mU0,1676
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.0.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
14
+ pysmarlaapi-0.2.0.dist-info/METADATA,sha256=XOCu8O2fyfOypK-oFsDm3O4TYHkDusw4W_zr7AU72hI,763
15
+ pysmarlaapi-0.2.0.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,,