From fc122eac6ba54c9a986b106b0e04419d6f6a0fc6 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Tue, 7 May 2024 17:55:14 +0200 Subject: [PATCH] Fix issues after rebasing --- kasa/iot/iotdevice.py | 5 +++-- kasa/iot/modules/cloud.py | 5 ++--- kasa/smart/modules/firmware.py | 21 ++------------------- kasa/smart/smartdevice.py | 10 ++++++---- 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/kasa/iot/iotdevice.py b/kasa/iot/iotdevice.py index 81735ec2..144d803d 100755 --- a/kasa/iot/iotdevice.py +++ b/kasa/iot/iotdevice.py @@ -26,6 +26,7 @@ from ..deviceconfig import DeviceConfig from ..emeterstatus import EmeterStatus from ..exceptions import KasaException from ..feature import Feature +from ..firmware import Firmware from ..module import ModuleT from ..protocol import BaseProtocol from .iotmodule import IotModule @@ -718,6 +719,6 @@ class IotDevice(Device): @property @requires_update - def firmware(self) -> Cloud: + def firmware(self) -> Firmware: """Returns object implementing the firmware handling.""" - return self.modules["cloud"] + return cast(Firmware, self.modules["cloud"]) diff --git a/kasa/iot/modules/cloud.py b/kasa/iot/modules/cloud.py index 4bcfee5c..4606442e 100644 --- a/kasa/iot/modules/cloud.py +++ b/kasa/iot/modules/cloud.py @@ -3,12 +3,11 @@ from __future__ import annotations import logging - -from pydantic.v1 import BaseModel - from datetime import date from typing import Optional +from pydantic.v1 import BaseModel, Field, validator + from ...feature import Feature from ...firmware import ( Firmware, diff --git a/kasa/smart/modules/firmware.py b/kasa/smart/modules/firmware.py index 07616cf4..81c7b62b 100644 --- a/kasa/smart/modules/firmware.py +++ b/kasa/smart/modules/firmware.py @@ -9,14 +9,13 @@ from typing import TYPE_CHECKING, Any, Optional # 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 -from pydantic.v1 import BaseModel, Field, validator # 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 +from pydantic.v1 import BaseModel, Field, validator from ...exceptions import SmartErrorCode -from ...feature import Feature, FeatureType +from ...feature import Feature from ...firmware import Firmware as FirmwareInterface from ...firmware import FirmwareUpdate as FirmwareUpdateInterface from ...firmware import UpdateResult @@ -105,22 +104,6 @@ class Firmware(SmartModule, FirmwareInterface): 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: """Query to execute during the update cycle.""" diff --git a/kasa/smart/smartdevice.py b/kasa/smart/smartdevice.py index 1e53bc0d..17f9d359 100644 --- a/kasa/smart/smartdevice.py +++ b/kasa/smart/smartdevice.py @@ -16,6 +16,7 @@ from ..emeterstatus import EmeterStatus from ..exceptions import AuthenticationError, DeviceError, KasaException, SmartErrorCode from ..fan import Fan from ..feature import Feature +from ..firmware import Firmware from ..module import ModuleT from ..smartprotocol import SmartProtocol from .modules import ( @@ -26,9 +27,11 @@ from .modules import ( DeviceModule, EnergyModule, FanModule, - Firmware, TimeModule, ) +from .modules import ( + Firmware as FirmwareModule, +) from .smartmodule import SmartModule _LOGGER = logging.getLogger(__name__) @@ -626,11 +629,10 @@ class SmartDevice(Bulb, Fan, Device): return self._device_type @property - def firmware(self) -> FirmwareInterface: + def firmware(self) -> Firmware: """Return firmware module.""" # TODO: open question: does it make sense to expose common modules? - fw = cast(FirmwareInterface, self.modules["Firmware"]) - return fw + return cast(Firmware, self.get_module(FirmwareModule)) @staticmethod def _get_device_type_from_components(