Enable Ruff SIM118 (#87772)
parent
2cdc741900
commit
9030ca05b1
|
@ -738,7 +738,7 @@ async def async_get_triggers(
|
|||
return []
|
||||
|
||||
triggers = []
|
||||
for trigger, subtype in REMOTES[device.model].keys():
|
||||
for trigger, subtype in REMOTES[device.model]:
|
||||
triggers.append(
|
||||
{
|
||||
CONF_DEVICE_ID: device_id,
|
||||
|
|
|
@ -20,10 +20,7 @@ async def async_setup_entry(
|
|||
][CONF_COORDINATOR]
|
||||
|
||||
async_add_entities(
|
||||
[
|
||||
FritzBoxTemplate(coordinator, ain)
|
||||
for ain in coordinator.data.templates.keys()
|
||||
]
|
||||
[FritzBoxTemplate(coordinator, ain) for ain in coordinator.data.templates]
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ class GoogleProvider(Provider):
|
|||
if language in MAP_LANG_TLD:
|
||||
tld = MAP_LANG_TLD[language].tld
|
||||
language = MAP_LANG_TLD[language].lang
|
||||
if options is not None and "tld" in options.keys():
|
||||
if options is not None and "tld" in options:
|
||||
tld = options["tld"]
|
||||
tts = gTTS(text=message, lang=language, tld=tld)
|
||||
mp3_data = BytesIO()
|
||||
|
|
|
@ -800,9 +800,7 @@ class GTFSDepartureSensor(SensorEntity):
|
|||
@staticmethod
|
||||
def dict_for_table(resource: Any) -> dict:
|
||||
"""Return a dictionary for the SQLAlchemy resource given."""
|
||||
return {
|
||||
col: getattr(resource, col) for col in resource.__table__.columns.keys()
|
||||
}
|
||||
return {col: getattr(resource, col) for col in resource.__table__.columns}
|
||||
|
||||
def append_keys(self, resource: dict, prefix: str | None = None) -> None:
|
||||
"""Properly format key val pairs to append to attributes."""
|
||||
|
|
|
@ -193,5 +193,5 @@ class HMThermostat(HMDevice, ClimateEntity):
|
|||
):
|
||||
self._data[HM_CONTROL_MODE] = None
|
||||
|
||||
for node in self._hmdevice.SENSORNODE.keys():
|
||||
for node in self._hmdevice.SENSORNODE:
|
||||
self._data[node] = None
|
||||
|
|
|
@ -63,9 +63,7 @@ class KrakenOptionsFlowHandler(config_entries.OptionsFlow):
|
|||
tradable_asset_pairs = await self.hass.async_add_executor_job(
|
||||
get_tradable_asset_pairs, api
|
||||
)
|
||||
tradable_asset_pairs_for_multi_select = {
|
||||
v: v for v in tradable_asset_pairs.keys()
|
||||
}
|
||||
tradable_asset_pairs_for_multi_select = {v: v for v in tradable_asset_pairs}
|
||||
options = {
|
||||
vol.Optional(
|
||||
CONF_SCAN_INTERVAL,
|
||||
|
|
|
@ -109,7 +109,7 @@ class SomaTilt(SomaEntity, CoverEntity):
|
|||
|
||||
api_position = int(response["position"])
|
||||
|
||||
if "closed_upwards" in response.keys():
|
||||
if "closed_upwards" in response:
|
||||
self.current_position = 50 + ((api_position * 50) / 100)
|
||||
else:
|
||||
self.current_position = 50 - ((api_position * 50) / 100)
|
||||
|
|
|
@ -389,9 +389,7 @@ class SpeechManager:
|
|||
if options is not None:
|
||||
supported_options = provider.supported_options or []
|
||||
invalid_opts = [
|
||||
opt_name
|
||||
for opt_name in options.keys()
|
||||
if opt_name not in supported_options
|
||||
opt_name for opt_name in options if opt_name not in supported_options
|
||||
]
|
||||
if invalid_opts:
|
||||
raise HomeAssistantError(f"Invalid options found: {invalid_opts}")
|
||||
|
|
|
@ -130,7 +130,7 @@ class UbusDeviceScanner(DeviceScanner):
|
|||
if result := self.ubus.get_hostapd_clients(hostapd):
|
||||
results = results + 1
|
||||
# Check for each device is authorized (valid wpa key)
|
||||
for key in result["clients"].keys():
|
||||
for key in result["clients"]:
|
||||
device = result["clients"][key]
|
||||
if device["authorized"]:
|
||||
self.last_results.append(key)
|
||||
|
|
|
@ -43,4 +43,4 @@ def extract_domain_configs(config: ConfigType, domain: str) -> Sequence[str]:
|
|||
Async friendly.
|
||||
"""
|
||||
pattern = re.compile(rf"^{domain}(| .+)$")
|
||||
return [key for key in config.keys() if pattern.match(key)]
|
||||
return [key for key in config if pattern.match(key)]
|
||||
|
|
|
@ -123,7 +123,7 @@ async def async_check_ha_config_file( # noqa: C901
|
|||
core_config.pop(CONF_PACKAGES, None)
|
||||
|
||||
# Filter out repeating config sections
|
||||
components = {key.partition(" ")[0] for key in config.keys()}
|
||||
components = {key.partition(" ")[0] for key in config}
|
||||
|
||||
# Process and validate config
|
||||
for domain in components:
|
||||
|
|
|
@ -537,7 +537,7 @@ def schema_with_slug_keys(
|
|||
if not isinstance(value, dict):
|
||||
raise vol.Invalid("expected dictionary")
|
||||
|
||||
for key in value.keys():
|
||||
for key in value:
|
||||
slug_validator(key)
|
||||
|
||||
return cast(dict, schema(value))
|
||||
|
|
|
@ -149,7 +149,7 @@ class SchemaCommonFlowHandler:
|
|||
and not self._handler.show_advanced_options
|
||||
):
|
||||
# Add advanced field default if not set
|
||||
for key in data_schema.schema.keys():
|
||||
for key in data_schema.schema:
|
||||
if isinstance(key, (vol.Optional, vol.Required)):
|
||||
if (
|
||||
key.description
|
||||
|
|
|
@ -166,7 +166,7 @@ def is_complex(value: Any) -> bool:
|
|||
if isinstance(value, list):
|
||||
return any(is_complex(val) for val in value)
|
||||
if isinstance(value, collections.abc.Mapping):
|
||||
return any(is_complex(val) for val in value.keys()) or any(
|
||||
return any(is_complex(val) for val in value) or any(
|
||||
is_complex(val) for val in value.values()
|
||||
)
|
||||
return False
|
||||
|
|
|
@ -249,6 +249,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
|
||||
"SIM118", # Use {key} in {dict} instead of {key} in {dict}.keys()
|
||||
"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
|
||||
|
|
|
@ -52,7 +52,7 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
|
|||
|
||||
def get_suggested(schema, key):
|
||||
"""Get suggested value for key in voluptuous schema."""
|
||||
for k in schema.keys():
|
||||
for k in schema:
|
||||
if k == key:
|
||||
if k.description is None or "suggested_value" not in k.description:
|
||||
return None
|
||||
|
|
|
@ -140,7 +140,7 @@ async def test_zeroconf_setup_onboarding(hass: HomeAssistant) -> None:
|
|||
|
||||
def get_suggested(schema, key):
|
||||
"""Get suggested value for key in voluptuous schema."""
|
||||
for k in schema.keys():
|
||||
for k in schema:
|
||||
if k == key:
|
||||
if k.description is None or "suggested_value" not in k.description:
|
||||
return None
|
||||
|
|
|
@ -111,7 +111,7 @@ async def test_send_simple_message(hass: HomeAssistant) -> None:
|
|||
|
||||
expected_content_type = "application/json"
|
||||
assert (
|
||||
"Content-Type" in mock.last_request.headers.keys()
|
||||
"Content-Type" in mock.last_request.headers
|
||||
and mock.last_request.headers["Content-Type"] == expected_content_type
|
||||
)
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
|
|||
|
||||
def get_suggested(schema, key):
|
||||
"""Get suggested value for key in voluptuous schema."""
|
||||
for k in schema.keys():
|
||||
for k in schema:
|
||||
if k == key:
|
||||
if k.description is None or "suggested_value" not in k.description:
|
||||
return None
|
||||
|
|
|
@ -170,7 +170,7 @@ async def test_config_flow_hides_members(
|
|||
|
||||
def get_suggested(schema, key):
|
||||
"""Get suggested value for key in voluptuous schema."""
|
||||
for k in schema.keys():
|
||||
for k in schema:
|
||||
if k == key:
|
||||
if k.description is None or "suggested_value" not in k.description:
|
||||
return None
|
||||
|
|
|
@ -805,12 +805,12 @@ async def test_emulated_color_temp_group(
|
|||
state = hass.states.get("light.test1")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes[ATTR_COLOR_TEMP] == 200
|
||||
assert ATTR_HS_COLOR in state.attributes.keys()
|
||||
assert ATTR_HS_COLOR in state.attributes
|
||||
|
||||
state = hass.states.get("light.test2")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes[ATTR_COLOR_TEMP] == 200
|
||||
assert ATTR_HS_COLOR in state.attributes.keys()
|
||||
assert ATTR_HS_COLOR in state.attributes
|
||||
|
||||
state = hass.states.get("light.test3")
|
||||
assert state.state == STATE_ON
|
||||
|
|
|
@ -52,11 +52,11 @@ async def test_async_callbacks(hass: HomeAssistant) -> None:
|
|||
_call_all_callbacks(subscriber)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
for callback_name in _NO_PARAM_CALLBACKS.keys():
|
||||
for callback_name in _NO_PARAM_CALLBACKS:
|
||||
callback_mock = callbacks[callback_name]
|
||||
callback_mock.assert_awaited_once()
|
||||
|
||||
for callback_name in _ACTIVITY_CALLBACKS.keys():
|
||||
for callback_name in _ACTIVITY_CALLBACKS:
|
||||
callback_mock = callbacks[callback_name]
|
||||
callback_mock.assert_awaited_once_with(_ACTIVITY_TUPLE)
|
||||
|
||||
|
@ -96,11 +96,11 @@ async def test_callbacks(hass: HomeAssistant) -> None:
|
|||
_call_all_callbacks(subscriber)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
for callback_name in _NO_PARAM_CALLBACKS.keys():
|
||||
for callback_name in _NO_PARAM_CALLBACKS:
|
||||
callback_mock = callbacks[callback_name]
|
||||
callback_mock.assert_called_once()
|
||||
|
||||
for callback_name in _ACTIVITY_CALLBACKS.keys():
|
||||
for callback_name in _ACTIVITY_CALLBACKS:
|
||||
callback_mock = callbacks[callback_name]
|
||||
callback_mock.assert_called_once_with(_ACTIVITY_TUPLE)
|
||||
|
||||
|
@ -122,12 +122,12 @@ async def test_subscribe_unsubscribe(hass: HomeAssistant) -> None:
|
|||
_call_all_callbacks(subscriber)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
for callback_name in _NO_PARAM_CALLBACKS.keys():
|
||||
for callback_name in _NO_PARAM_CALLBACKS:
|
||||
callback_one[callback_name].assert_not_called()
|
||||
callback_two[callback_name].assert_called_once()
|
||||
callback_three[callback_name].assert_not_called()
|
||||
|
||||
for callback_name in _ACTIVITY_CALLBACKS.keys():
|
||||
for callback_name in _ACTIVITY_CALLBACKS:
|
||||
callback_one[callback_name].assert_not_called()
|
||||
callback_two[callback_name].assert_called_once_with(_ACTIVITY_TUPLE)
|
||||
callback_three[callback_name].assert_not_called()
|
||||
|
|
|
@ -67,7 +67,7 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
|
|||
|
||||
def get_suggested(schema, key):
|
||||
"""Get suggested value for key in voluptuous schema."""
|
||||
for k in schema.keys():
|
||||
for k in schema:
|
||||
if k == key:
|
||||
if k.description is None or "suggested_value" not in k.description:
|
||||
return None
|
||||
|
|
|
@ -56,7 +56,7 @@ async def test_config_flow(hass: HomeAssistant, platform: str) -> None:
|
|||
|
||||
def get_suggested(schema, key):
|
||||
"""Get suggested value for key in voluptuous schema."""
|
||||
for k in schema.keys():
|
||||
for k in schema:
|
||||
if k == key:
|
||||
if k.description is None or "suggested_value" not in k.description:
|
||||
return None
|
||||
|
|
|
@ -82,7 +82,7 @@ async def mock_modbus_fixture(
|
|||
):
|
||||
"""Load integration modbus using mocked pymodbus."""
|
||||
conf = copy.deepcopy(do_config)
|
||||
for key in conf.keys():
|
||||
for key in conf:
|
||||
if config_addon:
|
||||
conf[key][0].update(config_addon)
|
||||
for entity in conf[key]:
|
||||
|
|
|
@ -843,7 +843,7 @@ async def test_invalid_discovery_prefix(
|
|||
|
||||
def get_default(schema: vol.Schema, key: str) -> Any:
|
||||
"""Get default value for key in voluptuous schema."""
|
||||
for schema_key in schema.keys():
|
||||
for schema_key in schema:
|
||||
if schema_key == key:
|
||||
if schema_key.default == vol.UNDEFINED:
|
||||
return None
|
||||
|
@ -852,7 +852,7 @@ def get_default(schema: vol.Schema, key: str) -> Any:
|
|||
|
||||
def get_suggested(schema: vol.Schema, key: str) -> Any:
|
||||
"""Get suggested value for key in voluptuous schema."""
|
||||
for schema_key in schema.keys():
|
||||
for schema_key in schema:
|
||||
if schema_key == key:
|
||||
if (
|
||||
schema_key.description is None
|
||||
|
|
|
@ -26,7 +26,7 @@ async def test_mapping_integrity() -> None:
|
|||
for capability, attrib in binary_sensor.CAPABILITY_TO_ATTRIB.items():
|
||||
assert capability in CAPABILITIES, capability
|
||||
assert attrib in ATTRIBUTES, attrib
|
||||
assert attrib in binary_sensor.ATTRIB_TO_CLASS.keys(), attrib
|
||||
assert attrib in binary_sensor.ATTRIB_TO_CLASS, attrib
|
||||
# Ensure every ATTRIB_TO_CLASS value is in DEVICE_CLASSES
|
||||
for attrib, device_class in binary_sensor.ATTRIB_TO_CLASS.items():
|
||||
assert attrib in ATTRIBUTES, attrib
|
||||
|
|
|
@ -86,7 +86,7 @@ async def test_fail(hass: HomeAssistant, extra_input_data, error) -> None:
|
|||
|
||||
def get_suggested(schema, key):
|
||||
"""Get suggested value for key in voluptuous schema."""
|
||||
for k in schema.keys():
|
||||
for k in schema:
|
||||
if k == key:
|
||||
if k.description is None or "suggested_value" not in k.description:
|
||||
return None
|
||||
|
|
|
@ -57,7 +57,7 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
|
|||
|
||||
def get_suggested(schema, key):
|
||||
"""Get suggested value for key in voluptuous schema."""
|
||||
for k in schema.keys():
|
||||
for k in schema:
|
||||
if k == key:
|
||||
if k.description is None or "suggested_value" not in k.description:
|
||||
return None
|
||||
|
|
|
@ -138,7 +138,7 @@ async def test_tariffs(hass: HomeAssistant) -> None:
|
|||
|
||||
def get_suggested(schema, key):
|
||||
"""Get suggested value for key in voluptuous schema."""
|
||||
for k in schema.keys():
|
||||
for k in schema:
|
||||
if k == key:
|
||||
if k.description is None or "suggested_value" not in k.description:
|
||||
return None
|
||||
|
|
Loading…
Reference in New Issue