python-swidget 1.2.0__tar.gz → 1.2.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-swidget
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: Python API for Swidget smart devices
5
5
  Home-page: https://github.com/swidget/python-swidget
6
6
  License: GPL-3.0-or-later
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-swidget"
3
- version = "1.2.0"
3
+ version = "1.2.2"
4
4
  description = "Python API for Swidget smart devices"
5
5
  license = "GPL-3.0-or-later"
6
6
  authors = ["Swidget"]
@@ -65,7 +65,7 @@ class SwidgetDevice:
65
65
  self.device_type = DeviceType.Unknown
66
66
  self._friendly_name = "Unknown Swidget Device"
67
67
  self.assemblies: Dict[Any, Any] = dict()
68
- self._subscribers: Callable[[Dict[str, Any]], Any] = list()
68
+ self._subscribers: List[Any] = list()
69
69
  headers = {self.token_name: self.secret_key,
70
70
  'Connection': 'keep-alive'}
71
71
  connector = TCPConnector(verify_ssl=False, force_close=True)
@@ -113,7 +113,10 @@ class SwidgetDevice:
113
113
  async def close(self) -> None:
114
114
  await self.stop()
115
115
 
116
- async def add_event_callback(self, callback: Callable[[Dict, Any], None],) -> bool:
116
+ async def disconnect(self) -> None:
117
+ await self.stop()
118
+
119
+ def add_event_callback(self, callback: Callable[[Any], Any]):
117
120
  for c in self._subscribers:
118
121
  if c == callback:
119
122
  _LOGGER.warn(f"Callback has already been added, not adding the same callback function again")
@@ -121,7 +124,7 @@ class SwidgetDevice:
121
124
  self._subscribers.append(callback)
122
125
  return True
123
126
 
124
- async def remove_event_callback(self, callback: Callable[[Dict, Any], None],) -> bool:
127
+ def remove_event_callback(self, callback: Callable[[Any], Any]):
125
128
  if callback in self._subscribers:
126
129
  self._subscribers.remove(callback)
127
130
  return True
@@ -363,7 +366,7 @@ class SwidgetDevice:
363
366
  ssl=False,
364
367
  data=json.dumps(data)
365
368
  ) as response:
366
- result = await response.status
369
+ result = response.status
367
370
  if result == 200:
368
371
  return True
369
372
  return False
@@ -389,7 +392,7 @@ class SwidgetDevice:
389
392
  "rssi": self.rssi
390
393
  }
391
394
 
392
- async def get_child_consumption(self, plug_id=0) -> Any:
395
+ def get_child_consumption(self, plug_id=0) -> Any:
393
396
  """Get the power consumption of a plug in watts."""
394
397
  if plug_id == "all":
395
398
  return_dict = {}
@@ -401,7 +404,7 @@ class SwidgetDevice:
401
404
  return return_dict
402
405
  return self.assemblies['host'].components[str(plug_id)].functions['power']['current']
403
406
 
404
- async def total_consumption(self) -> float:
407
+ def total_consumption(self) -> float:
405
408
  """Get the total power consumption in watts."""
406
409
  total_consumption = 0
407
410
  for id, properties in self.assemblies['host'].components.items():
@@ -409,7 +412,7 @@ class SwidgetDevice:
409
412
  return total_consumption
410
413
 
411
414
  @property
412
- async def realtime_values(self) -> Dict:
415
+ def realtime_values(self) -> Dict:
413
416
  """Get a dict of realtime value attributes from the insert and host
414
417
 
415
418
  :return: A dictionary of insert sensor values and power consumption values
@@ -419,7 +422,7 @@ class SwidgetDevice:
419
422
  for feature in self.insert_features:
420
423
  return_dict.update(self.get_function_values(feature))
421
424
  return_dict.update({'rssi': self.rssi})
422
- power_values = await self.get_child_consumption("all")
425
+ power_values =self.get_child_consumption("all")
423
426
  if power_values:
424
427
  return_dict.update(power_values)
425
428
  return return_dict
@@ -550,12 +553,6 @@ class SwidgetDevice:
550
553
  """Disconnect from the websocket."""
551
554
  await self.disconnect()
552
555
 
553
- def __repr__(self) -> str:
554
- """Return the representation."""
555
- url = self.connection.ws_server_url
556
- prefix = "" if self.connection.connected else "not "
557
- return f"{type(self).__name__}(ws_server_url={url!r}, {prefix}connected)"
558
-
559
556
  def __repr__(self) -> str:
560
557
  if self._last_update == 0:
561
558
  return f"<{self.device_type} at {self.ip_address} - update() needed>"
@@ -137,8 +137,8 @@ class SwidgetWebsocket:
137
137
 
138
138
  async def receive_message_or_raise(self) -> Any:
139
139
  """Receive ONE (raw) message or raise."""
140
- assert self._ws_client
141
- ws_msg = await self._ws_client.receive()
140
+ assert self._client
141
+ ws_msg = await self._client.receive()
142
142
 
143
143
  if ws_msg.type in (WSMsgType.CLOSE, WSMsgType.CLOSED, WSMsgType.CLOSING):
144
144
  raise ConnectionError("Connection was closed.")
File without changes