Update black to 22.1.0 (#65788)
This commit is contained in:
parent
58409d0895
commit
fa09cf663e
42 changed files with 204 additions and 255 deletions
|
@ -5,7 +5,7 @@ repos:
|
|||
- id: pyupgrade
|
||||
args: [--py39-plus]
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 21.12b0
|
||||
rev: 22.1.0
|
||||
hooks:
|
||||
- id: black
|
||||
args:
|
||||
|
|
|
@ -24,11 +24,11 @@ def create_matcher(utterance):
|
|||
|
||||
# Group part
|
||||
if group_match is not None:
|
||||
pattern.append(fr"(?P<{group_match.groups()[0]}>[\w ]+?)\s*")
|
||||
pattern.append(rf"(?P<{group_match.groups()[0]}>[\w ]+?)\s*")
|
||||
|
||||
# Optional part
|
||||
elif optional_match is not None:
|
||||
pattern.append(fr"(?:{optional_match.groups()[0]} *)?")
|
||||
pattern.append(rf"(?:{optional_match.groups()[0]} *)?")
|
||||
|
||||
pattern.append("$")
|
||||
return re.compile("".join(pattern), re.I)
|
||||
|
|
|
@ -65,7 +65,7 @@ class BanSensor(SensorEntity):
|
|||
self.last_ban = None
|
||||
self.log_parser = log_parser
|
||||
self.log_parser.ip_regex[self.jail] = re.compile(
|
||||
fr"\[{re.escape(self.jail)}\]\s*(Ban|Unban) (.*)"
|
||||
rf"\[{re.escape(self.jail)}\]\s*(Ban|Unban) (.*)"
|
||||
)
|
||||
_LOGGER.debug("Setting up jail %s", self.jail)
|
||||
|
||||
|
|
|
@ -158,12 +158,9 @@ def wifi_entities_list(
|
|||
if network_info:
|
||||
ssid = network_info["NewSSID"]
|
||||
_LOGGER.debug("SSID from device: <%s>", ssid)
|
||||
if (
|
||||
slugify(
|
||||
if slugify(
|
||||
ssid,
|
||||
)
|
||||
in [slugify(v) for v in networks.values()]
|
||||
):
|
||||
) in [slugify(v) for v in networks.values()]:
|
||||
_LOGGER.debug("SSID duplicated, adding suffix")
|
||||
networks[i] = f'{ssid} {std_table[network_info["NewStandard"]]}'
|
||||
else:
|
||||
|
|
|
@ -774,14 +774,10 @@ class StartStopTrait(_Trait):
|
|||
"""Execute a StartStop command."""
|
||||
if command == COMMAND_STARTSTOP:
|
||||
if params["start"] is False:
|
||||
if (
|
||||
self.state.state
|
||||
in (
|
||||
if self.state.state in (
|
||||
cover.STATE_CLOSING,
|
||||
cover.STATE_OPENING,
|
||||
)
|
||||
or self.state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
):
|
||||
) or self.state.attributes.get(ATTR_ASSUMED_STATE):
|
||||
await self.hass.services.async_call(
|
||||
self.state.domain,
|
||||
cover.SERVICE_STOP_COVER,
|
||||
|
|
|
@ -119,14 +119,10 @@ def get_accessory(hass, driver, state, aid, config): # noqa: C901
|
|||
elif state.domain == "cover":
|
||||
device_class = state.attributes.get(ATTR_DEVICE_CLASS)
|
||||
|
||||
if (
|
||||
device_class
|
||||
in (
|
||||
if device_class in (
|
||||
cover.CoverDeviceClass.GARAGE,
|
||||
cover.CoverDeviceClass.GATE,
|
||||
)
|
||||
and features & (cover.SUPPORT_OPEN | cover.SUPPORT_CLOSE)
|
||||
):
|
||||
) and features & (cover.SUPPORT_OPEN | cover.SUPPORT_CLOSE):
|
||||
a_type = "GarageDoorOpener"
|
||||
elif (
|
||||
device_class == cover.CoverDeviceClass.WINDOW
|
||||
|
|
|
@ -253,7 +253,7 @@ class PandoraMediaPlayer(MediaPlayerEntity):
|
|||
try:
|
||||
match_idx = self._pianobar.expect(
|
||||
[
|
||||
br"(\d\d):(\d\d)/(\d\d):(\d\d)",
|
||||
rb"(\d\d):(\d\d)/(\d\d):(\d\d)",
|
||||
"No song playing",
|
||||
"Select station",
|
||||
"Receiving new playlist",
|
||||
|
|
|
@ -91,15 +91,11 @@ async def async_setup_platform(
|
|||
_LOGGER.debug("The following stations were returned: %s", stations)
|
||||
for station in stations:
|
||||
waqi_sensor = WaqiSensor(client, station)
|
||||
if (
|
||||
not station_filter
|
||||
or {
|
||||
if not station_filter or {
|
||||
waqi_sensor.uid,
|
||||
waqi_sensor.url,
|
||||
waqi_sensor.station_name,
|
||||
}
|
||||
& set(station_filter)
|
||||
):
|
||||
} & set(station_filter):
|
||||
dev.append(waqi_sensor)
|
||||
except (
|
||||
aiohttp.client_exceptions.ClientConnectorError,
|
||||
|
|
|
@ -431,14 +431,10 @@ class Thermostat(ZhaEntity, ClimateEntity):
|
|||
self.debug("preset mode '%s' is not supported", preset_mode)
|
||||
return
|
||||
|
||||
if (
|
||||
self.preset_mode
|
||||
not in (
|
||||
if self.preset_mode not in (
|
||||
preset_mode,
|
||||
PRESET_NONE,
|
||||
)
|
||||
and not await self.async_preset_handler(self.preset_mode, enable=False)
|
||||
):
|
||||
) and not await self.async_preset_handler(self.preset_mode, enable=False):
|
||||
self.debug("Couldn't turn off '%s' preset", self.preset_mode)
|
||||
return
|
||||
|
||||
|
|
|
@ -42,5 +42,5 @@ def extract_domain_configs(config: ConfigType, domain: str) -> Sequence[str]:
|
|||
|
||||
Async friendly.
|
||||
"""
|
||||
pattern = re.compile(fr"^{domain}(| .+)$")
|
||||
pattern = re.compile(rf"^{domain}(| .+)$")
|
||||
return [key for key in config.keys() if pattern.match(key)]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Automatically generated from .pre-commit-config.yaml by gen_requirements_all.py, do not edit
|
||||
|
||||
bandit==1.7.0
|
||||
black==21.12b0
|
||||
black==22.1.0
|
||||
codespell==2.1.0
|
||||
flake8-comprehensions==3.7.0
|
||||
flake8-docstrings==1.6.0
|
||||
|
|
|
@ -118,8 +118,7 @@ def test_blueprint_validate():
|
|||
is None
|
||||
)
|
||||
|
||||
assert (
|
||||
models.Blueprint(
|
||||
assert models.Blueprint(
|
||||
{
|
||||
"blueprint": {
|
||||
"name": "Hello",
|
||||
|
@ -127,9 +126,7 @@ def test_blueprint_validate():
|
|||
"homeassistant": {"min_version": "100000.0.0"},
|
||||
},
|
||||
}
|
||||
).validate()
|
||||
== ["Requires at least Home Assistant 100000.0.0"]
|
||||
)
|
||||
).validate() == ["Requires at least Home Assistant 100000.0.0"]
|
||||
|
||||
|
||||
def test_blueprint_inputs(blueprint_2):
|
||||
|
|
|
@ -1810,8 +1810,7 @@ async def test_extract_entities():
|
|||
|
||||
async def test_extract_devices():
|
||||
"""Test extracting devices."""
|
||||
assert (
|
||||
condition.async_extract_devices(
|
||||
assert condition.async_extract_devices(
|
||||
{
|
||||
"condition": "and",
|
||||
"conditions": [
|
||||
|
@ -1855,9 +1854,7 @@ async def test_extract_devices():
|
|||
Template("{{ is_state('light.example', 'on') }}"),
|
||||
],
|
||||
}
|
||||
)
|
||||
== {"abcd", "qwer", "abcd_not", "qwer_not", "abcd_or", "qwer_or"}
|
||||
)
|
||||
) == {"abcd", "qwer", "abcd_not", "qwer_not", "abcd_or", "qwer_or"}
|
||||
|
||||
|
||||
async def test_condition_template_error(hass):
|
||||
|
|
|
@ -1050,8 +1050,7 @@ async def test_component_config_exceptions(hass, caplog):
|
|||
|
||||
# component.PLATFORM_SCHEMA
|
||||
caplog.clear()
|
||||
assert (
|
||||
await config_util.async_process_component_config(
|
||||
assert await config_util.async_process_component_config(
|
||||
hass,
|
||||
{"test_domain": {"platform": "test_platform"}},
|
||||
integration=Mock(
|
||||
|
@ -1064,9 +1063,7 @@ async def test_component_config_exceptions(hass, caplog):
|
|||
)
|
||||
),
|
||||
),
|
||||
)
|
||||
== {"test_domain": []}
|
||||
)
|
||||
) == {"test_domain": []}
|
||||
assert "ValueError: broken" in caplog.text
|
||||
assert (
|
||||
"Unknown error validating test_platform platform config with test_domain component platform schema"
|
||||
|
@ -1085,20 +1082,15 @@ async def test_component_config_exceptions(hass, caplog):
|
|||
)
|
||||
),
|
||||
):
|
||||
assert (
|
||||
await config_util.async_process_component_config(
|
||||
assert await config_util.async_process_component_config(
|
||||
hass,
|
||||
{"test_domain": {"platform": "test_platform"}},
|
||||
integration=Mock(
|
||||
domain="test_domain",
|
||||
get_platform=Mock(return_value=None),
|
||||
get_component=Mock(
|
||||
return_value=Mock(spec=["PLATFORM_SCHEMA_BASE"])
|
||||
get_component=Mock(return_value=Mock(spec=["PLATFORM_SCHEMA_BASE"])),
|
||||
),
|
||||
),
|
||||
)
|
||||
== {"test_domain": []}
|
||||
)
|
||||
) == {"test_domain": []}
|
||||
assert "ValueError: broken" in caplog.text
|
||||
assert (
|
||||
"Unknown error validating config for test_platform platform for test_domain component with PLATFORM_SCHEMA"
|
||||
|
|
|
@ -461,8 +461,7 @@ def test_rgbww_to_color_temperature():
|
|||
Temperature values must be in mireds
|
||||
Home Assistant uses rgbcw for rgbww
|
||||
"""
|
||||
assert (
|
||||
color_util.rgbww_to_color_temperature(
|
||||
assert color_util.rgbww_to_color_temperature(
|
||||
(
|
||||
0,
|
||||
0,
|
||||
|
@ -472,9 +471,7 @@ def test_rgbww_to_color_temperature():
|
|||
),
|
||||
153,
|
||||
500,
|
||||
)
|
||||
== (153, 255)
|
||||
)
|
||||
) == (153, 255)
|
||||
assert color_util.rgbww_to_color_temperature((0, 0, 0, 128, 0), 153, 500) == (
|
||||
153,
|
||||
128,
|
||||
|
@ -507,15 +504,12 @@ def test_white_levels_to_color_temperature():
|
|||
Temperature values must be in mireds
|
||||
Home Assistant uses rgbcw for rgbww
|
||||
"""
|
||||
assert (
|
||||
color_util.while_levels_to_color_temperature(
|
||||
assert color_util.while_levels_to_color_temperature(
|
||||
255,
|
||||
0,
|
||||
153,
|
||||
500,
|
||||
)
|
||||
== (153, 255)
|
||||
)
|
||||
) == (153, 255)
|
||||
assert color_util.while_levels_to_color_temperature(128, 0, 153, 500) == (
|
||||
153,
|
||||
128,
|
||||
|
|
|
@ -143,21 +143,15 @@ def test_find_unserializable_data():
|
|||
|
||||
bad_data = object()
|
||||
|
||||
assert (
|
||||
find_paths_unserializable_data(
|
||||
assert find_paths_unserializable_data(
|
||||
[State("mock_domain.mock_entity", "on", {"bad": bad_data})],
|
||||
dump=partial(dumps, cls=MockJSONEncoder),
|
||||
)
|
||||
== {"$[0](State: mock_domain.mock_entity).attributes.bad": bad_data}
|
||||
)
|
||||
) == {"$[0](State: mock_domain.mock_entity).attributes.bad": bad_data}
|
||||
|
||||
assert (
|
||||
find_paths_unserializable_data(
|
||||
assert find_paths_unserializable_data(
|
||||
[Event("bad_event", {"bad_attribute": bad_data})],
|
||||
dump=partial(dumps, cls=MockJSONEncoder),
|
||||
)
|
||||
== {"$[0](Event: bad_event).data.bad_attribute": bad_data}
|
||||
)
|
||||
) == {"$[0](Event: bad_event).data.bad_attribute": bad_data}
|
||||
|
||||
class BadData:
|
||||
def __init__(self):
|
||||
|
@ -166,10 +160,7 @@ def test_find_unserializable_data():
|
|||
def as_dict(self):
|
||||
return {"bla": self.bla}
|
||||
|
||||
assert (
|
||||
find_paths_unserializable_data(
|
||||
assert find_paths_unserializable_data(
|
||||
BadData(),
|
||||
dump=partial(dumps, cls=MockJSONEncoder),
|
||||
)
|
||||
== {"$(BadData).bla": bad_data}
|
||||
)
|
||||
) == {"$(BadData).bla": bad_data}
|
||||
|
|
|
@ -25,10 +25,7 @@ def test_substitute():
|
|||
with pytest.raises(UndefinedSubstitution):
|
||||
substitute(Input("hello"), {})
|
||||
|
||||
assert (
|
||||
substitute(
|
||||
assert substitute(
|
||||
{"info": [1, Input("hello"), 2, Input("world")]},
|
||||
{"hello": 5, "world": 10},
|
||||
)
|
||||
== {"info": [1, 5, 2, 10]}
|
||||
)
|
||||
) == {"info": [1, 5, 2, 10]}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue