pysmarlaapi 0.2.4__tar.gz → 0.4.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 (25) hide show
  1. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/PKG-INFO +1 -1
  2. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/pysmarlaapi/__init__.py +1 -1
  3. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/pysmarlaapi/classes/auth_token.py +9 -0
  4. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/pysmarlaapi/classes/connection.py +3 -1
  5. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/pysmarlaapi/federwiege/__init__.py +2 -1
  6. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/pysmarlaapi/federwiege/classes/property.py +2 -2
  7. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/pysmarlaapi/federwiege/classes/service.py +1 -3
  8. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/pysmarlaapi/federwiege/services/__init__.py +1 -0
  9. pysmarlaapi-0.4.0/pysmarlaapi/federwiege/services/analyser_service.py +65 -0
  10. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/pysmarlaapi/federwiege/services/babywiege_service.py +11 -11
  11. pysmarlaapi-0.4.0/pysmarlaapi/federwiege/services/info_service.py +46 -0
  12. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/tests/test.py +12 -3
  13. pysmarlaapi-0.2.4/pysmarlaapi/federwiege/services/analyser_service.py +0 -46
  14. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/.gitignore +0 -0
  15. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/.pre-commit-config.yaml +0 -0
  16. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/.pypirc +0 -0
  17. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/.vscode/launch.json +0 -0
  18. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/.vscode/settings.json +0 -0
  19. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/README.md +0 -0
  20. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/pyproject.toml +0 -0
  21. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/pysmarlaapi/classes/__init__.py +0 -0
  22. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/pysmarlaapi/connection_hub/__init__.py +0 -0
  23. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/pysmarlaapi/federwiege/classes/__init__.py +0 -0
  24. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/requirements.txt +0 -0
  25. {pysmarlaapi-0.2.4 → pysmarlaapi-0.4.0}/requirements_dev.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pysmarlaapi
3
- Version: 0.2.4
3
+ Version: 0.4.0
4
4
  Summary: Swing2Sleep Smarla API
5
5
  Author-email: Robin Lintermann <robin.lintermann@explicatis.com>
6
6
  Requires-Python: >=3.11.9
@@ -1,4 +1,4 @@
1
- __version__ = "0.2.4"
1
+ __version__ = "0.4.0"
2
2
 
3
3
  from .classes import Connection
4
4
  from .federwiege import Federwiege
@@ -1,3 +1,4 @@
1
+ import base64
1
2
  from dataclasses import dataclass
2
3
  from typing import Self
3
4
 
@@ -23,5 +24,13 @@ class AuthToken:
23
24
  def from_string(cls, value) -> Self:
24
25
  return AuthToken.from_json(jsonpickle.decode(value))
25
26
 
27
+ @classmethod
28
+ def from_base64(cls, value) -> Self:
29
+ token = base64.b64decode(value.encode()).decode()
30
+ return AuthToken.from_string(token)
31
+
26
32
  def get_string(self) -> str:
27
33
  return jsonpickle.encode(self, unpicklable=False)
34
+
35
+ def get_base64(self) -> str:
36
+ return base64.b64encode(self.get_string().encode()).decode()
@@ -6,7 +6,7 @@ from . import AuthToken
6
6
 
7
7
  class Connection:
8
8
 
9
- def __init__(self, url: str, token: AuthToken = None, token_str=None, token_json=None):
9
+ def __init__(self, url: str, token: AuthToken = None, token_str=None, token_json=None, token_b64=None):
10
10
  self.url = url
11
11
  if token is not None:
12
12
  self.token = token
@@ -14,6 +14,8 @@ class Connection:
14
14
  self.token = AuthToken.from_json(token_json)
15
15
  elif token_str is not None:
16
16
  self.token = AuthToken.from_string(token_str)
17
+ elif token_b64 is not None:
18
+ self.token = AuthToken.from_base64(token_b64)
17
19
  else:
18
20
  self.token = None
19
21
 
@@ -4,7 +4,7 @@ import threading
4
4
  from ..classes import Connection
5
5
  from ..connection_hub import ConnectionHub
6
6
  from .classes import Service
7
- from .services import AnalyserService, BabywiegeService
7
+ from .services import AnalyserService, BabywiegeService, InfoService
8
8
 
9
9
 
10
10
  class Federwiege:
@@ -28,6 +28,7 @@ class Federwiege:
28
28
  self.services: dict[str, Service] = {
29
29
  "babywiege": BabywiegeService(self.hub),
30
30
  "analyser": AnalyserService(self.hub),
31
+ "info": InfoService(self.hub),
31
32
  }
32
33
 
33
34
  self.registered = False
@@ -8,8 +8,8 @@ _VT = TypeVar("_VT")
8
8
 
9
9
  class Property(Generic[_VT]):
10
10
 
11
- def __init__(self, connection_hub: ConnectionHub):
12
- self.hub = connection_hub
11
+ def __init__(self, hub: ConnectionHub):
12
+ self.hub = hub
13
13
  self.value: _VT = None
14
14
  self.listeners = set()
15
15
  self.lock = asyncio.Lock()
@@ -1,11 +1,9 @@
1
- from ...connection_hub import ConnectionHub
2
1
  from .property import Property
3
2
 
4
3
 
5
4
  class Service:
6
5
 
