pysmarlaapi 0.10.2__tar.gz → 0.11.0__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 (22) hide show
  1. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/PKG-INFO +1 -1
  2. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/__init__.py +1 -1
  3. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/connection_hub/__init__.py +6 -17
  4. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/federwiege/__init__.py +24 -5
  5. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/LICENSE +0 -0
  6. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/README.md +0 -0
  7. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pyproject.toml +0 -0
  8. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/classes/__init__.py +0 -0
  9. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/classes/auth_token.py +0 -0
  10. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/classes/connection.py +0 -0
  11. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/federwiege/classes/__init__.py +0 -0
  12. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/federwiege/classes/property.py +0 -0
  13. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/federwiege/classes/service.py +0 -0
  14. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/federwiege/services/__init__.py +0 -0
  15. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/federwiege/services/analyser_service.py +0 -0
  16. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/federwiege/services/babywiege_service.py +0 -0
  17. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/federwiege/services/info_service.py +0 -0
  18. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/federwiege/services/system_service.py +0 -0
  19. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/federwiege/types/__init__.py +0 -0
  20. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/federwiege/types/send_diag_status.py +0 -0
  21. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/federwiege/types/spring_status.py +0 -0
  22. {pysmarlaapi-0.10.2 → pysmarlaapi-0.11.0}/pysmarlaapi/federwiege/types/update_status.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pysmarlaapi
3
- Version: 0.10.2
3
+ Version: 0.11.0
4
4
  Summary: Swing2Sleep Smarla API
5
5
  Author-email: Robin Lintermann <robin.lintermann@explicatis.com>
6
6
  Requires-Python: >=3.11
@@ -1,4 +1,4 @@
1
- __version__ = "0.10.2"
1
+ __version__ = "0.11.0"
2
2
 
3
3
  from .classes import Connection
4
4
  from .federwiege import Federwiege
@@ -38,6 +38,7 @@ class ConnectionHub:
38
38
  self,
39
39
  event_loop: asyncio.AbstractEventLoop,
40
40
  connection: Connection,
41
+ listener,
41
42
  max_delay: int = 256,
42
43
  ):
43
44
  self.connection: Connection = connection
@@ -47,7 +48,7 @@ class ConnectionHub:
47
48
 
48
49
  self.logger = logging.getLogger(f"{__package__}[{self.connection.token.serialNumber}]")
49
50
 
50
- self.listeners = set()
51
+ self.connection_callback = listener
51
52
 
52
53
  self._running = False
53
54
  self._wake = asyncio.Event()
@@ -58,9 +59,11 @@ class ConnectionHub:
58
59
  async def notifycontrollerconnection(self, args):
59
60
  value = args[0]
60
61
  if value == "ControllerConnected":
61
- await self.notify_listeners(True)
62
+ self.logger.info("Controller connected")
63
+ await self.connection_callback(True)
62
64
  else:
63
- await self.notify_listeners(False)
65
+ self.logger.info("Controller disconnected")
66
+ await self.connection_callback(False)
64
67
 
65
68
  def setup(self):
66
69
  self.client = SignalRClient(self.connection.url + "/MobileAppHub", retry_count=1)
@@ -69,20 +72,6 @@ class ConnectionHub:
69
72
  self.client.on_error(self.on_error)
70
73
  self.client.on("SetNotifyAppConnectionCallback", self.notifycontrollerconnection)
71
74
 
72
- def add_listener(self, listener):
73
- if self.running:
74
- return
75
- self.listeners.add(listener)
76
-
77
- def remove_listener(self, listener):
78
- if self.running:
79
- return
80
- self.listeners.remove(listener)
81
-
82
- async def notify_listeners(self, value):
83
- for listener in self.listeners:
84
- await listener(value)
85
-
86
75
  async def on_open_function(self):
87
76
  self._retry_delay = 1
88
77
  self.logger.info("Connection to server established")
@@ -1,6 +1,8 @@
1
1
  import asyncio
2
2
  import threading
3
3
 
4
+ import aiohttp
5
+
4
6
  from ..classes import Connection
5
7
  from ..connection_hub import ConnectionHub
6
8
  from .classes import Service
@@ -18,14 +20,15 @@ class Federwiege:
18
20
  def connected(self):
19
21
  return self.hub.connected
20
22
 
21
- async def on_controller_connection_change(self, value):
23
+ async def on_connection_change(self, value):
22
24
  self.available = value
23
- if value:
25
+ if self.available:
24
26
  self.sync()
25
27
 
26
28
  def __init__(self, event_loop: asyncio.AbstractEventLoop, connection: Connection):
27
29
  self.serial_number = connection.token.serialNumber
28
- self.hub = ConnectionHub(event_loop, connection)
30
+ self.connection = connection
31
+ self.hub = ConnectionHub(event_loop, connection, self.on_connection_change)
29
32
  self.services: dict[str, Service] = {
30
33
  "babywiege": BabywiegeService(self.hub),
31
34
  "analyser": AnalyserService(self.hub),
@@ -38,6 +41,23 @@ class Federwiege:
38
41
 
39
42
  self.available = False
40
43
 
44
+ async def check_firmware_update(self) -> tuple[str, str] | None:
45
+ await self.connection.refresh_token()
46
+
47
+ try:
48
+ async with aiohttp.ClientSession(self.connection.url) as session:
49
+ response = await session.get(
50
+ "/api/Firmware/CheckFirmwareUpdate",
51
+ headers={"accept": "*/*", "Content-Type": "application/json", "Authorization": f"Bearer {self.connection.get_token()}"},
52
+ )
53
+ if response.status != 200:
54
+ return None
55
+ content = await response.json()
56
+ except (aiohttp.ClientError, asyncio.TimeoutError):
57
+ return None
58
+
59
+ return (content["targetFirmware"], content["releaseNotes"])
60
+
41
61
  def get_service(self, key: str):
42
62
  if key not in self.services:
43
63
  return None
@@ -66,7 +86,6 @@ class Federwiege:
66
86
  with self._lock:
67
87
  if self.registered:
68
88
  return
69
- self.registered = True
70
- self.hub.add_listener(self.on_controller_connection_change)
71
89
  for service in self.services.values():
72
90
  service.register()
91
+ self.registered = True
File without changes
File without changes