mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-05-05 14:11:18 +00:00
Update pre-commit hooks (#401)
* Update pre-commit hooks * Fix implicit optionals
This commit is contained in:
parent
ad5b5c2230
commit
327efb6c65
@ -1,6 +1,6 @@
|
|||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.1.0
|
rev: v4.3.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
@ -10,18 +10,18 @@ repos:
|
|||||||
- id: check-ast
|
- id: check-ast
|
||||||
|
|
||||||
- repo: https://github.com/asottile/pyupgrade
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
rev: v2.31.1
|
rev: v3.2.2
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyupgrade
|
- id: pyupgrade
|
||||||
args: ['--py37-plus']
|
args: ['--py37-plus']
|
||||||
|
|
||||||
- repo: https://github.com/python/black
|
- repo: https://github.com/python/black
|
||||||
rev: 22.3.0
|
rev: 22.10.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
|
|
||||||
- repo: https://github.com/pycqa/flake8
|
- repo: https://github.com/pycqa/flake8
|
||||||
rev: 3.9.2
|
rev: 5.0.4
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: flake8
|
||||||
additional_dependencies: [flake8-docstrings]
|
additional_dependencies: [flake8-docstrings]
|
||||||
@ -33,13 +33,13 @@ repos:
|
|||||||
additional_dependencies: [toml]
|
additional_dependencies: [toml]
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||||
rev: v0.942
|
rev: v0.991
|
||||||
hooks:
|
hooks:
|
||||||
- id: mypy
|
- id: mypy
|
||||||
additional_dependencies: [types-click]
|
additional_dependencies: [types-click]
|
||||||
|
|
||||||
- repo: https://github.com/PyCQA/doc8
|
- repo: https://github.com/PyCQA/doc8
|
||||||
rev: '0.11.1'
|
rev: 'v1.0.0'
|
||||||
hooks:
|
hooks:
|
||||||
- id: doc8
|
- id: doc8
|
||||||
additional_dependencies: [tomli]
|
additional_dependencies: [tomli]
|
||||||
|
@ -31,7 +31,7 @@ class _DiscoverProtocol(asyncio.DatagramProtocol):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
on_discovered: OnDiscoveredCallable = None,
|
on_discovered: Optional[OnDiscoveredCallable] = None,
|
||||||
target: str = "255.255.255.255",
|
target: str = "255.255.255.255",
|
||||||
discovery_packets: int = 3,
|
discovery_packets: int = 3,
|
||||||
interface: Optional[str] = None,
|
interface: Optional[str] = None,
|
||||||
|
@ -296,7 +296,9 @@ class SmartBulb(SmartDevice):
|
|||||||
# TODO: add warning and refer to use light.state?
|
# TODO: add warning and refer to use light.state?
|
||||||
return await self._query_helper(self.LIGHT_SERVICE, "get_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."""
|
"""Set the light state."""
|
||||||
if transition is not None:
|
if transition is not None:
|
||||||
state["transition_period"] = transition
|
state["transition_period"] = transition
|
||||||
@ -345,7 +347,12 @@ class SmartBulb(SmartDevice):
|
|||||||
|
|
||||||
@requires_update
|
@requires_update
|
||||||
async def set_hsv(
|
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:
|
) -> Dict:
|
||||||
"""Set new HSV.
|
"""Set new HSV.
|
||||||
|
|
||||||
@ -392,7 +399,7 @@ class SmartBulb(SmartDevice):
|
|||||||
|
|
||||||
@requires_update
|
@requires_update
|
||||||
async def set_color_temp(
|
async def set_color_temp(
|
||||||
self, temp: int, *, brightness=None, transition: int = None
|
self, temp: int, *, brightness=None, transition: Optional[int] = None
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
"""Set the color temperature of the device in kelvin.
|
"""Set the color temperature of the device in kelvin.
|
||||||
|
|
||||||
@ -426,7 +433,9 @@ class SmartBulb(SmartDevice):
|
|||||||
return int(light_state["brightness"])
|
return int(light_state["brightness"])
|
||||||
|
|
||||||
@requires_update
|
@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.
|
"""Set the brightness in percentage.
|
||||||
|
|
||||||
:param int brightness: brightness in percent
|
:param int brightness: brightness in percent
|
||||||
@ -464,14 +473,14 @@ class SmartBulb(SmartDevice):
|
|||||||
light_state = self.light_state
|
light_state = self.light_state
|
||||||
return bool(light_state["on_off"])
|
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.
|
"""Turn the bulb off.
|
||||||
|
|
||||||
:param int transition: transition in milliseconds.
|
:param int transition: transition in milliseconds.
|
||||||
"""
|
"""
|
||||||
return await self.set_light_state({"on_off": 0}, transition=transition)
|
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.
|
"""Turn the bulb on.
|
||||||
|
|
||||||
:param int transition: transition in milliseconds.
|
:param int transition: transition in milliseconds.
|
||||||
|
@ -510,7 +510,7 @@ class SmartDevice:
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
async def get_emeter_daily(
|
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:
|
) -> Dict:
|
||||||
"""Retrieve daily statistics for a given month.
|
"""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)
|
return await self.modules["emeter"].get_daystat(year=year, month=month, kwh=kwh)
|
||||||
|
|
||||||
@requires_update
|
@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.
|
"""Retrieve monthly statistics for a given year.
|
||||||
|
|
||||||
:param year: year for which to retrieve statistics (default: this year)
|
:param year: year for which to retrieve statistics (default: this year)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""Module for dimmers (currently only HS220)."""
|
"""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.modules import AmbientLight, Motion
|
||||||
from kasa.smartdevice import DeviceType, SmartDeviceException, requires_update
|
from kasa.smartdevice import DeviceType, SmartDeviceException, requires_update
|
||||||
@ -60,7 +60,9 @@ class SmartDimmer(SmartPlug):
|
|||||||
return int(sys_info["brightness"])
|
return int(sys_info["brightness"])
|
||||||
|
|
||||||
@requires_update
|
@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.
|
"""Set the new dimmer brightness level in percentage.
|
||||||
|
|
||||||
:param int transition: transition duration in milliseconds.
|
:param int transition: transition duration in milliseconds.
|
||||||
@ -89,7 +91,7 @@ class SmartDimmer(SmartPlug):
|
|||||||
self.DIMMER_SERVICE, "set_brightness", {"brightness": brightness}
|
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.
|
"""Turn the bulb off.
|
||||||
|
|
||||||
:param int transition: transition duration in milliseconds.
|
:param int transition: transition duration in milliseconds.
|
||||||
@ -100,7 +102,7 @@ class SmartDimmer(SmartPlug):
|
|||||||
return await super().turn_off()
|
return await super().turn_off()
|
||||||
|
|
||||||
@requires_update
|
@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.
|
"""Turn the bulb on.
|
||||||
|
|
||||||
:param int transition: transition duration in milliseconds.
|
:param int transition: transition duration in milliseconds.
|
||||||
|
@ -172,7 +172,7 @@ class SmartStrip(SmartDevice):
|
|||||||
|
|
||||||
@requires_update
|
@requires_update
|
||||||
async def get_emeter_daily(
|
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:
|
) -> Dict:
|
||||||
"""Retrieve daily statistics for a given month.
|
"""Retrieve daily statistics for a given month.
|
||||||
|
|
||||||
@ -187,7 +187,9 @@ class SmartStrip(SmartDevice):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@requires_update
|
@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.
|
"""Retrieve monthly statistics for a given year.
|
||||||
|
|
||||||
:param year: year for which to retrieve statistics (default: this year)
|
:param year: year for which to retrieve statistics (default: this year)
|
||||||
@ -262,7 +264,9 @@ class SmartStripPlug(SmartPlug):
|
|||||||
"""
|
"""
|
||||||
await self._modular_update({})
|
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."""
|
"""Create a request for requesting all emeter statistics at once."""
|
||||||
if year is None:
|
if year is None:
|
||||||
year = datetime.now().year
|
year = datetime.now().year
|
||||||
|
Loading…
x
Reference in New Issue
Block a user