python-swidget 1.4.14__tar.gz → 1.4.15__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.
- {python_swidget-1.4.14 → python_swidget-1.4.15}/PKG-INFO +1 -1
- {python_swidget-1.4.14 → python_swidget-1.4.15}/pyproject.toml +1 -1
- {python_swidget-1.4.14 → python_swidget-1.4.15}/swidget/swidgetdevice.py +34 -6
- {python_swidget-1.4.14 → python_swidget-1.4.15}/README.md +0 -0
- {python_swidget-1.4.14 → python_swidget-1.4.15}/swidget/__init__.py +0 -0
- {python_swidget-1.4.14 → python_swidget-1.4.15}/swidget/cli.py +0 -0
- {python_swidget-1.4.14 → python_swidget-1.4.15}/swidget/discovery.py +0 -0
- {python_swidget-1.4.14 → python_swidget-1.4.15}/swidget/exceptions.py +0 -0
- {python_swidget-1.4.14 → python_swidget-1.4.15}/swidget/provision.py +0 -0
- {python_swidget-1.4.14 → python_swidget-1.4.15}/swidget/py.typed +0 -0
- {python_swidget-1.4.14 → python_swidget-1.4.15}/swidget/swidgetdimmer.py +0 -0
- {python_swidget-1.4.14 → python_swidget-1.4.15}/swidget/swidgetoutlet.py +0 -0
- {python_swidget-1.4.14 → python_swidget-1.4.15}/swidget/swidgetswitch.py +0 -0
- {python_swidget-1.4.14 → python_swidget-1.4.15}/swidget/swidgettimerswitch.py +0 -0
- {python_swidget-1.4.14 → python_swidget-1.4.15}/swidget/websocket.py +0 -0
|
@@ -249,6 +249,9 @@ class SwidgetDevice:
|
|
|
249
249
|
):
|
|
250
250
|
_LOGGER.debug("Calling SwidgetDevice.process_state()")
|
|
251
251
|
await self.process_state(message)
|
|
252
|
+
elif message["request_id"] == "device_config":
|
|
253
|
+
_LOGGER.debug("Calling SwidgetDevice.process_device_config()")
|
|
254
|
+
await self.process_device_config(message)
|
|
252
255
|
else:
|
|
253
256
|
message_type = ["request_id"]
|
|
254
257
|
_LOGGER.error(
|
|
@@ -374,11 +377,33 @@ class SwidgetDevice:
|
|
|
374
377
|
raise SwidgetConnectionException from e
|
|
375
378
|
|
|
376
379
|
async def get_device_config(self) -> Any:
|
|
377
|
-
"""
|
|
380
|
+
"""Refresh the local device_config cache.
|
|
381
|
+
|
|
382
|
+
Uses the websocket when available — the response lands on
|
|
383
|
+
``message_callback`` with ``request_id == "device_config"`` and
|
|
384
|
+
``process_device_config`` updates the cache. Falls back to HTTP
|
|
385
|
+
before the socket is connected (e.g. during entry pre-load).
|
|
386
|
+
"""
|
|
378
387
|
_LOGGER.debug("SwidgetDevice.get_device_config() called")
|
|
379
|
-
|
|
388
|
+
if self.use_websockets and self.connected:
|
|
389
|
+
_LOGGER.debug("In websocket mode. Sending get_device_config over websocket")
|
|
390
|
+
await self._websocket.send_str(
|
|
391
|
+
json.dumps(
|
|
392
|
+
{"type": "get_device_config", "request_id": "device_config"}
|
|
393
|
+
)
|
|
394
|
+
)
|
|
395
|
+
return
|
|
396
|
+
_LOGGER.debug("In http mode. Sending get_device_config over http")
|
|
380
397
|
config = await self.make_http_request("GET", "device_config")
|
|
381
|
-
self.
|
|
398
|
+
await self.process_device_config(config)
|
|
399
|
+
|
|
400
|
+
async def process_device_config(self, config) -> None:
|
|
401
|
+
"""Process a device_config payload from HTTP body or websocket message."""
|
|
402
|
+
_LOGGER.debug("SwidgetDevice.process_device_config() called")
|
|
403
|
+
# Strip transport metadata so DeviceConfiguration sees the same
|
|
404
|
+
# shape regardless of whether the payload arrived via HTTP or WS.
|
|
405
|
+
cfg = {k: v for k, v in config.items() if k != "request_id"}
|
|
406
|
+
self.device_config = DeviceConfiguration(cfg)
|
|
382
407
|
self._last_update = int(time.time())
|
|
383
408
|
|
|
384
409
|
async def set_device_config(self, updates: Dict[str, Any]) -> None:
|
|
@@ -499,7 +524,12 @@ class SwidgetDevice:
|
|
|
499
524
|
self._last_update = int(time.time())
|
|
500
525
|
|
|
501
526
|
async def update(self) -> None:
|
|
502
|
-
"""
|
|
527
|
+
"""Refresh state and summary; device_config is fetched separately.
|
|
528
|
+
|
|
529
|
+
device_config rarely changes, and a successful set_device_config
|
|
530
|
+
already pushes a fresh copy into the local cache, so we don't
|
|
531
|
+
re-fetch it on every coordinator poll.
|
|
532
|
+
"""
|
|
503
533
|
_LOGGER.debug("SwidgetDevice.update() called")
|
|
504
534
|
if self._last_update == 0:
|
|
505
535
|
_LOGGER.debug("Performing the initial update to obtain sysinfo")
|
|
@@ -507,8 +537,6 @@ class SwidgetDevice:
|
|
|
507
537
|
await self.get_state()
|
|
508
538
|
if self._friendly_name == "Unknown Swidget Device":
|
|
509
539
|
await self.get_friendly_name()
|
|
510
|
-
if not self.device_config.config_populated():
|
|
511
|
-
await self.get_device_config()
|
|
512
540
|
elif (int(time.time()) - self._last_update) < 5:
|
|
513
541
|
_LOGGER.debug("update() recently called, not executing")
|
|
514
542
|
else:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|