Update pre-commit hooks (#401)

* Update pre-commit hooks

* Fix implicit optionals
This commit is contained in:
Teemu R
2022-11-15 19:05:08 +01:00
committed by GitHub
parent ad5b5c2230
commit 327efb6c65
6 changed files with 39 additions and 22 deletions

View File

@@ -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,

View File

@@ -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.

View File

@@ -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)

View File

@@ -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.

View File

@@ -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