Enable Ruff SIM300 (#86793)

This commit is contained in:
Franck Nijhof 2023-01-30 11:03:23 +01:00 committed by GitHub
parent 9ac8f9aa37
commit c56832bb2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 43 additions and 42 deletions

View file

@ -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 (

View file

@ -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:

View file

@ -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"

View file

@ -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

View file

@ -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:

View file

@ -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

View file

@ -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 (

View file

@ -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()

View file

@ -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

View file

@ -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

View file

@ -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):

View file

@ -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"

View file

@ -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]

View file

@ -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):

View file

@ -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

View file

@ -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

View file

@ -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):

View file

@ -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)

View file

@ -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")

View file

@ -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

View file

@ -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")

View file

@ -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)

View file

@ -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")

View file

@ -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()

View file

@ -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():