7
- def __init__(self, connection_hub: ConnectionHub):
8
- self.hub = connection_hub
6
+ def __init__(self):
9
7
  self.registered = False
10
8
  self.props: dict[str, Property] = {}
11
9
 
@@ -1,2 +1,3 @@
1
1
  from .analyser_service import AnalyserService
2
2
  from .babywiege_service import BabywiegeService
3
+ from .info_service import InfoService
@@ -0,0 +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)
@@ -4,11 +4,11 @@ from ..classes import Property, Service
4
4
 
5
5
  class BabywiegeService(Service):
6
6
 
7
- def __init__(self, connection_hub: ConnectionHub):
8
- super().__init__(connection_hub)
9
- self.add_property("swing_active", SwingActiveProperty(self.hub))
10
- self.add_property("intensity", IntensityProperty(self.hub))
11
- self.add_property("smartmode", SmartModeProperty(self.hub))
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
12
 
13
13
 
14
14
  class SwingActiveProperty(Property[bool]):
@@ -18,8 +18,8 @@ class SwingActiveProperty(Property[bool]):
18
18
  self.set(value, push=False)
19
19
  await self.notify_listeners(value)
20
20
 
21
- def __init__(self, parent: Service):
22
- super().__init__(parent)
21
+ def __init__(self, hub: ConnectionHub):
22
+ super().__init__(hub)
23
23
  self.value = False
24
24
 
25
25
  def pull(self):
@@ -39,8 +39,8 @@ class IntensityProperty(Property[int]):
39
39
  self.set(value, push=False)
40
40
  await self.notify_listeners(value)
41
41
 
42
- def __init__(self, parent: Service):
43
- super().__init__(parent)
42
+ def __init__(self, hub: ConnectionHub):
43
+ super().__init__(hub)
44
44
  self.value = 0
45
45
 
46
46
  def pull(self):
@@ -60,8 +60,8 @@ class SmartModeProperty(Property[bool]):
60
60
  self.set(value, push=False)
61
61
  await self.notify_listeners(value)
62
62
 
63
- def __init__(self, parent: Service):
64
- super().__init__(parent)
63
+ def __init__(self, hub: ConnectionHub):
64
+ super().__init__(hub)
65
65
  self.value = False
66
66
 
67
67
  def pull(self):
@@ -0,0 +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)
@@ -10,15 +10,15 @@ logging.basicConfig(level=20)
10
10
  from pysmarlaapi import Connection, Federwiege
11
11
 
12
12
  try:
13
- from config import AUTH_TOKEN_PERSONAL, HOST
13
+ from config import AUTH_TOKEN_B64, HOST
14
14
  except ImportError:
15
15
  print("config.py or mandatory variables missing, please add in root folder...")
16
- exit()
16
+ sys.exit()
17
17
 
18
18
  loop = asyncio.get_event_loop()
19
19
  async_thread = threading.Thread(target=loop.run_forever)
20
20
 
21
- connection = Connection(url=HOST, token_json=AUTH_TOKEN_PERSONAL)
21
+ connection = Connection(url=HOST, token_b64=AUTH_TOKEN_B64)
22
22
 
23
23
  federwiege = Federwiege(loop, connection)
24
24
 
@@ -33,10 +33,19 @@ def main():
33
33
 
34
34
  swing_active_prop = federwiege.get_service("babywiege").get_property("swing_active")
35
35
  intensity_prop = federwiege.get_service("babywiege").get_property("intensity")
36
+
36
37
  oscillation_prop = federwiege.get_service("analyser").get_property("oscillation")
38
+ swing_count_prop = federwiege.get_service("analyser").get_property("swing_count")
39
+
40
+ display_name_prop = federwiege.get_service("info").get_property("display_name")
41
+ version_prop = federwiege.get_service("info").get_property("version")
37
42
 
38
43
  time.sleep(1)
39
44
 
45
+ print(display_name_prop.get())
46
+ print(version_prop.get())
47
+ print(swing_count_prop.get())
48
+
40
49
  value = swing_active_prop.get()
41
50
  print(f"Swing Active: {value}")
42
51
  intensity = intensity_prop.get()
@@ -1,46 +0,0 @@
1
- from ...connection_hub import ConnectionHub
2
- from ..classes import Property, Service
3
-
4
-
5
- class AnalyserService(Service):
6
-
7
- def __init__(self, connection_hub: ConnectionHub):
8
- super().__init__(connection_hub)
9
- self.add_property("oscillation", OscillationProperty(self.hub))
10
- self.add_property("activity", ActivityProperty(self.hub))
11
-
12
-
13
- class OscillationProperty(Property[list[int, int]]):
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, parent: Service):
21
- super().__init__(parent)
22
- self.value = [0, 0]
23
-
24
- def pull(self):
25
- self.hub.send_serialized_data("GetOscillation")
26
-
27
- def register(self):
28
- self.hub.client.on("GetOscillationCallback", self.on_callback)
29
-
30
-
31
- class ActivityProperty(Property[int]):
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, parent: Service):
39
- super().__init__(parent)
40
- self.value = 0
41
-
42
- def pull(self):
43
- self.hub.send_serialized_data("GetActivity")
44
-
45
- def register(self):
46
- self.hub.client.on("GetActivityCallback", self.on_callback)
File without changes
File without changes
File without changes
File without changes