Enable some PERF rules (#112498)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
Joost Lekkerkerker 2024-03-06 17:50:41 +01:00 committed by GitHub
parent 656ef143da
commit c8f39911cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 12 additions and 12 deletions

View file

@ -145,7 +145,7 @@ def add_insteon_events(hass: HomeAssistant, device: Device) -> None:
for name_or_group, event in device.events.items():
if isinstance(name_or_group, int):
for _, event in device.events[name_or_group].items():
for event in device.events[name_or_group].values():
_register_event(event, async_fire_insteon_event)
else:
_register_event(event, async_fire_insteon_event)

View file

@ -21,7 +21,7 @@ def redact_matter_attributes(node_data: dict[str, Any]) -> dict[str, Any]:
"""Redact Matter cluster attribute."""
redacted = deepcopy(node_data)
for attribute_to_redact in ATTRIBUTES_TO_REDACT:
for attribute_path, _value in redacted["attributes"].items():
for attribute_path in redacted["attributes"]:
_, cluster_id, attribute_id = parse_attribute_path(attribute_path)
if cluster_id != attribute_to_redact.cluster_id:
continue

View file

@ -429,7 +429,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
]
await asyncio.gather(*tasks)
for _, component in mqtt_data.reload_handlers.items():
for component in mqtt_data.reload_handlers.values():
component()
# Fire event

View file

@ -259,7 +259,7 @@ class PrometheusMetrics:
self, entity_id: str, friendly_name: str | None = None
) -> None:
"""Remove labelsets matching the given entity id from all metrics."""
for _, metric in self._metrics.items():
for metric in self._metrics.values():
for sample in cast(list[prometheus_client.Metric], metric.collect())[
0
].samples:

View file

@ -57,7 +57,7 @@ def get_all_network_interfaces(hass: HomeAssistant) -> set[str]:
"""Return all network interfaces on system."""
psutil_wrapper: ha_psutil = hass.data[DOMAIN]
interfaces: set[str] = set()
for interface, _ in psutil_wrapper.psutil.net_if_addrs().items():
for interface in psutil_wrapper.psutil.net_if_addrs():
if interface.startswith("veth"):
# Don't load docker virtual network interfaces
continue

View file

@ -26,10 +26,7 @@ async def async_setup_entry(
"""Set up Velbus switch based on config_entry."""
await hass.data[DOMAIN][entry.entry_id]["tsk"]
cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
entities = []
for channel in cntrl.get_all("cover"):
entities.append(VelbusCover(channel))
async_add_entities(entities)
async_add_entities(VelbusCover(channel) for channel in cntrl.get_all("cover"))
class VelbusCover(VelbusEntity, CoverEntity):

View file

@ -600,6 +600,9 @@ select = [
"N804", # First argument of a class method should be named cls
"N805", # First argument of a method should be named self
"N815", # Variable {name} in class scope should not be mixedCase
"PERF101", # Do not cast an iterable to list before iterating over it
"PERF102", # When using only the {subset} of a dict use the {subset}() method
"PERF203", # try-except within a loop incurs performance overhead
"PGH004", # Use specific rule codes when using noqa
"PLC0414", # Useless import alias. Import alias does not rename original package.
"PLC", # pylint

View file

@ -402,7 +402,7 @@ async def test_multiple_observations(hass: HomeAssistant) -> None:
state = hass.states.get("binary_sensor.test_binary")
for _, attrs in state.attributes.items():
for attrs in state.attributes.values():
json.dumps(attrs)
assert state.attributes.get("occurred_observation_entities") == []
assert state.attributes.get("probability") == 0.2
@ -474,7 +474,7 @@ async def test_multiple_numeric_observations(hass: HomeAssistant) -> None:
state = hass.states.get("binary_sensor.test_binary")
for _, attrs in state.attributes.items():
for attrs in state.attributes.values():
json.dumps(attrs)
assert state.attributes.get("occurred_observation_entities") == []
assert state.attributes.get("probability") == 0.1
@ -782,7 +782,7 @@ async def test_state_attributes_are_serializable(hass: HomeAssistant) -> None:
state.attributes.get("occurred_observation_entities")
)
for _, attrs in state.attributes.items():
for attrs in state.attributes.values():
json.dumps(attrs)