pysmarlaapi 0.1.0__tar.gz → 0.2.1__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.

Potentially problematic release.


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

Files changed (25) hide show
  1. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/PKG-INFO +1 -1
  2. pysmarlaapi-0.2.1/pysmarlaapi/__init__.py +4 -0
  3. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/pysmarlaapi/connection_hub/__init__.py +4 -4
  4. pysmarlaapi-0.2.1/pysmarlaapi/federwiege/__init__.py +63 -0
  5. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/pysmarlaapi/federwiege/classes/service.py +2 -5
  6. pysmarlaapi-0.2.1/pysmarlaapi/federwiege/services/__init__.py +2 -0
  7. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/pysmarlaapi/federwiege/services/analyser_service.py +0 -1
  8. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/pysmarlaapi/federwiege/services/babywiege_service.py +0 -1
  9. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/tests/test.py +11 -11
  10. pysmarlaapi-0.1.0/pysmarlaapi/__init__.py +0 -4
  11. pysmarlaapi-0.1.0/pysmarlaapi/federwiege/__init__.py +0 -2
  12. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/.gitignore +0 -0
  13. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/.pre-commit-config.yaml +0 -0
  14. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/.pypirc +0 -0
  15. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/.vscode/launch.json +0 -0
  16. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/.vscode/settings.json +0 -0
  17. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/README.md +0 -0
  18. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/pyproject.toml +0 -0
  19. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/pysmarlaapi/classes/__init__.py +0 -0
  20. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/pysmarlaapi/classes/auth_token.py +0 -0
  21. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/pysmarlaapi/classes/connection.py +0 -0
  22. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/pysmarlaapi/federwiege/classes/__init__.py +0 -0
  23. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/pysmarlaapi/federwiege/classes/property.py +0 -0
  24. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/requirements.txt +0 -0
  25. {pysmarlaapi-0.1.0 → pysmarlaapi-0.2.1}/requirements_dev.txt +0 -0
@@ -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,4 @@
1
+ __version__ = "0.2.1"
2
+
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)
@@ -0,0 +1,63 @@
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]):
@@ -7,8 +7,7 @@ import time
7
7
  sys.path.append("../")
8
8
  logging.basicConfig(level=20)
9
9
 
10
- from pysmarlaapi import Connection, ConnectionHub
11
- from pysmarlaapi.federwiege import AnalyserService, BabywiegeService
10
+ from pysmarlaapi import Connection, Federwiege
12
11
 
13
12
  try:
14
13
  from config import AUTH_TOKEN_PERSONAL, HOST
@@ -21,21 +20,20 @@ async_thread = threading.Thread(target=loop.run_forever)
21
20
 
22
21
  connection = Connection(url=HOST, token_json=AUTH_TOKEN_PERSONAL)
23
22
 
24
- hub = ConnectionHub(loop, connection, interval=10, backoff=0)
25
- babywiege_svc = BabywiegeService(hub)
26
- analyser_svc = AnalyserService(hub)
23
+ federwiege = Federwiege(loop, connection)
27
24
 
28
25
 
29
26
  def main():
30
27
  async_thread.start()
31
- hub.start()
28
+ federwiege.register()
29
+ federwiege.connect()
32
30
 
33
- while not hub.connected:
31
+ while not (federwiege.connected and federwiege.available):
34
32
  time.sleep(1)
35
33
 
36
- swing_active_prop = babywiege_svc.get_property("swing_active")
37
- intensity_prop = babywiege_svc.get_property("intensity")
38
- oscillation_prop = analyser_svc.get_property("oscillation")
34
+ swing_active_prop = federwiege.get_service("babywiege").get_property("swing_active")
35
+ intensity_prop = federwiege.get_service("babywiege").get_property("intensity")
36
+ oscillation_prop = federwiege.get_service("analyser").get_property("oscillation")
39
37
 
40
38
  time.sleep(1)
41
39
 
@@ -75,5 +73,7 @@ if __name__ == "__main__":
75
73
  main()
76
74
  except BaseException:
77
75
  pass
78
- hub.stop()
76
+ federwiege.disconnect()
77
+ while federwiege.connected:
78
+ time.sleep(1)
79
79
  loop.call_soon_threadsafe(loop.stop)
@@ -1,4 +0,0 @@
1
- __version__ = "0.1.0"
2
-
3
- from .classes import AuthToken, Connection
4
- from .connection_hub import ConnectionHub
@@ -1,2 +0,0 @@
1
- from .services.analyser_service import AnalyserService
2
- from .services.babywiege_service import BabywiegeService
File without changes
File without changes
File without changes
File without changes