Add ruff rule PIE804 (#113620)

Co-authored-by: J. Nick Koston <nick@koston.org>
pull/113632/head
Sid 2024-03-16 23:45:18 +01:00 committed by GitHub
parent d0352ed91d
commit fe9cc6705c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 64 additions and 91 deletions

View File

@ -26,7 +26,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
client = GitHubAPI(
token=entry.data[CONF_ACCESS_TOKEN],
session=async_get_clientsession(hass),
**{"client_name": SERVER_SOFTWARE},
client_name=SERVER_SOFTWARE,
)
repositories: list[str] = entry.options[CONF_REPOSITORIES]

View File

@ -38,12 +38,12 @@ async def get_repositories(hass: HomeAssistant, access_token: str) -> list[str]:
repositories = set()
async def _get_starred_repositories() -> None:
response = await client.user.starred(**{"params": {"per_page": 100}})
response = await client.user.starred(params={"per_page": 100})
if not response.is_last_page:
results = await asyncio.gather(
*(
client.user.starred(
**{"params": {"per_page": 100, "page": page_number}},
params={"per_page": 100, "page": page_number},
)
for page_number in range(
response.next_page_number, response.last_page_number + 1
@ -56,12 +56,12 @@ async def get_repositories(hass: HomeAssistant, access_token: str) -> list[str]:
repositories.update(response.data)
async def _get_personal_repositories() -> None:
response = await client.user.repos(**{"params": {"per_page": 100}})
response = await client.user.repos(params={"per_page": 100})
if not response.is_last_page:
results = await asyncio.gather(
*(
client.user.repos(
**{"params": {"per_page": 100, "page": page_number}},
params={"per_page": 100, "page": page_number},
)
for page_number in range(
response.next_page_number, response.last_page_number + 1
@ -137,7 +137,7 @@ class GitHubConfigFlow(ConfigFlow, domain=DOMAIN):
self._device = GitHubDeviceAPI(
client_id=CLIENT_ID,
session=async_get_clientsession(self.hass),
**{"client_name": SERVER_SOFTWARE},
client_name=SERVER_SOFTWARE,
)
try:

View File

@ -27,7 +27,7 @@ async def async_get_config_entry_diagnostics(
client = GitHubAPI(
token=config_entry.data[CONF_ACCESS_TOKEN],
session=async_get_clientsession(hass),
**{"client_name": SERVER_SOFTWARE},
client_name=SERVER_SOFTWARE,
)
try:

View File

@ -47,7 +47,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
if not entry.unique_id:
# If the config entry doesn't already have a unique ID, set one:
hass.config_entries.async_update_entry(
entry, **{"unique_id": entry.data[CONF_ZIP_CODE]}
entry, unique_id=entry.data[CONF_ZIP_CODE]
)
websession = aiohttp_client.async_get_clientsession(hass)

View File

@ -605,6 +605,7 @@ select = [
"N815", # Variable {name} in class scope should not be mixedCase
"PERF", # Perflint
"PGH004", # Use specific rule codes when using noqa
"PIE804", # Unnecessary dict kwargs
"PIE790", # Unnecessary pass statement
"PIE794", # Class field is defined multiple times
"PIE807", # Prefer list/dict over useless lambda

View File

@ -53,7 +53,7 @@ async def test_sensors(
assert entry.disabled
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
update_entry = entity_registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
entry.entity_id, disabled_by=None
)
await hass.async_block_till_done()
assert update_entry != entry
@ -75,7 +75,7 @@ async def test_sensors(
assert entry.disabled
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
update_entry = entity_registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
entry.entity_id, disabled_by=None
)
await hass.async_block_till_done()
assert update_entry != entry
@ -84,7 +84,7 @@ async def test_sensors(
assert state is None
update_entry = entity_registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
entry.entity_id, disabled_by=None
)
await hass.async_block_till_done()
async_fire_time_changed(
@ -135,7 +135,7 @@ async def test_sensors_model_01(
assert entry.disabled
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
update_entry = entity_registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
entry.entity_id, disabled_by=None
)
await hass.async_block_till_done()
assert update_entry != entry
@ -144,7 +144,7 @@ async def test_sensors_model_01(
assert state is None
update_entry = entity_registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
entry.entity_id, disabled_by=None
)
await hass.async_block_till_done()
async_fire_time_changed(

View File

@ -134,7 +134,7 @@ async def test_sensor_disabled(
# Test enabling entity.
updated_entry = entity_registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
entry.entity_id, disabled_by=None
)
assert updated_entry != entry

View File

@ -121,7 +121,7 @@ async def test_apprise_notification(hass: HomeAssistant) -> None:
# Validate calls were made under the hood correctly
obj.add.assert_called_once_with(config[BASE_COMPONENT]["url"])
obj.notify.assert_called_once_with(
**{"body": data["message"], "title": data["title"], "tag": None}
body=data["message"], title=data["title"], tag=None
)
@ -162,7 +162,7 @@ async def test_apprise_multiple_notification(hass: HomeAssistant) -> None:
# Validate 2 calls were made under the hood
assert obj.add.call_count == 2
obj.notify.assert_called_once_with(
**{"body": data["message"], "title": data["title"], "tag": None}
body=data["message"], title=data["title"], tag=None
)
@ -204,5 +204,5 @@ async def test_apprise_notification_with_target(
# Validate calls were made under the hood correctly
apprise_obj.notify.assert_called_once_with(
**{"body": data["message"], "title": data["title"], "tag": data["target"]}
body=data["message"], title=data["title"], tag=data["target"]
)

View File

@ -467,19 +467,17 @@ async def test_register_view_with_location(
with patch(
"homeassistant.components.cloud.http_api.async_detect_location_info",
return_value=LocationInfo(
**{
"country_code": "XX",
"zip_code": "12345",
"region_code": "GH",
"ip": "1.2.3.4",
"city": "Gotham",
"region_name": "Gotham",
"time_zone": "Earth/Gotham",
"currency": "XXX",
"latitude": "12.34567",
"longitude": "12.34567",
"use_metric": True,
}
country_code="XX",
zip_code="12345",
region_code="GH",
ip="1.2.3.4",
city="Gotham",
region_name="Gotham",
time_zone="Earth/Gotham",
currency="XXX",
latitude="12.34567",
longitude="12.34567",
use_metric=True,
),
):
req = await cloud_client.post(

View File

@ -121,7 +121,7 @@ async def enable_all_entities(hass, freezer, config_entry_id, time_till_next_upd
for entry in entities
if entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
]:
registry.async_update_entity(entry.entity_id, **{"disabled_by": None})
registry.async_update_entity(entry.entity_id, disabled_by=None)
await hass.async_block_till_done()
freezer.tick(time_till_next_update)
async_fire_time_changed(hass)

View File

@ -86,7 +86,7 @@ async def test_enable_sensor(
# enable the entity
updated_entry = entity_registry.async_update_entity(
entity_entry.entity_id, **{"disabled_by": None}
entity_entry.entity_id, disabled_by=None
)
assert updated_entry != entity_entry
assert updated_entry.disabled is False

View File

@ -60,7 +60,7 @@ async def test_rssi_sensor(
# Test enabling entity
updated_entry = entity_registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
entry.entity_id, disabled_by=None
)
with _patch_discovery(device=bulb), _patch_config_flow_try_connect(
@ -112,7 +112,7 @@ async def test_rssi_sensor_old_firmware(
# Test enabling entity
updated_entry = entity_registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
entry.entity_id, disabled_by=None
)
with _patch_discovery(device=bulb), _patch_config_flow_try_connect(

View File

@ -488,7 +488,7 @@ async def test_sensor_disabled(
# Test enabling entity
updated_entry = entity_registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
entry.entity_id, disabled_by=None
)
assert updated_entry != entry

View File

@ -50,7 +50,7 @@ async def test_binary_sensors(
setup_owproxy_mock_devices(owproxy, Platform.BINARY_SENSOR, [device_id])
# Some entities are disabled, enable them and reload before checking states
for ent in entity_entries:
entity_registry.async_update_entity(ent.entity_id, **{"disabled_by": None})
entity_registry.async_update_entity(ent.entity_id, disabled_by=None)
await hass.config_entries.async_reload(config_entry.entry_id)
await hass.async_block_till_done()

View File

@ -54,7 +54,7 @@ async def test_sensors(
setup_owproxy_mock_devices(owproxy, Platform.SENSOR, [device_id])
# Some entities are disabled, enable them and reload before checking states
for ent in entity_entries:
entity_registry.async_update_entity(ent.entity_id, **{"disabled_by": None})
entity_registry.async_update_entity(ent.entity_id, disabled_by=None)
await hass.config_entries.async_reload(config_entry.entry_id)
await hass.async_block_till_done()

View File

@ -57,7 +57,7 @@ async def test_switches(
setup_owproxy_mock_devices(owproxy, Platform.SWITCH, [device_id])
# Some entities are disabled, enable them and reload before checking states
for ent in entity_entries:
entity_registry.async_update_entity(ent.entity_id, **{"disabled_by": None})
entity_registry.async_update_entity(ent.entity_id, disabled_by=None)
await hass.config_entries.async_reload(config_entry.entry_id)
await hass.async_block_till_done()

View File

@ -247,7 +247,7 @@ async def test_media_lookups(
},
True,
)
search.assert_called_with(**{"title": "Movie 1", "libtype": None})
search.assert_called_with(title="Movie 1", libtype=None)
with pytest.raises(MediaNotFound) as excinfo:
payload = '{"title": "Movie 1"}'

View File

@ -50,7 +50,7 @@ async def test_sensors(
# Some entities are disabled, enable them and reload before checking states
for ent in entity_entries:
entity_registry.async_update_entity(ent.entity_id, **{"disabled_by": None})
entity_registry.async_update_entity(ent.entity_id, disabled_by=None)
await hass.config_entries.async_reload(config_entry.entry_id)
await hass.async_block_till_done()

View File

@ -46,7 +46,7 @@ async def test_sensors(
# Some entities are disabled, enable them and reload before checking states
for ent in entity_entries:
entity_registry.async_update_entity(ent.entity_id, **{"disabled_by": None})
entity_registry.async_update_entity(ent.entity_id, disabled_by=None)
await hass.config_entries.async_reload(config_entry.entry_id)
await hass.async_block_till_done()

View File

@ -92,7 +92,7 @@ def test_send_message_with_bad_data_throws_vol_error(
logging.DEBUG, logger="homeassistant.components.signal_messenger.notify"
), pytest.raises(vol.Invalid) as exc:
data = {"test": "test"}
signal_notification_service.send_message(MESSAGE, **{"data": data})
signal_notification_service.send_message(MESSAGE, data=data)
assert "Sending signal message" in caplog.text
assert "extra keys not allowed" in str(exc.value)
@ -112,7 +112,7 @@ def test_send_message_with_attachment(
) as temp_file:
temp_file.write("attachment_data")
data = {"attachments": [temp_file.name]}
signal_notification_service.send_message(MESSAGE, **{"data": data})
signal_notification_service.send_message(MESSAGE, data=data)
assert "Sending signal message" in caplog.text
assert signal_requests_mock.called
@ -131,7 +131,7 @@ def test_send_message_with_attachment_as_url(
logging.DEBUG, logger="homeassistant.components.signal_messenger.notify"
):
data = {"urls": [URL_ATTACHMENT]}
signal_notification_service.send_message(MESSAGE, **{"data": data})
signal_notification_service.send_message(MESSAGE, data=data)
assert "Sending signal message" in caplog.text
assert signal_requests_mock.called

View File

@ -66,9 +66,7 @@ async def test_sensor_disabled(hass: HomeAssistant, mock_bridge) -> None:
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
# Test enabling entity
updated_entry = registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
)
updated_entry = registry.async_update_entity(entry.entity_id, disabled_by=None)
assert updated_entry != entry
assert updated_entry.disabled is False

View File

@ -105,9 +105,7 @@ def _enable_entity(hass: HomeAssistant, entity_name: str) -> None:
"""Enable disabled entity."""
ent_reg = async_get(hass)
entry = ent_reg.async_get(entity_name)
updated_entry = ent_reg.async_update_entity(
entry.entity_id, **{"disabled_by": None}
)
updated_entry = ent_reg.async_update_entity(entry.entity_id, disabled_by=None)
assert updated_entry != entry
assert updated_entry.disabled is False

View File

@ -68,9 +68,7 @@ def _enable_entity(hass: HomeAssistant, entity_name: str) -> None:
"""Enable disabled entity."""
ent_reg = async_get(hass)
entry = ent_reg.async_get(entity_name)
updated_entry = ent_reg.async_update_entity(
entry.entity_id, **{"disabled_by": None}
)
updated_entry = ent_reg.async_update_entity(entry.entity_id, disabled_by=None)
assert updated_entry != entry
assert updated_entry.disabled is False

View File

@ -372,13 +372,7 @@ async def test_xiaomi_vacuum_services(
"velocity": -0.1,
},
"manual_control",
mock.call(
**{
"duration": 1000,
"rotation": -40,
"velocity": -0.1,
}
),
mock.call(duration=1000, rotation=-40, velocity=-0.1),
),
(
SERVICE_STOP_REMOTE_CONTROL,
@ -397,13 +391,7 @@ async def test_xiaomi_vacuum_services(
"velocity": 0.1,
},
"manual_control_once",
mock.call(
**{
"duration": 2000,
"rotation": 120,
"velocity": 0.1,
}
),
mock.call(duration=2000, rotation=120, velocity=0.1),
),
(
SERVICE_CLEAN_ZONE,

View File

@ -119,9 +119,7 @@ async def test_disabled_legacy_sensor(
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
# Test enabling legacy entity
updated_entry = registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
)
updated_entry = registry.async_update_entity(entry.entity_id, disabled_by=None)
assert updated_entry != entry
assert updated_entry.disabled is False
@ -274,7 +272,7 @@ async def test_config_parameter_binary_sensor(
assert entity_entry.entity_category == EntityCategory.DIAGNOSTIC
updated_entry = ent_reg.async_update_entity(
binary_sensor_entity_id, **{"disabled_by": None}
binary_sensor_entity_id, disabled_by=None
)
assert updated_entry != entity_entry
assert updated_entry.disabled is False

View File

@ -341,7 +341,7 @@ async def test_get_node_status_triggers(
entity_id = async_get_node_status_sensor_entity_id(
hass, device.id, ent_reg, dev_reg
)
entity = ent_reg.async_update_entity(entity_id, **{"disabled_by": None})
entity = ent_reg.async_update_entity(entity_id, disabled_by=None)
await hass.config_entries.async_reload(integration.entry_id)
await hass.async_block_till_done()
@ -373,7 +373,7 @@ async def test_if_node_status_change_fires(
entity_id = async_get_node_status_sensor_entity_id(
hass, device.id, ent_reg, dev_reg
)
entity = ent_reg.async_update_entity(entity_id, **{"disabled_by": None})
entity = ent_reg.async_update_entity(entity_id, disabled_by=None)
await hass.config_entries.async_reload(integration.entry_id)
await hass.async_block_till_done()
@ -452,7 +452,7 @@ async def test_if_node_status_change_fires_legacy(
entity_id = async_get_node_status_sensor_entity_id(
hass, device.id, ent_reg, dev_reg
)
ent_reg.async_update_entity(entity_id, **{"disabled_by": None})
ent_reg.async_update_entity(entity_id, disabled_by=None)
await hass.config_entries.async_reload(integration.entry_id)
await hass.async_block_till_done()
@ -530,7 +530,7 @@ async def test_get_trigger_capabilities_node_status(
entity_id = async_get_node_status_sensor_entity_id(
hass, device.id, ent_reg, dev_reg
)
ent_reg.async_update_entity(entity_id, **{"disabled_by": None})
ent_reg.async_update_entity(entity_id, disabled_by=None)
await hass.config_entries.async_reload(integration.entry_id)
await hass.async_block_till_done()

View File

@ -153,9 +153,7 @@ async def test_merten_507801_disabled_enitites(
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
# Test enabling entity
updated_entry = registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
)
updated_entry = registry.async_update_entity(entry.entity_id, disabled_by=None)
assert updated_entry != entry
assert updated_entry.disabled is False

View File

@ -232,7 +232,7 @@ async def test_config_parameter_number(
assert entity_entry.entity_category == EntityCategory.CONFIG
for entity_id in (number_entity_id, number_with_states_entity_id):
updated_entry = ent_reg.async_update_entity(entity_id, **{"disabled_by": None})
updated_entry = ent_reg.async_update_entity(entity_id, disabled_by=None)
assert updated_entry != entity_entry
assert updated_entry.disabled is False

View File

@ -308,9 +308,7 @@ async def test_config_parameter_select(
assert entity_entry.disabled
assert entity_entry.entity_category == EntityCategory.CONFIG
updated_entry = ent_reg.async_update_entity(
select_entity_id, **{"disabled_by": None}
)
updated_entry = ent_reg.async_update_entity(select_entity_id, disabled_by=None)
assert updated_entry != entity_entry
assert updated_entry.disabled is False

View File

@ -222,7 +222,7 @@ async def test_disabled_notification_sensor(
# Test enabling entity
updated_entry = ent_reg.async_update_entity(
entity_entry.entity_id, **{"disabled_by": None}
entity_entry.entity_id, disabled_by=None
)
assert updated_entry != entity_entry
assert updated_entry.disabled is False
@ -278,7 +278,7 @@ async def test_config_parameter_sensor(
assert entity_entry.entity_category == EntityCategory.DIAGNOSTIC
for entity_id in (sensor_entity_id, sensor_with_states_entity_id):
updated_entry = ent_reg.async_update_entity(entity_id, **{"disabled_by": None})
updated_entry = ent_reg.async_update_entity(entity_id, disabled_by=None)
assert updated_entry != entity_entry
assert updated_entry.disabled is False
@ -295,7 +295,7 @@ async def test_config_parameter_sensor(
assert state.state == "C-Wire"
updated_entry = ent_reg.async_update_entity(
entity_entry.entity_id, **{"disabled_by": None}
entity_entry.entity_id, disabled_by=None
)
assert updated_entry != entity_entry
assert updated_entry.disabled is False
@ -753,7 +753,7 @@ async def test_statistics_sensors_no_last_seen(
assert entry.disabled
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
ent_reg.async_update_entity(entry.entity_id, **{"disabled_by": None})
ent_reg.async_update_entity(entry.entity_id, disabled_by=None)
# reload integration and check if entity is correctly there
await hass.config_entries.async_reload(integration.entry_id)

View File

@ -228,9 +228,7 @@ async def test_config_parameter_switch(
assert entity_entry
assert entity_entry.disabled
updated_entry = ent_reg.async_update_entity(
switch_entity_id, **{"disabled_by": None}
)
updated_entry = ent_reg.async_update_entity(switch_entity_id, disabled_by=None)
assert updated_entry != entity_entry
assert updated_entry.disabled is False
assert entity_entry.entity_category == EntityCategory.CONFIG

View File

@ -1971,7 +1971,7 @@ async def test_core_store_historic_currency(
assert issue
assert issue.translation_placeholders == {"currency": "LTT"}
await hass.config.async_update(**{"currency": "EUR"})
await hass.config.async_update(currency="EUR")
issue = issue_registry.async_get_issue("homeassistant", issue_id)
assert not issue
@ -2027,7 +2027,7 @@ async def test_core_store_no_country(
issue = issue_registry.async_get_issue("homeassistant", issue_id)
assert issue
await hass.config.async_update(**{"country": "SE"})
await hass.config.async_update(country="SE")
issue = issue_registry.async_get_issue("homeassistant", issue_id)
assert not issue