diff --git a/homeassistant/components/fronius/config_flow.py b/homeassistant/components/fronius/config_flow.py index 22bfc4a67f4..2b46d226b7a 100644 --- a/homeassistant/components/fronius/config_flow.py +++ b/homeassistant/components/fronius/config_flow.py @@ -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, ): diff --git a/homeassistant/components/roomba/config_flow.py b/homeassistant/components/roomba/config_flow.py index 08973b415ee..7b834421135 100644 --- a/homeassistant/components/roomba/config_flow.py +++ b/homeassistant/components/roomba/config_flow.py @@ -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( diff --git a/pyproject.toml b/pyproject.toml index bc5c3c53b85..6cfd01a7c7e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/tests/components/alexa/test_state_report.py b/tests/components/alexa/test_state_report.py index c851b7991ac..6bd7caccc38 100644 --- a/tests/components/alexa/test_state_report.py +++ b/tests/components/alexa/test_state_report.py @@ -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}", diff --git a/tests/components/bluetooth/test_wrappers.py b/tests/components/bluetooth/test_wrappers.py index 9a191cdbf90..1fc42ebf187 100644 --- a/tests/components/bluetooth/test_wrappers.py +++ b/tests/components/bluetooth/test_wrappers.py @@ -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() diff --git a/tests/components/esphome/bluetooth/test_client.py b/tests/components/esphome/bluetooth/test_client.py index 2898ae2bda2..98993be37d0 100644 --- a/tests/components/esphome/bluetooth/test_client.py +++ b/tests/components/esphome/bluetooth/test_client.py @@ -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 diff --git a/tests/components/evil_genius_labs/test_light.py b/tests/components/evil_genius_labs/test_light.py index cbc68ccf2d7..e0ecb5415a7 100644 --- a/tests/components/evil_genius_labs/test_light.py +++ b/tests/components/evil_genius_labs/test_light.py @@ -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) diff --git a/tests/components/google/test_init.py b/tests/components/google/test_init.py index c51ecf593e3..319f6be5012 100644 --- a/tests/components/google/test_init.py +++ b/tests/components/google/test_init.py @@ -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 diff --git a/tests/components/homeassistant_hardware/test_silabs_multiprotocol_addon.py b/tests/components/homeassistant_hardware/test_silabs_multiprotocol_addon.py index 6d1efc79df4..6221ac3ecb5 100644 --- a/tests/components/homeassistant_hardware/test_silabs_multiprotocol_addon.py +++ b/tests/components/homeassistant_hardware/test_silabs_multiprotocol_addon.py @@ -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 + ) diff --git a/tests/components/media_player/test_browse_media.py b/tests/components/media_player/test_browse_media.py index 8c5554793a6..e3c5614d815 100644 --- a/tests/components/media_player/test_browse_media.py +++ b/tests/components/media_player/test_browse_media.py @@ -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( diff --git a/tests/components/recorder/test_init.py b/tests/components/recorder/test_init.py index 96814da5171..238f6420c78 100644 --- a/tests/components/recorder/test_init.py +++ b/tests/components/recorder/test_init.py @@ -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" diff --git a/tests/components/withings/test_init.py b/tests/components/withings/test_init.py index 4caf83bef91..e5fa2dcb9fd 100644 --- a/tests/components/withings/test_init.py +++ b/tests/components/withings/test_init.py @@ -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) diff --git a/tests/components/zha/test_gateway.py b/tests/components/zha/test_gateway.py index 5ae1cc0e7e5..182cc2c4752 100644 --- a/tests/components/zha/test_gateway.py +++ b/tests/components/zha/test_gateway.py @@ -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() diff --git a/tests/components/zha/test_websocket_api.py b/tests/components/zha/test_websocket_api.py index 041329123f8..73dc63258b6 100644 --- a/tests/components/zha/test_websocket_api.py +++ b/tests/components/zha/test_websocket_api.py @@ -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( diff --git a/tests/helpers/test_aiohttp_client.py b/tests/helpers/test_aiohttp_client.py index 7ec4e996629..73339e9fe3c 100644 --- a/tests/helpers/test_aiohttp_client.py +++ b/tests/helpers/test_aiohttp_client.py @@ -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: