Add ruff B005, B015, B032 and fix occurrences (#113543)
Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com> Co-authored-by: J. Nick Koston <nick@koston.org>pull/113583/head
parent
bb667abd51
commit
27e844e3bf
|
@ -115,7 +115,7 @@ class FroniusConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
) -> ConfigFlowResult:
|
||||
"""Handle a flow initiated by the DHCP client."""
|
||||
for entry in self._async_current_entries(include_ignore=False):
|
||||
if entry.data[CONF_HOST].lstrip("http://").rstrip("/").lower() in (
|
||||
if entry.data[CONF_HOST].removeprefix("http://").rstrip("/").lower() in (
|
||||
discovery_info.ip,
|
||||
discovery_info.hostname,
|
||||
):
|
||||
|
|
|
@ -95,7 +95,7 @@ class RoombaConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
) -> ConfigFlowResult:
|
||||
"""Handle zeroconf discovery."""
|
||||
return await self._async_step_discovery(
|
||||
discovery_info.host, discovery_info.hostname.lower().rstrip(".local.")
|
||||
discovery_info.host, discovery_info.hostname.lower().removesuffix(".local.")
|
||||
)
|
||||
|
||||
async def async_step_dhcp(
|
||||
|
|
|
@ -580,10 +580,13 @@ filterwarnings = [
|
|||
[tool.ruff.lint]
|
||||
select = [
|
||||
"B002", # Python does not support the unary prefix increment
|
||||
"B005", # Using .strip() with multi-character strings is misleading
|
||||
"B007", # Loop control variable {name} not used within loop body
|
||||
"B014", # Exception handler with duplicate exception
|
||||
"B015", # Pointless comparison. Did you mean to assign a value? Otherwise, prepend assert or remove it.
|
||||
"B023", # Function definition does not bind loop variable {name}
|
||||
"B026", # Star-arg unpacking after a keyword argument is strongly discouraged
|
||||
"B032", # Possible unintentional type annotation (using :). Did you mean to assign (using =)?
|
||||
"B904", # Use raise from to specify exception cause
|
||||
"C", # complexity
|
||||
"COM818", # Trailing comma on bare tuple prohibited
|
||||
|
|
|
@ -410,7 +410,7 @@ async def test_report_state_number(
|
|||
}
|
||||
|
||||
if unit:
|
||||
state["unit_of_measurement"]: unit
|
||||
state["unit_of_measurement"] = unit
|
||||
|
||||
hass.states.async_set(
|
||||
f"{domain}.test_{domain}",
|
||||
|
|
|
@ -244,7 +244,7 @@ async def test_test_switch_adapters_when_out_of_slots(
|
|||
) as allocate_slot_mock:
|
||||
ble_device = hci0_device_advs["00:00:00:00:00:03"][0]
|
||||
client = bleak.BleakClient(ble_device)
|
||||
await client.connect() is True
|
||||
assert await client.connect() is True
|
||||
assert release_slot_mock.call_count == 0
|
||||
|
||||
cancel_hci0()
|
||||
|
|
|
@ -55,4 +55,4 @@ async def test_client_usage_while_not_connected(client_data: ESPHomeClientData)
|
|||
with pytest.raises(
|
||||
BleakError, match=f"{ESP_NAME}.*{ESP_MAC_ADDRESS}.*not connected"
|
||||
):
|
||||
await client.write_gatt_char("test", b"test") is False
|
||||
assert await client.write_gatt_char("test", b"test") is False
|
||||
|
|
|
@ -46,11 +46,11 @@ async def test_turn_on_color(hass: HomeAssistant, setup_evil_genius_labs) -> Non
|
|||
)
|
||||
|
||||
assert len(mock_set_path_value.mock_calls) == 2
|
||||
mock_set_path_value.mock_calls[0][1] == ("brightness", 100)
|
||||
mock_set_path_value.mock_calls[1][1] == ("power", 1)
|
||||
assert mock_set_path_value.mock_calls[0][1] == ("brightness", 100)
|
||||
assert mock_set_path_value.mock_calls[1][1] == ("power", 1)
|
||||
|
||||
assert len(mock_set_rgb_color.mock_calls) == 1
|
||||
mock_set_rgb_color.mock_calls[0][1] == (10, 20, 30)
|
||||
assert mock_set_rgb_color.mock_calls[0][1] == (10, 20, 30)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("platforms", [("light",)])
|
||||
|
@ -68,8 +68,8 @@ async def test_turn_on_effect(hass: HomeAssistant, setup_evil_genius_labs) -> No
|
|||
)
|
||||
|
||||
assert len(mock_set_path_value.mock_calls) == 2
|
||||
mock_set_path_value.mock_calls[0][1] == ("pattern", 4)
|
||||
mock_set_path_value.mock_calls[1][1] == ("power", 1)
|
||||
assert mock_set_path_value.mock_calls[0][1] == ("pattern", 4)
|
||||
assert mock_set_path_value.mock_calls[1][1] == ("power", 1)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("platforms", [("light",)])
|
||||
|
@ -86,4 +86,4 @@ async def test_turn_off(hass: HomeAssistant, setup_evil_genius_labs) -> None:
|
|||
)
|
||||
|
||||
assert len(mock_set_path_value.mock_calls) == 1
|
||||
mock_set_path_value.mock_calls[0][1] == ("power", 0)
|
||||
assert mock_set_path_value.mock_calls[0][1] == ("power", 0)
|
||||
|
|
|
@ -816,7 +816,7 @@ async def test_calendar_yaml_update(
|
|||
assert await component_setup()
|
||||
|
||||
mock_calendars_yaml().read.assert_called()
|
||||
mock_calendars_yaml().write.called is expect_write_calls
|
||||
assert mock_calendars_yaml().write.called is expect_write_calls
|
||||
|
||||
state = hass.states.get(TEST_API_ENTITY)
|
||||
assert state
|
||||
|
|
|
@ -1719,9 +1719,12 @@ async def test_multi_pan_addon_using_device_not_running(
|
|||
"state": "not_running",
|
||||
}
|
||||
|
||||
await silabs_multiprotocol_addon.multi_pan_addon_using_device(
|
||||
hass, "/dev/ttyAMA1"
|
||||
) is False
|
||||
assert (
|
||||
await silabs_multiprotocol_addon.multi_pan_addon_using_device(
|
||||
hass, "/dev/ttyAMA1"
|
||||
)
|
||||
is False
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -1750,6 +1753,9 @@ async def test_multi_pan_addon_using_device(
|
|||
"state": "running",
|
||||
}
|
||||
|
||||
await silabs_multiprotocol_addon.multi_pan_addon_using_device(
|
||||
hass, "/dev/ttyAMA1"
|
||||
) is expected_result
|
||||
assert (
|
||||
await silabs_multiprotocol_addon.multi_pan_addon_using_device(
|
||||
hass, "/dev/ttyAMA1"
|
||||
)
|
||||
is expected_result
|
||||
)
|
||||
|
|
|
@ -88,7 +88,7 @@ async def test_process_play_media_url(hass: HomeAssistant, mock_sign_path) -> No
|
|||
)
|
||||
|
||||
# Not changing a URL which is not absolute and does not start with /
|
||||
async_process_play_media_url(hass, "hello") == "hello"
|
||||
assert async_process_play_media_url(hass, "hello") == "hello"
|
||||
|
||||
|
||||
async def test_process_play_media_url_for_addon(
|
||||
|
|
|
@ -543,7 +543,7 @@ def test_saving_state_with_commit_interval_zero(
|
|||
) -> None:
|
||||
"""Test saving a state with a commit interval of zero."""
|
||||
hass = hass_recorder({"commit_interval": 0})
|
||||
get_instance(hass).commit_interval == 0
|
||||
assert get_instance(hass).commit_interval == 0
|
||||
|
||||
entity_id = "test.recorder"
|
||||
state = "restoring_from_db"
|
||||
|
|
|
@ -412,7 +412,7 @@ async def test_setup_with_cloud(
|
|||
|
||||
for config_entry in hass.config_entries.async_entries("withings"):
|
||||
await hass.config_entries.async_remove(config_entry.entry_id)
|
||||
fake_delete_cloudhook.call_count == 2
|
||||
assert fake_delete_cloudhook.call_count == 2
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert not hass.config_entries.async_entries(DOMAIN)
|
||||
|
|
|
@ -264,7 +264,7 @@ async def test_gateway_initialize_bellows_thread(
|
|||
) as mock_new:
|
||||
await zha_gateway.async_initialize()
|
||||
|
||||
mock_new.mock_calls[-1].kwargs["config"]["use_thread"] is thread_state
|
||||
assert mock_new.mock_calls[-1].kwargs["config"]["use_thread"] is thread_state
|
||||
|
||||
await zha_gateway.shutdown()
|
||||
|
||||
|
|
|
@ -938,7 +938,7 @@ async def test_websocket_change_channel(
|
|||
assert msg["type"] == const.TYPE_RESULT
|
||||
assert msg["success"]
|
||||
|
||||
change_channel_mock.mock_calls == [call(ANY, new_channel)]
|
||||
change_channel_mock.assert_has_calls([call(ANY, new_channel)])
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
|
@ -288,8 +288,8 @@ async def test_sending_named_tuple(
|
|||
session = client.async_create_clientsession(hass)
|
||||
resp = await session.post("http://127.0.0.1/rgb", json={"rgb": RGBColor(4, 3, 2)})
|
||||
assert resp.status == 200
|
||||
await resp.json() == {"rgb": RGBColor(4, 3, 2)}
|
||||
aioclient_mock.mock_calls[0][2]["rgb"] == RGBColor(4, 3, 2)
|
||||
assert await resp.json() == {"rgb": [4, 3, 2]}
|
||||
assert aioclient_mock.mock_calls[0][2]["rgb"] == RGBColor(4, 3, 2)
|
||||
|
||||
|
||||
async def test_client_session_immutable_headers(hass: HomeAssistant) -> None:
|
||||
|
|
Loading…
Reference in New Issue