mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-01-10 14:57:07 +00:00
Improve smartdevice update module
* Expose current and latest firmware as features * Implement update loop that blocks until the update is complete
This commit is contained in:
parent
39e6aac63b
commit
06fe4e71cf
@ -1,6 +1,7 @@
|
|||||||
"""Implementation of firmware module."""
|
"""Implementation of firmware module."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
import asyncio
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
@ -16,6 +17,11 @@ from ...exceptions import SmartErrorCode
|
|||||||
from ...feature import Feature
|
from ...feature import Feature
|
||||||
from ..smartmodule import SmartModule
|
from ..smartmodule import SmartModule
|
||||||
|
|
||||||
|
# When support for cpython older than 3.11 is dropped
|
||||||
|
# async_timeout can be replaced with asyncio.timeout
|
||||||
|
from async_timeout import timeout as asyncio_timeout
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..smartdevice import SmartDevice
|
from ..smartdevice import SmartDevice
|
||||||
|
|
||||||
@ -99,6 +105,12 @@ class Firmware(SmartModule):
|
|||||||
category=Feature.Category.Info,
|
category=Feature.Category.Info,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
self._add_feature(
|
||||||
|
Feature(device, "Current firmware version", container=self, attribute_getter="current_firmware")
|
||||||
|
)
|
||||||
|
self._add_feature(
|
||||||
|
Feature(device, "Available firmware version", container=self, attribute_getter="latest_firmware")
|
||||||
|
)
|
||||||
|
|
||||||
def query(self) -> dict:
|
def query(self) -> dict:
|
||||||
"""Query to execute during the update cycle."""
|
"""Query to execute during the update cycle."""
|
||||||
@ -112,6 +124,7 @@ class Firmware(SmartModule):
|
|||||||
"""Return the current firmware version."""
|
"""Return the current firmware version."""
|
||||||
return self._device.hw_info["sw_ver"]
|
return self._device.hw_info["sw_ver"]
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def latest_firmware(self) -> str:
|
def latest_firmware(self) -> str:
|
||||||
"""Return the latest firmware version."""
|
"""Return the latest firmware version."""
|
||||||
|
Loading…
Reference in New Issue
Block a user