Update black to 22.1.0 (#65788)

This commit is contained in:
Franck Nijhof 2022-02-05 14:19:37 +01:00 committed by GitHub
parent 58409d0895
commit fa09cf663e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 204 additions and 255 deletions

View file

@ -5,7 +5,7 @@ repos:
- id: pyupgrade - id: pyupgrade
args: [--py39-plus] args: [--py39-plus]
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 21.12b0 rev: 22.1.0
hooks: hooks:
- id: black - id: black
args: args:

View file

@ -24,11 +24,11 @@ def create_matcher(utterance):
# Group part # Group part
if group_match is not None: 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 # Optional part
elif optional_match is not None: elif optional_match is not None:
pattern.append(fr"(?:{optional_match.groups()[0]} *)?") pattern.append(rf"(?:{optional_match.groups()[0]} *)?")
pattern.append("$") pattern.append("$")
return re.compile("".join(pattern), re.I) return re.compile("".join(pattern), re.I)

View file

@ -65,7 +65,7 @@ class BanSensor(SensorEntity):
self.last_ban = None self.last_ban = None
self.log_parser = log_parser self.log_parser = log_parser
self.log_parser.ip_regex[self.jail] = re.compile( 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) _LOGGER.debug("Setting up jail %s", self.jail)

View file

@ -158,12 +158,9 @@ def wifi_entities_list(
if network_info: if network_info:
ssid = network_info["NewSSID"] ssid = network_info["NewSSID"]
_LOGGER.debug("SSID from device: <%s>", ssid) _LOGGER.debug("SSID from device: <%s>", ssid)
if ( if slugify(
slugify(
ssid, ssid,
) ) in [slugify(v) for v in networks.values()]:
in [slugify(v) for v in networks.values()]
):
_LOGGER.debug("SSID duplicated, adding suffix") _LOGGER.debug("SSID duplicated, adding suffix")
networks[i] = f'{ssid} {std_table[network_info["NewStandard"]]}' networks[i] = f'{ssid} {std_table[network_info["NewStandard"]]}'
else: else:

View file

@ -774,14 +774,10 @@ class StartStopTrait(_Trait):
"""Execute a StartStop command.""" """Execute a StartStop command."""
if command == COMMAND_STARTSTOP: if command == COMMAND_STARTSTOP:
if params["start"] is False: if params["start"] is False:
if ( if self.state.state in (
self.state.state
in (
cover.STATE_CLOSING, cover.STATE_CLOSING,
cover.STATE_OPENING, 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( await self.hass.services.async_call(
self.state.domain, self.state.domain,
cover.SERVICE_STOP_COVER, cover.SERVICE_STOP_COVER,

View file

@ -119,14 +119,10 @@ def get_accessory(hass, driver, state, aid, config): # noqa: C901
elif state.domain == "cover": elif state.domain == "cover":
device_class = state.attributes.get(ATTR_DEVICE_CLASS) device_class = state.attributes.get(ATTR_DEVICE_CLASS)
if ( if device_class in (
device_class
in (
cover.CoverDeviceClass.GARAGE, cover.CoverDeviceClass.GARAGE,
cover.CoverDeviceClass.GATE, cover.CoverDeviceClass.GATE,
) ) and features & (cover.SUPPORT_OPEN | cover.SUPPORT_CLOSE):
and features & (cover.SUPPORT_OPEN | cover.SUPPORT_CLOSE)
):
a_type = "GarageDoorOpener" a_type = "GarageDoorOpener"
elif ( elif (
device_class == cover.CoverDeviceClass.WINDOW device_class == cover.CoverDeviceClass.WINDOW

View file

@ -253,7 +253,7 @@ class PandoraMediaPlayer(MediaPlayerEntity):
try: try:
match_idx = self._pianobar.expect( 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", "No song playing",
"Select station", "Select station",
"Receiving new playlist", "Receiving new playlist",

View file

@ -91,15 +91,11 @@ async def async_setup_platform(
_LOGGER.debug("The following stations were returned: %s", stations) _LOGGER.debug("The following stations were returned: %s", stations)
for station in stations: for station in stations:
waqi_sensor = WaqiSensor(client, station) waqi_sensor = WaqiSensor(client, station)
if ( if not station_filter or {
not station_filter
or {
waqi_sensor.uid, waqi_sensor.uid,
waqi_sensor.url, waqi_sensor.url,
waqi_sensor.station_name, waqi_sensor.station_name,
} } & set(station_filter):
& set(station_filter)
):
dev.append(waqi_sensor) dev.append(waqi_sensor)
except ( except (
aiohttp.client_exceptions.ClientConnectorError, aiohttp.client_exceptions.ClientConnectorError,

View file

@ -431,14 +431,10 @@ class Thermostat(ZhaEntity, ClimateEntity):
self.debug("preset mode '%s' is not supported", preset_mode) self.debug("preset mode '%s' is not supported", preset_mode)
return return
if ( if self.preset_mode not in (
self.preset_mode
not in (
preset_mode, preset_mode,
PRESET_NONE, 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) self.debug("Couldn't turn off '%s' preset", self.preset_mode)
return return

View file

@ -42,5 +42,5 @@ def extract_domain_configs(config: ConfigType, domain: str) -> Sequence[str]:
Async friendly. Async friendly.
""" """
pattern = re.compile(fr"^{domain}(| .+)$") pattern = re.compile(rf"^{domain}(| .+)$")
return [key for key in config.keys() if pattern.match(key)] return [key for key in config.keys() if pattern.match(key)]

View file

@ -1,7 +1,7 @@
# Automatically generated from .pre-commit-config.yaml by gen_requirements_all.py, do not edit # Automatically generated from .pre-commit-config.yaml by gen_requirements_all.py, do not edit
bandit==1.7.0 bandit==1.7.0
black==21.12b0 black==22.1.0
codespell==2.1.0 codespell==2.1.0
flake8-comprehensions==3.7.0 flake8-comprehensions==3.7.0
flake8-docstrings==1.6.0 flake8-docstrings==1.6.0

View file

@ -118,8 +118,7 @@ def test_blueprint_validate():
is None is None
) )
assert ( assert models.Blueprint(
models.Blueprint(
{ {
"blueprint": { "blueprint": {
"name": "Hello", "name": "Hello",
@ -127,9 +126,7 @@ def test_blueprint_validate():
"homeassistant": {"min_version": "100000.0.0"}, "homeassistant": {"min_version": "100000.0.0"},
}, },
} }
).validate() ).validate() == ["Requires at least Home Assistant 100000.0.0"]
== ["Requires at least Home Assistant 100000.0.0"]
)
def test_blueprint_inputs(blueprint_2): def test_blueprint_inputs(blueprint_2):

View file

@ -1810,8 +1810,7 @@ async def test_extract_entities():
async def test_extract_devices(): async def test_extract_devices():
"""Test extracting devices.""" """Test extracting devices."""
assert ( assert condition.async_extract_devices(
condition.async_extract_devices(
{ {
"condition": "and", "condition": "and",
"conditions": [ "conditions": [
@ -1855,9 +1854,7 @@ async def test_extract_devices():
Template("{{ is_state('light.example', 'on') }}"), 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): async def test_condition_template_error(hass):

View file

@ -1050,8 +1050,7 @@ async def test_component_config_exceptions(hass, caplog):
# component.PLATFORM_SCHEMA # component.PLATFORM_SCHEMA
caplog.clear() caplog.clear()
assert ( assert await config_util.async_process_component_config(
await config_util.async_process_component_config(
hass, hass,
{"test_domain": {"platform": "test_platform"}}, {"test_domain": {"platform": "test_platform"}},
integration=Mock( 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 "ValueError: broken" in caplog.text
assert ( assert (
"Unknown error validating test_platform platform config with test_domain component platform schema" "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 ( assert await config_util.async_process_component_config(
await config_util.async_process_component_config(
hass, hass,
{"test_domain": {"platform": "test_platform"}}, {"test_domain": {"platform": "test_platform"}},
integration=Mock( integration=Mock(
domain="test_domain", domain="test_domain",
get_platform=Mock(return_value=None), get_platform=Mock(return_value=None),
get_component=Mock( get_component=Mock(return_value=Mock(spec=["PLATFORM_SCHEMA_BASE"])),
return_value=Mock(spec=["PLATFORM_SCHEMA_BASE"])
), ),
), ) == {"test_domain": []}
)
== {"test_domain": []}
)
assert "ValueError: broken" in caplog.text assert "ValueError: broken" in caplog.text
assert ( assert (
"Unknown error validating config for test_platform platform for test_domain component with PLATFORM_SCHEMA" "Unknown error validating config for test_platform platform for test_domain component with PLATFORM_SCHEMA"

View file

@ -461,8 +461,7 @@ def test_rgbww_to_color_temperature():
Temperature values must be in mireds Temperature values must be in mireds
Home Assistant uses rgbcw for rgbww Home Assistant uses rgbcw for rgbww
""" """
assert ( assert color_util.rgbww_to_color_temperature(
color_util.rgbww_to_color_temperature(
( (
0, 0,
0, 0,
@ -472,9 +471,7 @@ def test_rgbww_to_color_temperature():
), ),
153, 153,
500, 500,
) ) == (153, 255)
== (153, 255)
)
assert color_util.rgbww_to_color_temperature((0, 0, 0, 128, 0), 153, 500) == ( assert color_util.rgbww_to_color_temperature((0, 0, 0, 128, 0), 153, 500) == (
153, 153,
128, 128,
@ -507,15 +504,12 @@ def test_white_levels_to_color_temperature():
Temperature values must be in mireds Temperature values must be in mireds
Home Assistant uses rgbcw for rgbww Home Assistant uses rgbcw for rgbww
""" """
assert ( assert color_util.while_levels_to_color_temperature(
color_util.while_levels_to_color_temperature(
255, 255,
0, 0,
153, 153,
500, 500,
) ) == (153, 255)
== (153, 255)
)
assert color_util.while_levels_to_color_temperature(128, 0, 153, 500) == ( assert color_util.while_levels_to_color_temperature(128, 0, 153, 500) == (
153, 153,
128, 128,

View file

@ -143,21 +143,15 @@ def test_find_unserializable_data():
bad_data = object() bad_data = object()
assert ( assert find_paths_unserializable_data(
find_paths_unserializable_data(
[State("mock_domain.mock_entity", "on", {"bad": bad_data})], [State("mock_domain.mock_entity", "on", {"bad": bad_data})],
dump=partial(dumps, cls=MockJSONEncoder), 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 ( assert find_paths_unserializable_data(
find_paths_unserializable_data(
[Event("bad_event", {"bad_attribute": bad_data})], [Event("bad_event", {"bad_attribute": bad_data})],
dump=partial(dumps, cls=MockJSONEncoder), 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: class BadData:
def __init__(self): def __init__(self):
@ -166,10 +160,7 @@ def test_find_unserializable_data():
def as_dict(self): def as_dict(self):
return {"bla": self.bla} return {"bla": self.bla}
assert ( assert find_paths_unserializable_data(
find_paths_unserializable_data(
BadData(), BadData(),
dump=partial(dumps, cls=MockJSONEncoder), dump=partial(dumps, cls=MockJSONEncoder),
) ) == {"$(BadData).bla": bad_data}
== {"$(BadData).bla": bad_data}
)

View file

@ -25,10 +25,7 @@ def test_substitute():
with pytest.raises(UndefinedSubstitution): with pytest.raises(UndefinedSubstitution):
substitute(Input("hello"), {}) substitute(Input("hello"), {})
assert ( assert substitute(
substitute(
{"info": [1, Input("hello"), 2, Input("world")]}, {"info": [1, Input("hello"), 2, Input("world")]},
{"hello": 5, "world": 10}, {"hello": 5, "world": 10},
) ) == {"info": [1, 5, 2, 10]}
== {"info": [1, 5, 2, 10]}
)