pysmarlaapi 0.7.1__tar.gz → 0.8.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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pysmarlaapi
3
- Version: 0.7.1
3
+ Version: 0.8.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.7.1"
1
+ __version__ = "0.8.0"
2
2
 
3
3
  from .classes import Connection
4
4
  from .federwiege import Federwiege
@@ -27,22 +27,26 @@ class Connection:
27
27
  async def refresh_token(self) -> bool:
28
28
  try:
29
29
  async with aiohttp.ClientSession(self.url) as session:
30
- response = await session.post(
31
- "/api/AppParing/getToken",
32
- headers={"accept": "*/*", "Content-Type": "application/json"},
33
- data=jsonpickle.encode(self.token, unpicklable=False),
34
- )
30
+ content = await self._get_token(session)
35
31
  except (aiohttp.ClientError, asyncio.TimeoutError):
36
32
  return False
37
33
 
38
- if response.status != 200:
34
+ if not content:
39
35
  return False
40
36
 
41
- content = await response.json()
42
-
43
37
  try:
44
38
  self.token = AuthToken.from_json(content)
45
39
  except ValueError:
46
40
  return False
47
41
 
48
42
  return True
43
+
44
+ async def _get_token(self, session: aiohttp.ClientSession):
45
+ async with await session.post(
46
+ "/api/AppParing/getToken",
47
+ headers={"accept": "*/*", "Content-Type": "application/json"},
48
+ data=jsonpickle.encode(self.token, unpicklable=False),
49
+ ) as response:
50
+ if response.status != 200:
51
+ return None
52
+ return await response.json()
@@ -8,9 +8,9 @@ _VT = TypeVar("_VT")
8
8
 
9
9
  class Property(Generic[_VT]):
10
10
 
11
- def __init__(self, hub: ConnectionHub):
11
+ def __init__(self, hub: ConnectionHub, value: _VT):
12
12
  self.hub = hub
13
- self.value: _VT = None
13
+ self.value: _VT = value
14
14
  self.listeners = set()
15
15
  self.lock = asyncio.Lock()
16
16
 
@@ -11,7 +11,7 @@ class AnalyserService(Service):
11
11
  self.add_property("swing_count", SwingCountProperty(hub))
12
12
 
13
13
 
14
- class OscillationProperty(Property[list[int, int]]):
14
+ class OscillationProperty(Property[list[int]]):
15
15
 
16
16
  async def on_callback(self, args):
17
17
  value = args[0]["value"]
@@ -19,8 +19,7 @@ class OscillationProperty(Property[list[int, int]]):
19
19
  await self.notify_listeners(value)
20
20
 
21
21
  def __init__(self, hub: ConnectionHub):
22
- super().__init__(hub)
23
- self.value = [0, 0]
22
+ super().__init__(hub, [0, 0])
24
23
 
25
24
  def pull(self):
26
25
  self.hub.send_serialized_data("GetOscillation")
@@ -37,8 +36,7 @@ class ActivityProperty(Property[int]):
37
36
  await self.notify_listeners(value)
38
37
 
39
38
  def __init__(self, hub: ConnectionHub):
40
- super().__init__(hub)
41
- self.value = 0
39
+ super().__init__(hub, 0)
42
40
 
43
41
  def pull(self):
44
42
  self.hub.send_serialized_data("GetActivity")
@@ -55,8 +53,7 @@ class SwingCountProperty(Property[int]):
55
53
  await self.notify_listeners(value)
56
54
 
57
55
  def __init__(self, hub: ConnectionHub):
58
- super().__init__(hub)
59
- self.value = 0
56
+ super().__init__(hub, 0)
60
57
 
61
58
  def pull(self):
62
59
  self.hub.send_serialized_data("GetSwingCount")
@@ -8,7 +8,7 @@ class BabywiegeService(Service):
8
8
  super().__init__()
9
9
  self.add_property("swing_active", SwingActiveProperty(hub))
10
10
  self.add_property("intensity", IntensityProperty(hub))
11
- self.add_property("smartmode", SmartModeProperty(hub))
11
+ self.add_property("smart_mode", SmartModeProperty(hub))
12
12
 
13
13
 
14
14
  class SwingActiveProperty(Property[bool]):
@@ -19,8 +19,7 @@ class SwingActiveProperty(Property[bool]):
19
19
  await self.notify_listeners(value)
20
20
 
21
21
  def __init__(self, hub: ConnectionHub):
22
- super().__init__(hub)
23
- self.value = False
22
+ super().__init__(hub, False)
24
23
 
25
24
  def pull(self):
26
25
  self.hub.send_serialized_data("GetSwingActive")
@@ -40,8 +39,7 @@ class IntensityProperty(Property[int]):
40
39
  await self.notify_listeners(value)
41
40
 
42
41
  def __init__(self, hub: ConnectionHub):
43
- super().__init__(hub)
44
- self.value = 0
42
+ super().__init__(hub, 0)
45
43
 
46
44
  def pull(self):
47
45
  self.hub.send_serialized_data("GetIntensity")
@@ -61,8 +59,7 @@ class SmartModeProperty(Property[bool]):
61
59
  await self.notify_listeners(value)
62
60
 
63
61
  def __init__(self, hub: ConnectionHub):
64
- super().__init__(hub)
65
- self.value = False
62
+ super().__init__(hub, False)
66
63
 
67
64
  def pull(self):
68
65
  self.hub.send_serialized_data("GetSmartMode")
@@ -18,8 +18,7 @@ class DisplayNameProperty(Property[str]):
18
18
  await self.notify_listeners(value)
19
19
 
20
20
  def __init__(self, hub: ConnectionHub):
21
- super().__init__(hub)
22
- self.value = "Smarla"
21
+ super().__init__(hub, "Smarla")
23
22
 
24
23
  def pull(self):
25
24
  self.hub.send_serialized_data("GetDisplayName")
@@ -36,8 +35,7 @@ class VersionProperty(Property[str]):
36
35
  await self.notify_listeners(value)
37
36
 
38
37
  def __init__(self, hub: ConnectionHub):
39
- super().__init__(hub)
40
- self.value = "1.0.0"
38
+ super().__init__(hub, "1.0.0")
41
39
 
42
40
  def pull(self):
43
41
  self.hub.send_serialized_data("GetVersion")
File without changes
File without changes
File without changes