Use ruff and ruff format (#534)

Replaces the previously used linting and code formatting tools with ruff.
This commit is contained in:
Teemu R
2023-10-29 23:15:42 +01:00
committed by GitHub
parent 0061668c9f
commit c431dbb832
26 changed files with 220 additions and 174 deletions

View File

@@ -1,8 +1,16 @@
import logging
import re
from voluptuous import Coerce # type: ignore
from voluptuous import REMOVE_EXTRA, All, Any, Invalid, Optional, Range, Schema
from voluptuous import (
REMOVE_EXTRA,
All,
Any,
Coerce, # type: ignore
Invalid,
Optional,
Range,
Schema,
)
from ..protocol import TPLinkSmartHomeProtocol
@@ -305,7 +313,9 @@ class FakeTransportProtocol(TPLinkSmartHomeProtocol):
self.proto = proto
def set_alias(self, x, child_ids=[]):
def set_alias(self, x, child_ids=None):
if child_ids is None:
child_ids = []
_LOGGER.debug("Setting alias to %s, child_ids: %s", x["alias"], child_ids)
if child_ids:
for child in self.proto["system"]["get_sysinfo"]["children"]:
@@ -314,7 +324,9 @@ class FakeTransportProtocol(TPLinkSmartHomeProtocol):
else:
self.proto["system"]["get_sysinfo"]["alias"] = x["alias"]
def set_relay_state(self, x, child_ids=[]):
def set_relay_state(self, x, child_ids=None):
if child_ids is None:
child_ids = []
_LOGGER.debug("Setting relay state to %s", x["state"])
if not child_ids and "children" in self.proto["system"]["get_sysinfo"]:
@@ -362,12 +374,10 @@ class FakeTransportProtocol(TPLinkSmartHomeProtocol):
_LOGGER.debug("Current light state: %s", light_state)
new_state = light_state
if state_changes["on_off"] == 1: # turn on requested
if not light_state[
"on_off"
]: # if we were off, use the dft_on_state as a base
_LOGGER.debug("Bulb was off, using dft_on_state")
new_state = light_state["dft_on_state"]
# turn on requested, if we were off, use the dft_on_state as a base
if state_changes["on_off"] == 1 and not light_state["on_off"]:
_LOGGER.debug("Bulb was off, using dft_on_state")
new_state = light_state["dft_on_state"]
# override the existing settings
new_state.update(state_changes)
@@ -384,7 +394,7 @@ class FakeTransportProtocol(TPLinkSmartHomeProtocol):
self.proto["system"]["get_sysinfo"]["light_state"] = new_state
def set_preferred_state(self, new_state, *args):
"""Implementation of set_preferred_state."""
"""Implement set_preferred_state."""
self.proto["system"]["get_sysinfo"]["preferred_state"][
new_state["index"]
] = new_state
@@ -459,11 +469,11 @@ class FakeTransportProtocol(TPLinkSmartHomeProtocol):
child_ids = []
def get_response_for_module(target):
if target not in proto.keys():
if target not in proto:
return error(msg="target not found")
def get_response_for_command(cmd):
if cmd not in proto[target].keys():
if cmd not in proto[target]:
return error(msg=f"command {cmd} not found")
params = request[target][cmd]