From 327efb6c65a762a6aec1d7c3bf3244a4b18ead85 Mon Sep 17 00:00:00 2001 From: Teemu R Date: Tue, 15 Nov 2022 19:05:08 +0100 Subject: [PATCH] Update pre-commit hooks (#401) * Update pre-commit hooks * Fix implicit optionals --- .pre-commit-config.yaml | 12 ++++++------ kasa/discover.py | 2 +- kasa/smartbulb.py | 21 +++++++++++++++------ kasa/smartdevice.py | 6 ++++-- kasa/smartdimmer.py | 10 ++++++---- kasa/smartstrip.py | 10 +++++++--- 6 files changed, 39 insertions(+), 22 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5e52e539..6887d059 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.1.0 + rev: v4.3.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -10,18 +10,18 @@ repos: - id: check-ast - repo: https://github.com/asottile/pyupgrade - rev: v2.31.1 + rev: v3.2.2 hooks: - id: pyupgrade args: ['--py37-plus'] - repo: https://github.com/python/black - rev: 22.3.0 + rev: 22.10.0 hooks: - id: black - repo: https://github.com/pycqa/flake8 - rev: 3.9.2 + rev: 5.0.4 hooks: - id: flake8 additional_dependencies: [flake8-docstrings] @@ -33,13 +33,13 @@ repos: additional_dependencies: [toml] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.942 + rev: v0.991 hooks: - id: mypy additional_dependencies: [types-click] - repo: https://github.com/PyCQA/doc8 - rev: '0.11.1' + rev: 'v1.0.0' hooks: - id: doc8 additional_dependencies: [tomli] diff --git a/kasa/discover.py b/kasa/discover.py index c09010ef..06285d1b 100755 --- a/kasa/discover.py +++ b/kasa/discover.py @@ -31,7 +31,7 @@ class _DiscoverProtocol(asyncio.DatagramProtocol): def __init__( self, *, - on_discovered: OnDiscoveredCallable = None, + on_discovered: Optional[OnDiscoveredCallable] = None, target: str = "255.255.255.255", discovery_packets: int = 3, interface: Optional[str] = None, diff --git a/kasa/smartbulb.py b/kasa/smartbulb.py index af79d7de..7d7db868 100644 --- a/kasa/smartbulb.py +++ b/kasa/smartbulb.py @@ -296,7 +296,9 @@ class SmartBulb(SmartDevice): # TODO: add warning and refer to use light.state? return await self._query_helper(self.LIGHT_SERVICE, "get_light_state") - async def set_light_state(self, state: Dict, *, transition: int = None) -> Dict: + async def set_light_state( + self, state: Dict, *, transition: Optional[int] = None + ) -> Dict: """Set the light state.""" if transition is not None: state["transition_period"] = transition @@ -345,7 +347,12 @@ class SmartBulb(SmartDevice): @requires_update async def set_hsv( - self, hue: int, saturation: int, value: int = None, *, transition: int = None + self, + hue: int, + saturation: int, + value: Optional[int] = None, + *, + transition: Optional[int] = None ) -> Dict: """Set new HSV. @@ -392,7 +399,7 @@ class SmartBulb(SmartDevice): @requires_update async def set_color_temp( - self, temp: int, *, brightness=None, transition: int = None + self, temp: int, *, brightness=None, transition: Optional[int] = None ) -> Dict: """Set the color temperature of the device in kelvin. @@ -426,7 +433,9 @@ class SmartBulb(SmartDevice): return int(light_state["brightness"]) @requires_update - async def set_brightness(self, brightness: int, *, transition: int = None) -> Dict: + async def set_brightness( + self, brightness: int, *, transition: Optional[int] = None + ) -> Dict: """Set the brightness in percentage. :param int brightness: brightness in percent @@ -464,14 +473,14 @@ class SmartBulb(SmartDevice): light_state = self.light_state return bool(light_state["on_off"]) - async def turn_off(self, *, transition: int = None, **kwargs) -> Dict: + async def turn_off(self, *, transition: Optional[int] = None, **kwargs) -> Dict: """Turn the bulb off. :param int transition: transition in milliseconds. """ return await self.set_light_state({"on_off": 0}, transition=transition) - async def turn_on(self, *, transition: int = None, **kwargs) -> Dict: + async def turn_on(self, *, transition: Optional[int] = None, **kwargs) -> Dict: """Turn the bulb on. :param int transition: transition in milliseconds. diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index cf3c5384..253853f8 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -510,7 +510,7 @@ class SmartDevice: return data async def get_emeter_daily( - self, year: int = None, month: int = None, kwh: bool = True + self, year: Optional[int] = None, month: Optional[int] = None, kwh: bool = True ) -> Dict: """Retrieve daily statistics for a given month. @@ -524,7 +524,9 @@ class SmartDevice: return await self.modules["emeter"].get_daystat(year=year, month=month, kwh=kwh) @requires_update - async def get_emeter_monthly(self, year: int = None, kwh: bool = True) -> Dict: + async def get_emeter_monthly( + self, year: Optional[int] = None, kwh: bool = True + ) -> Dict: """Retrieve monthly statistics for a given year. :param year: year for which to retrieve statistics (default: this year) diff --git a/kasa/smartdimmer.py b/kasa/smartdimmer.py index cb830d23..74d9221a 100644 --- a/kasa/smartdimmer.py +++ b/kasa/smartdimmer.py @@ -1,5 +1,5 @@ """Module for dimmers (currently only HS220).""" -from typing import Any, Dict +from typing import Any, Dict, Optional from kasa.modules import AmbientLight, Motion from kasa.smartdevice import DeviceType, SmartDeviceException, requires_update @@ -60,7 +60,9 @@ class SmartDimmer(SmartPlug): return int(sys_info["brightness"]) @requires_update - async def set_brightness(self, brightness: int, *, transition: int = None): + async def set_brightness( + self, brightness: int, *, transition: Optional[int] = None + ): """Set the new dimmer brightness level in percentage. :param int transition: transition duration in milliseconds. @@ -89,7 +91,7 @@ class SmartDimmer(SmartPlug): self.DIMMER_SERVICE, "set_brightness", {"brightness": brightness} ) - async def turn_off(self, *, transition: int = None, **kwargs): + async def turn_off(self, *, transition: Optional[int] = None, **kwargs): """Turn the bulb off. :param int transition: transition duration in milliseconds. @@ -100,7 +102,7 @@ class SmartDimmer(SmartPlug): return await super().turn_off() @requires_update - async def turn_on(self, *, transition: int = None, **kwargs): + async def turn_on(self, *, transition: Optional[int] = None, **kwargs): """Turn the bulb on. :param int transition: transition duration in milliseconds. diff --git a/kasa/smartstrip.py b/kasa/smartstrip.py index 47ada672..69ea03e5 100755 --- a/kasa/smartstrip.py +++ b/kasa/smartstrip.py @@ -172,7 +172,7 @@ class SmartStrip(SmartDevice): @requires_update async def get_emeter_daily( - self, year: int = None, month: int = None, kwh: bool = True + self, year: Optional[int] = None, month: Optional[int] = None, kwh: bool = True ) -> Dict: """Retrieve daily statistics for a given month. @@ -187,7 +187,9 @@ class SmartStrip(SmartDevice): ) @requires_update - async def get_emeter_monthly(self, year: int = None, kwh: bool = True) -> Dict: + async def get_emeter_monthly( + self, year: Optional[int] = None, kwh: bool = True + ) -> Dict: """Retrieve monthly statistics for a given year. :param year: year for which to retrieve statistics (default: this year) @@ -262,7 +264,9 @@ class SmartStripPlug(SmartPlug): """ await self._modular_update({}) - def _create_emeter_request(self, year: int = None, month: int = None): + def _create_emeter_request( + self, year: Optional[int] = None, month: Optional[int] = None + ): """Create a request for requesting all emeter statistics at once.""" if year is None: year = datetime.now().year