From c56832bb2c18a7aec242f01f7e34222765022fbb Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Mon, 30 Jan 2023 11:03:23 +0100 Subject: [PATCH] Enable Ruff SIM300 (#86793) --- homeassistant/components/cloud/account_link.py | 2 +- homeassistant/components/deconz/config_flow.py | 2 +- homeassistant/components/github/__init__.py | 2 +- homeassistant/components/horizon/media_player.py | 2 +- homeassistant/components/onvif/config_flow.py | 2 +- homeassistant/components/tuya/__init__.py | 2 +- homeassistant/components/webostv/media_player.py | 2 +- homeassistant/components/zha/binary_sensor.py | 2 +- pyproject.toml | 1 + tests/components/automation/test_init.py | 4 ++-- tests/components/cast/test_media_player.py | 2 +- tests/components/ecobee/test_climate.py | 2 +- tests/components/emulated_hue/test_hue_api.py | 4 ++-- .../components/generic_hygrostat/test_humidifier.py | 8 ++++---- tests/components/hyperion/test_light.py | 2 +- tests/components/melissa/test_climate.py | 2 +- tests/components/mfi/test_sensor.py | 8 ++++---- tests/components/min_max/test_sensor.py | 4 ++-- tests/components/remember_the_milk/test_init.py | 2 +- tests/components/script/test_init.py | 12 ++++++------ tests/components/shell_command/test_init.py | 2 +- tests/components/sun/test_init.py | 10 +++++----- tests/components/todoist/test_calendar.py | 2 +- tests/components/vultr/test_sensor.py | 2 +- tests/util/test_color.py | 2 +- 25 files changed, 43 insertions(+), 42 deletions(-) diff --git a/homeassistant/components/cloud/account_link.py b/homeassistant/components/cloud/account_link.py index 3cf021c24fe..e3b3c1231bb 100644 --- a/homeassistant/components/cloud/account_link.py +++ b/homeassistant/components/cloud/account_link.py @@ -38,7 +38,7 @@ async def async_provide_implementation(hass: HomeAssistant, domain: str): for service in services: if ( service["service"] == domain - and CURRENT_PLAIN_VERSION >= service["min_version"] + and service["min_version"] <= CURRENT_PLAIN_VERSION and ( service.get("accepts_new_authorizations", True) or ( diff --git a/homeassistant/components/deconz/config_flow.py b/homeassistant/components/deconz/config_flow.py index d94b40e8525..569f13666df 100644 --- a/homeassistant/components/deconz/config_flow.py +++ b/homeassistant/components/deconz/config_flow.py @@ -88,7 +88,7 @@ class DeconzFlowHandler(ConfigFlow, domain=DOMAIN): """ if user_input is not None: - if CONF_MANUAL_INPUT == user_input[CONF_HOST]: + if user_input[CONF_HOST] == CONF_MANUAL_INPUT: return await self.async_step_manual_input() for bridge in self.bridges: diff --git a/homeassistant/components/github/__init__.py b/homeassistant/components/github/__init__.py index 1ce5d7df0ce..725c319dd58 100644 --- a/homeassistant/components/github/__init__.py +++ b/homeassistant/components/github/__init__.py @@ -64,7 +64,7 @@ def async_cleanup_device_registry( ) for device in devices: for item in device.identifiers: - if DOMAIN == item[0] and item[1] not in entry.options[CONF_REPOSITORIES]: + if item[0] == DOMAIN and item[1] not in entry.options[CONF_REPOSITORIES]: LOGGER.debug( ( "Unlinking device %s for untracked repository %s from config" diff --git a/homeassistant/components/horizon/media_player.py b/homeassistant/components/horizon/media_player.py index 680d2982f9f..3a05f09501f 100644 --- a/homeassistant/components/horizon/media_player.py +++ b/homeassistant/components/horizon/media_player.py @@ -144,7 +144,7 @@ class HorizonDevice(MediaPlayerEntity): def play_media(self, media_type: str, media_id: str, **kwargs: Any) -> None: """Play media / switch to channel.""" - if MediaType.CHANNEL == media_type: + if media_type == MediaType.CHANNEL: try: self._select_channel(int(media_id)) self._attr_state = MediaPlayerState.PLAYING diff --git a/homeassistant/components/onvif/config_flow.py b/homeassistant/components/onvif/config_flow.py index a0dd77df53a..b4227b0cfa3 100644 --- a/homeassistant/components/onvif/config_flow.py +++ b/homeassistant/components/onvif/config_flow.py @@ -109,7 +109,7 @@ class OnvifFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): """ if user_input: - if CONF_MANUAL_INPUT == user_input[CONF_HOST]: + if user_input[CONF_HOST] == CONF_MANUAL_INPUT: return await self.async_step_configure() for device in self.devices: diff --git a/homeassistant/components/tuya/__init__.py b/homeassistant/components/tuya/__init__.py index 9f25cfe7773..2b28a7e4e5e 100644 --- a/homeassistant/components/tuya/__init__.py +++ b/homeassistant/components/tuya/__init__.py @@ -134,7 +134,7 @@ async def cleanup_device_registry( device_registry = dr.async_get(hass) for dev_id, device_entry in list(device_registry.devices.items()): for item in device_entry.identifiers: - if DOMAIN == item[0] and item[1] not in device_manager.device_map: + if item[0] == DOMAIN and item[1] not in device_manager.device_map: device_registry.async_remove_device(dev_id) break diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index d7eb306ef3c..06e7e202b36 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -296,7 +296,7 @@ class LgWebOSMediaPlayerEntity(RestoreEntity, MediaPlayerEntity): # not appear in the app or input lists in some cases elif not found_live_tv: app = {"id": LIVE_TV_APP_ID, "title": "Live TV"} - if LIVE_TV_APP_ID == self._client.current_app_id: + if self._client.current_app_id == LIVE_TV_APP_ID: self._current_source = app["title"] self._source_list["Live TV"] = app elif ( diff --git a/homeassistant/components/zha/binary_sensor.py b/homeassistant/components/zha/binary_sensor.py index 1250e3c92a7..af7ce6b5bf7 100644 --- a/homeassistant/components/zha/binary_sensor.py +++ b/homeassistant/components/zha/binary_sensor.py @@ -92,7 +92,7 @@ class BinarySensor(ZhaEntity, BinarySensorEntity): @callback def async_set_state(self, attr_id, attr_name, value): """Set the state.""" - if self.SENSOR_ATTR is None or self.SENSOR_ATTR != attr_name: + if self.SENSOR_ATTR is None or attr_name != self.SENSOR_ATTR: return self._state = bool(value) self.async_write_ha_state() diff --git a/pyproject.toml b/pyproject.toml index baebe35a57a..968bdb1fc83 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -253,6 +253,7 @@ select = [ "PLC0414", # Useless import alias. Import alias does not rename original package. "SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass "SIM117", # Merge with-statements that use the same scope + "SIM300", # Yoda conditions. Use 'age == 42' instead of '42 == age'. "SIM401", # Use get from dict with default instead of an if block "T20", # flake8-print "UP", # pyupgrade diff --git a/tests/components/automation/test_init.py b/tests/components/automation/test_init.py index 6f6b0df5814..d5e6cc0458d 100644 --- a/tests/components/automation/test_init.py +++ b/tests/components/automation/test_init.py @@ -2180,12 +2180,12 @@ async def test_recursive_automation_starting_script( # Fail if additional script modes are added to # make sure we cover all script modes in tests - assert SCRIPT_MODE_CHOICES == [ + assert [ SCRIPT_MODE_PARALLEL, SCRIPT_MODE_QUEUED, SCRIPT_MODE_RESTART, SCRIPT_MODE_SINGLE, - ] + ] == SCRIPT_MODE_CHOICES stop_scripts_at_shutdown_called = asyncio.Event() real_stop_scripts_at_shutdown = _async_stop_scripts_at_shutdown diff --git a/tests/components/cast/test_media_player.py b/tests/components/cast/test_media_player.py index 74ecd4a36fd..7954d0e1713 100644 --- a/tests/components/cast/test_media_player.py +++ b/tests/components/cast/test_media_player.py @@ -1986,7 +1986,7 @@ async def test_entry_setup_single_config(hass: HomeAssistant): assert config_entry.data["uuid"] == ["bla"] assert config_entry.data["ignore_cec"] == ["cast1"] - assert pychromecast.IGNORE_CEC == ["cast1"] + assert ["cast1"] == pychromecast.IGNORE_CEC async def test_entry_setup_list_config(hass: HomeAssistant): diff --git a/tests/components/ecobee/test_climate.py b/tests/components/ecobee/test_climate.py index da4cc6cf455..8b3dbdf0809 100644 --- a/tests/components/ecobee/test_climate.py +++ b/tests/components/ecobee/test_climate.py @@ -119,7 +119,7 @@ async def test_desired_fan_mode(ecobee_fixture, thermostat): async def test_fan(ecobee_fixture, thermostat): """Test fan property.""" - assert const.STATE_ON == thermostat.fan + assert thermostat.fan == const.STATE_ON ecobee_fixture["equipmentStatus"] = "" assert thermostat.fan == STATE_OFF ecobee_fixture["equipmentStatus"] = "heatPump, heatPump2" diff --git a/tests/components/emulated_hue/test_hue_api.py b/tests/components/emulated_hue/test_hue_api.py index 58303ce54a6..cecc267c5b0 100644 --- a/tests/components/emulated_hue/test_hue_api.py +++ b/tests/components/emulated_hue/test_hue_api.py @@ -379,7 +379,7 @@ async def test_light_without_brightness_can_be_turned_off(hass_hue, hue_client): assert len(turn_off_calls) == 1 call = turn_off_calls[-1] - assert light.DOMAIN == call.domain + assert call.domain == light.DOMAIN assert call.service == SERVICE_TURN_OFF assert "light.no_brightness" in call.data[ATTR_ENTITY_ID] @@ -421,7 +421,7 @@ async def test_light_without_brightness_can_be_turned_on(hass_hue, hue_client): assert len(turn_on_calls) == 1 call = turn_on_calls[-1] - assert light.DOMAIN == call.domain + assert call.domain == light.DOMAIN assert call.service == SERVICE_TURN_ON assert "light.no_brightness" in call.data[ATTR_ENTITY_ID] diff --git a/tests/components/generic_hygrostat/test_humidifier.py b/tests/components/generic_hygrostat/test_humidifier.py index 3d7c31002ba..4b6b9e4bb2a 100644 --- a/tests/components/generic_hygrostat/test_humidifier.py +++ b/tests/components/generic_hygrostat/test_humidifier.py @@ -687,11 +687,11 @@ async def test_init_ignores_tolerance(hass, setup_comp_3): calls = await _setup_switch(hass, True) _setup_sensor(hass, 39) await hass.async_block_till_done() - assert 1 == len(calls) + assert len(calls) == 1 call = calls[0] - assert HASS_DOMAIN == call.domain - assert SERVICE_TURN_OFF == call.service - assert ENT_SWITCH == call.data["entity_id"] + assert call.domain == HASS_DOMAIN + assert call.service == SERVICE_TURN_OFF + assert call.data["entity_id"] == ENT_SWITCH async def test_humidity_change_dry_off_within_tolerance(hass, setup_comp_3): diff --git a/tests/components/hyperion/test_light.py b/tests/components/hyperion/test_light.py index 136a67f0dba..31b2f100858 100644 --- a/tests/components/hyperion/test_light.py +++ b/tests/components/hyperion/test_light.py @@ -79,7 +79,7 @@ def _get_config_entry_from_unique_id( hass: HomeAssistant, unique_id: str ) -> ConfigEntry | None: for entry in hass.config_entries.async_entries(domain=DOMAIN): - if TEST_SYSINFO_ID == entry.unique_id: + if entry.unique_id == TEST_SYSINFO_ID: return entry return None diff --git a/tests/components/melissa/test_climate.py b/tests/components/melissa/test_climate.py index 11bb663b372..97d63a8212a 100644 --- a/tests/components/melissa/test_climate.py +++ b/tests/components/melissa/test_climate.py @@ -279,7 +279,7 @@ async def test_send(hass): thermostat._cur_settings = None await thermostat.async_send({"fan": api.FAN_LOW}) await hass.async_block_till_done() - assert FAN_LOW != thermostat.fan_mode + assert thermostat.fan_mode != FAN_LOW assert thermostat._cur_settings is None diff --git a/tests/components/mfi/test_sensor.py b/tests/components/mfi/test_sensor.py index 771d97a7327..16d6eb8480f 100644 --- a/tests/components/mfi/test_sensor.py +++ b/tests/components/mfi/test_sensor.py @@ -170,11 +170,11 @@ async def test_state_digital(port, sensor): """Test the digital input.""" port.model = "Input Digital" port.value = 0 - assert mfi.STATE_OFF == sensor.state + assert sensor.state == mfi.STATE_OFF port.value = 1 - assert mfi.STATE_ON == sensor.state + assert sensor.state == mfi.STATE_ON port.value = 2 - assert mfi.STATE_ON == sensor.state + assert sensor.state == mfi.STATE_ON async def test_state_digits(port, sensor): @@ -190,7 +190,7 @@ async def test_state_digits(port, sensor): async def test_state_uninitialized(port, sensor): """Test the state of uninitialized sensorfs.""" type(port).tag = mock.PropertyMock(side_effect=ValueError) - assert mfi.STATE_OFF == sensor.state + assert sensor.state == mfi.STATE_OFF async def test_update(port, sensor): diff --git a/tests/components/min_max/test_sensor.py b/tests/components/min_max/test_sensor.py index ad7f4025c7e..a742260daff 100644 --- a/tests/components/min_max/test_sensor.py +++ b/tests/components/min_max/test_sensor.py @@ -306,14 +306,14 @@ async def test_not_enough_sensor_value(hass: HomeAssistant) -> None: await hass.async_block_till_done() state = hass.states.get("sensor.test_max") - assert STATE_UNKNOWN != state.state + assert state.state != STATE_UNKNOWN assert entity_ids[1] == state.attributes.get("max_entity_id") hass.states.async_set(entity_ids[2], STATE_UNKNOWN) await hass.async_block_till_done() state = hass.states.get("sensor.test_max") - assert STATE_UNKNOWN != state.state + assert state.state != STATE_UNKNOWN assert entity_ids[1] == state.attributes.get("max_entity_id") hass.states.async_set(entity_ids[1], STATE_UNAVAILABLE) diff --git a/tests/components/remember_the_milk/test_init.py b/tests/components/remember_the_milk/test_init.py index 2f3511aeaa8..9d463165819 100644 --- a/tests/components/remember_the_milk/test_init.py +++ b/tests/components/remember_the_milk/test_init.py @@ -58,4 +58,4 @@ def test_load_key_map(hass): "os.path.isfile", Mock(return_value=True) ): config = rtm.RememberTheMilkConfiguration(hass) - assert ("0", "1", "2") == config.get_rtm_id(PROFILE, "1234") + assert config.get_rtm_id(PROFILE, "1234") == ("0", "1", "2") diff --git a/tests/components/script/test_init.py b/tests/components/script/test_init.py index 0c42b46059f..aebd0d809fb 100644 --- a/tests/components/script/test_init.py +++ b/tests/components/script/test_init.py @@ -1005,12 +1005,12 @@ async def test_script_restore_last_triggered(hass: HomeAssistant) -> None: async def test_recursive_script(hass, script_mode, warning_msg, caplog): """Test recursive script calls does not deadlock.""" # Make sure we cover all script modes - assert SCRIPT_MODE_CHOICES == [ + assert [ SCRIPT_MODE_PARALLEL, SCRIPT_MODE_QUEUED, SCRIPT_MODE_RESTART, SCRIPT_MODE_SINGLE, - ] + ] == SCRIPT_MODE_CHOICES assert await async_setup_component( hass, @@ -1053,12 +1053,12 @@ async def test_recursive_script(hass, script_mode, warning_msg, caplog): async def test_recursive_script_indirect(hass, script_mode, warning_msg, caplog): """Test recursive script calls does not deadlock.""" # Make sure we cover all script modes - assert SCRIPT_MODE_CHOICES == [ + assert [ SCRIPT_MODE_PARALLEL, SCRIPT_MODE_QUEUED, SCRIPT_MODE_RESTART, SCRIPT_MODE_SINGLE, - ] + ] == SCRIPT_MODE_CHOICES assert await async_setup_component( hass, @@ -1118,12 +1118,12 @@ async def test_recursive_script_turn_on(hass: HomeAssistant, script_mode, caplog - SCRIPT_MODE_SINGLE is not relevant because suca script can't turn itself on """ # Make sure we cover all script modes - assert SCRIPT_MODE_CHOICES == [ + assert [ SCRIPT_MODE_PARALLEL, SCRIPT_MODE_QUEUED, SCRIPT_MODE_RESTART, SCRIPT_MODE_SINGLE, - ] + ] == SCRIPT_MODE_CHOICES stop_scripts_at_shutdown_called = asyncio.Event() real_stop_scripts_at_shutdown = _async_stop_scripts_at_shutdown diff --git a/tests/components/shell_command/test_init.py b/tests/components/shell_command/test_init.py index 196e47351bc..437afb490dc 100644 --- a/tests/components/shell_command/test_init.py +++ b/tests/components/shell_command/test_init.py @@ -102,7 +102,7 @@ async def test_template_render(mock_call, hass): cmd = mock_call.mock_calls[0][1] assert mock_call.call_count == 1 - assert ("ls", "/bin", "Works") == cmd + assert cmd == ("ls", "/bin", "Works") @patch("homeassistant.components.shell_command.asyncio.create_subprocess_shell") diff --git a/tests/components/sun/test_init.py b/tests/components/sun/test_init.py index a5a09cb4655..522f3691fbc 100644 --- a/tests/components/sun/test_init.py +++ b/tests/components/sun/test_init.py @@ -119,21 +119,21 @@ async def test_state_change(hass, caplog): ) assert test_time is not None - assert sun.STATE_BELOW_HORIZON == hass.states.get(sun.ENTITY_ID).state + assert hass.states.get(sun.ENTITY_ID).state == sun.STATE_BELOW_HORIZON patched_time = test_time + timedelta(seconds=5) with freeze_time(patched_time): async_fire_time_changed(hass, patched_time) await hass.async_block_till_done() - assert sun.STATE_ABOVE_HORIZON == hass.states.get(sun.ENTITY_ID).state + assert hass.states.get(sun.ENTITY_ID).state == sun.STATE_ABOVE_HORIZON # Update core configuration with patch("homeassistant.helpers.condition.dt_util.utcnow", return_value=now): await hass.config.async_update(longitude=hass.config.longitude + 90) await hass.async_block_till_done() - assert sun.STATE_ABOVE_HORIZON == hass.states.get(sun.ENTITY_ID).state + assert hass.states.get(sun.ENTITY_ID).state == sun.STATE_ABOVE_HORIZON # Test listeners are not duplicated after a core configuration change test_time = dt_util.parse_datetime( @@ -152,7 +152,7 @@ async def test_state_change(hass, caplog): # Called once by time listener, once from Sun.update_events assert caplog.text.count("sun position_update") == 2 - assert sun.STATE_BELOW_HORIZON == hass.states.get(sun.ENTITY_ID).state + assert hass.states.get(sun.ENTITY_ID).state == sun.STATE_BELOW_HORIZON async def test_norway_in_june(hass): @@ -227,7 +227,7 @@ async def test_setup_and_remove_config_entry(hass: ha.HomeAssistant) -> None: hass.states.get(sun.ENTITY_ID).attributes[sun.STATE_ATTR_NEXT_RISING] ) assert test_time is not None - assert sun.STATE_BELOW_HORIZON == hass.states.get(sun.ENTITY_ID).state + assert hass.states.get(sun.ENTITY_ID).state == sun.STATE_BELOW_HORIZON # Remove the config entry assert await hass.config_entries.async_remove(config_entry.entry_id) diff --git a/tests/components/todoist/test_calendar.py b/tests/components/todoist/test_calendar.py index 3ec587b5e8b..139b36bd254 100644 --- a/tests/components/todoist/test_calendar.py +++ b/tests/components/todoist/test_calendar.py @@ -80,7 +80,7 @@ async def test_calendar_entity_unique_id(todoist_api, hass, api): registry = entity_registry.async_get(hass) entity = registry.async_get("calendar.name") - assert "12345" == entity.unique_id + assert entity.unique_id == "12345" @patch("homeassistant.components.todoist.calendar.TodoistAPIAsync") diff --git a/tests/components/vultr/test_sensor.py b/tests/components/vultr/test_sensor.py index 95f91270fa9..f3b21bd446b 100644 --- a/tests/components/vultr/test_sensor.py +++ b/tests/components/vultr/test_sensor.py @@ -54,7 +54,7 @@ def test_sensor(hass: HomeAssistant): # Test pre update if device.subscription == "576965": - assert vultr.DEFAULT_NAME == device.name + assert device.name == vultr.DEFAULT_NAME device.update() diff --git a/tests/util/test_color.py b/tests/util/test_color.py index 95d2ffc0fd7..ad4b73274e8 100644 --- a/tests/util/test_color.py +++ b/tests/util/test_color.py @@ -341,7 +341,7 @@ def test_should_return_pure_white_at_6600(): guess" approach. """ rgb = color_util.color_temperature_to_rgb(6600) - assert (255, 255, 255) == rgb + assert rgb == (255, 255, 255) def test_color_above_6600_should_have_more_blue_than_red_or_green():