From 1fdd056c0ec25948405660a2175cc4fa4183cfed Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Fri, 28 Jun 2024 14:17:47 +0200 Subject: [PATCH] Fix ruff manual-dict-comprehension PERF403 (#120723) * Fix PERF403 * Fix * Fix --- homeassistant/auth/__init__.py | 18 ++++----- homeassistant/auth/auth_store.py | 20 ++++++---- .../components/assist_pipeline/pipeline.py | 34 +++++++++------- homeassistant/components/blueprint/models.py | 3 +- homeassistant/components/cloud/prefs.py | 40 ++++++++++--------- .../components/gdacs/geo_location.py | 34 ++++++++-------- homeassistant/components/gdacs/sensor.py | 26 ++++++------ .../geonetnz_quakes/geo_location.py | 26 ++++++------ .../components/geonetnz_quakes/sensor.py | 26 ++++++------ .../components/geonetnz_volcano/sensor.py | 28 ++++++------- .../components/google_assistant/smart_home.py | 10 +++-- homeassistant/components/html5/notify.py | 5 +-- .../components/ign_sismologia/geo_location.py | 24 +++++------ .../components/kaiterra/air_quality.py | 21 +++++----- .../components/kraken/config_flow.py | 10 +++-- .../components/microsoft_face/__init__.py | 6 +-- .../geo_location.py | 32 +++++++-------- .../components/qld_bushfire/geo_location.py | 22 +++++----- .../usgs_earthquakes_feed/geo_location.py | 28 ++++++------- homeassistant/components/zwave_js/lock.py | 22 +++++----- homeassistant/helpers/area_registry.py | 22 +++++----- 21 files changed, 234 insertions(+), 223 deletions(-) diff --git a/homeassistant/auth/__init__.py b/homeassistant/auth/__init__.py index 665bc308d49..b74fd587fab 100644 --- a/homeassistant/auth/__init__.py +++ b/homeassistant/auth/__init__.py @@ -363,15 +363,15 @@ class AuthManager: local_only: bool | None = None, ) -> None: """Update a user.""" - kwargs: dict[str, Any] = {} - - for attr_name, value in ( - ("name", name), - ("group_ids", group_ids), - ("local_only", local_only), - ): - if value is not None: - kwargs[attr_name] = value + kwargs: dict[str, Any] = { + attr_name: value + for attr_name, value in ( + ("name", name), + ("group_ids", group_ids), + ("local_only", local_only), + ) + if value is not None + } await self._store.async_update_user(user, **kwargs) if is_active is not None: diff --git a/homeassistant/auth/auth_store.py b/homeassistant/auth/auth_store.py index 7843cb58df2..fc47a7d71e9 100644 --- a/homeassistant/auth/auth_store.py +++ b/homeassistant/auth/auth_store.py @@ -105,14 +105,18 @@ class AuthStore: "perm_lookup": self._perm_lookup, } - for attr_name, value in ( - ("is_owner", is_owner), - ("is_active", is_active), - ("local_only", local_only), - ("system_generated", system_generated), - ): - if value is not None: - kwargs[attr_name] = value + kwargs.update( + { + attr_name: value + for attr_name, value in ( + ("is_owner", is_owner), + ("is_active", is_active), + ("local_only", local_only), + ("system_generated", system_generated), + ) + if value is not None + } + ) new_user = models.User(**kwargs) diff --git a/homeassistant/components/assist_pipeline/pipeline.py b/homeassistant/components/assist_pipeline/pipeline.py index 56f88f60104..068afe53b49 100644 --- a/homeassistant/components/assist_pipeline/pipeline.py +++ b/homeassistant/components/assist_pipeline/pipeline.py @@ -304,21 +304,25 @@ async def async_update_pipeline( updates.pop("id") # Refactor this once we bump to Python 3.12 # and have https://peps.python.org/pep-0692/ - for key, val in ( - ("conversation_engine", conversation_engine), - ("conversation_language", conversation_language), - ("language", language), - ("name", name), - ("stt_engine", stt_engine), - ("stt_language", stt_language), - ("tts_engine", tts_engine), - ("tts_language", tts_language), - ("tts_voice", tts_voice), - ("wake_word_entity", wake_word_entity), - ("wake_word_id", wake_word_id), - ): - if val is not UNDEFINED: - updates[key] = val + updates.update( + { + key: val + for key, val in ( + ("conversation_engine", conversation_engine), + ("conversation_language", conversation_language), + ("language", language), + ("name", name), + ("stt_engine", stt_engine), + ("stt_language", stt_language), + ("tts_engine", tts_engine), + ("tts_language", tts_language), + ("tts_voice", tts_voice), + ("wake_word_entity", wake_word_entity), + ("wake_word_id", wake_word_id), + ) + if val is not UNDEFINED + } + ) await pipeline_data.pipeline_store.async_update_item(pipeline.id, updates) diff --git a/homeassistant/components/blueprint/models.py b/homeassistant/components/blueprint/models.py index 414d4e55a9b..01d26de618d 100644 --- a/homeassistant/components/blueprint/models.py +++ b/homeassistant/components/blueprint/models.py @@ -99,8 +99,7 @@ class Blueprint: inputs = {} for key, value in self.data[CONF_BLUEPRINT][CONF_INPUT].items(): if value and CONF_INPUT in value: - for key, value in value[CONF_INPUT].items(): - inputs[key] = value + inputs.update(dict(value[CONF_INPUT])) else: inputs[key] = value return inputs diff --git a/homeassistant/components/cloud/prefs.py b/homeassistant/components/cloud/prefs.py index af4e68194d6..9b7f863c368 100644 --- a/homeassistant/components/cloud/prefs.py +++ b/homeassistant/components/cloud/prefs.py @@ -180,24 +180,28 @@ class CloudPreferences: """Update user preferences.""" prefs = {**self._prefs} - for key, value in ( - (PREF_ENABLE_GOOGLE, google_enabled), - (PREF_ENABLE_ALEXA, alexa_enabled), - (PREF_ENABLE_REMOTE, remote_enabled), - (PREF_GOOGLE_SECURE_DEVICES_PIN, google_secure_devices_pin), - (PREF_CLOUDHOOKS, cloudhooks), - (PREF_CLOUD_USER, cloud_user), - (PREF_ALEXA_REPORT_STATE, alexa_report_state), - (PREF_GOOGLE_REPORT_STATE, google_report_state), - (PREF_ALEXA_SETTINGS_VERSION, alexa_settings_version), - (PREF_GOOGLE_SETTINGS_VERSION, google_settings_version), - (PREF_TTS_DEFAULT_VOICE, tts_default_voice), - (PREF_REMOTE_DOMAIN, remote_domain), - (PREF_GOOGLE_CONNECTED, google_connected), - (PREF_REMOTE_ALLOW_REMOTE_ENABLE, remote_allow_remote_enable), - ): - if value is not UNDEFINED: - prefs[key] = value + prefs.update( + { + key: value + for key, value in ( + (PREF_ENABLE_GOOGLE, google_enabled), + (PREF_ENABLE_ALEXA, alexa_enabled), + (PREF_ENABLE_REMOTE, remote_enabled), + (PREF_GOOGLE_SECURE_DEVICES_PIN, google_secure_devices_pin), + (PREF_CLOUDHOOKS, cloudhooks), + (PREF_CLOUD_USER, cloud_user), + (PREF_ALEXA_REPORT_STATE, alexa_report_state), + (PREF_GOOGLE_REPORT_STATE, google_report_state), + (PREF_ALEXA_SETTINGS_VERSION, alexa_settings_version), + (PREF_GOOGLE_SETTINGS_VERSION, google_settings_version), + (PREF_TTS_DEFAULT_VOICE, tts_default_voice), + (PREF_REMOTE_DOMAIN, remote_domain), + (PREF_GOOGLE_CONNECTED, google_connected), + (PREF_REMOTE_ALLOW_REMOTE_ENABLE, remote_allow_remote_enable), + ) + if value is not UNDEFINED + } + ) await self._save_prefs(prefs) diff --git a/homeassistant/components/gdacs/geo_location.py b/homeassistant/components/gdacs/geo_location.py index 394c9086d71..3f693241b24 100644 --- a/homeassistant/components/gdacs/geo_location.py +++ b/homeassistant/components/gdacs/geo_location.py @@ -188,20 +188,20 @@ class GdacsEvent(GeolocationEvent): @property def extra_state_attributes(self) -> dict[str, Any]: """Return the device state attributes.""" - attributes = {} - for key, value in ( - (ATTR_EXTERNAL_ID, self._external_id), - (ATTR_DESCRIPTION, self._description), - (ATTR_EVENT_TYPE, self._event_type), - (ATTR_ALERT_LEVEL, self._alert_level), - (ATTR_COUNTRY, self._country), - (ATTR_DURATION_IN_WEEK, self._duration_in_week), - (ATTR_FROM_DATE, self._from_date), - (ATTR_TO_DATE, self._to_date), - (ATTR_POPULATION, self._population), - (ATTR_SEVERITY, self._severity), - (ATTR_VULNERABILITY, self._vulnerability), - ): - if value or isinstance(value, bool): - attributes[key] = value - return attributes + return { + key: value + for key, value in ( + (ATTR_EXTERNAL_ID, self._external_id), + (ATTR_DESCRIPTION, self._description), + (ATTR_EVENT_TYPE, self._event_type), + (ATTR_ALERT_LEVEL, self._alert_level), + (ATTR_COUNTRY, self._country), + (ATTR_DURATION_IN_WEEK, self._duration_in_week), + (ATTR_FROM_DATE, self._from_date), + (ATTR_TO_DATE, self._to_date), + (ATTR_POPULATION, self._population), + (ATTR_SEVERITY, self._severity), + (ATTR_VULNERABILITY, self._vulnerability), + ) + if value or isinstance(value, bool) + } diff --git a/homeassistant/components/gdacs/sensor.py b/homeassistant/components/gdacs/sensor.py index 90ea668ea3f..c8205730da4 100644 --- a/homeassistant/components/gdacs/sensor.py +++ b/homeassistant/components/gdacs/sensor.py @@ -133,16 +133,16 @@ class GdacsSensor(SensorEntity): @property def extra_state_attributes(self) -> dict[str, Any]: """Return the device state attributes.""" - attributes: dict[str, Any] = {} - for key, value in ( - (ATTR_STATUS, self._status), - (ATTR_LAST_UPDATE, self._last_update), - (ATTR_LAST_UPDATE_SUCCESSFUL, self._last_update_successful), - (ATTR_LAST_TIMESTAMP, self._last_timestamp), - (ATTR_CREATED, self._created), - (ATTR_UPDATED, self._updated), - (ATTR_REMOVED, self._removed), - ): - if value or isinstance(value, bool): - attributes[key] = value - return attributes + return { + key: value + for key, value in ( + (ATTR_STATUS, self._status), + (ATTR_LAST_UPDATE, self._last_update), + (ATTR_LAST_UPDATE_SUCCESSFUL, self._last_update_successful), + (ATTR_LAST_TIMESTAMP, self._last_timestamp), + (ATTR_CREATED, self._created), + (ATTR_UPDATED, self._updated), + (ATTR_REMOVED, self._removed), + ) + if value or isinstance(value, bool) + } diff --git a/homeassistant/components/geonetnz_quakes/geo_location.py b/homeassistant/components/geonetnz_quakes/geo_location.py index f3458d96a18..78313e102e0 100644 --- a/homeassistant/components/geonetnz_quakes/geo_location.py +++ b/homeassistant/components/geonetnz_quakes/geo_location.py @@ -156,16 +156,16 @@ class GeonetnzQuakesEvent(GeolocationEvent): @property def extra_state_attributes(self) -> dict[str, Any]: """Return the device state attributes.""" - attributes = {} - for key, value in ( - (ATTR_EXTERNAL_ID, self._external_id), - (ATTR_DEPTH, self._depth), - (ATTR_LOCALITY, self._locality), - (ATTR_MAGNITUDE, self._magnitude), - (ATTR_MMI, self._mmi), - (ATTR_QUALITY, self._quality), - (ATTR_TIME, self._time), - ): - if value or isinstance(value, bool): - attributes[key] = value - return attributes + return { + key: value + for key, value in ( + (ATTR_EXTERNAL_ID, self._external_id), + (ATTR_DEPTH, self._depth), + (ATTR_LOCALITY, self._locality), + (ATTR_MAGNITUDE, self._magnitude), + (ATTR_MMI, self._mmi), + (ATTR_QUALITY, self._quality), + (ATTR_TIME, self._time), + ) + if value or isinstance(value, bool) + } diff --git a/homeassistant/components/geonetnz_quakes/sensor.py b/homeassistant/components/geonetnz_quakes/sensor.py index 020b76a6c97..2fce3e93d12 100644 --- a/homeassistant/components/geonetnz_quakes/sensor.py +++ b/homeassistant/components/geonetnz_quakes/sensor.py @@ -137,16 +137,16 @@ class GeonetnzQuakesSensor(SensorEntity): @property def extra_state_attributes(self): """Return the device state attributes.""" - attributes = {} - for key, value in ( - (ATTR_STATUS, self._status), - (ATTR_LAST_UPDATE, self._last_update), - (ATTR_LAST_UPDATE_SUCCESSFUL, self._last_update_successful), - (ATTR_LAST_TIMESTAMP, self._last_timestamp), - (ATTR_CREATED, self._created), - (ATTR_UPDATED, self._updated), - (ATTR_REMOVED, self._removed), - ): - if value or isinstance(value, bool): - attributes[key] = value - return attributes + return { + key: value + for key, value in ( + (ATTR_STATUS, self._status), + (ATTR_LAST_UPDATE, self._last_update), + (ATTR_LAST_UPDATE_SUCCESSFUL, self._last_update_successful), + (ATTR_LAST_TIMESTAMP, self._last_timestamp), + (ATTR_CREATED, self._created), + (ATTR_UPDATED, self._updated), + (ATTR_REMOVED, self._removed), + ) + if value or isinstance(value, bool) + } diff --git a/homeassistant/components/geonetnz_volcano/sensor.py b/homeassistant/components/geonetnz_volcano/sensor.py index 6197577b56c..980679cc64f 100644 --- a/homeassistant/components/geonetnz_volcano/sensor.py +++ b/homeassistant/components/geonetnz_volcano/sensor.py @@ -154,17 +154,17 @@ class GeonetnzVolcanoSensor(SensorEntity): @property def extra_state_attributes(self): """Return the device state attributes.""" - attributes = {} - for key, value in ( - (ATTR_EXTERNAL_ID, self._external_id), - (ATTR_ACTIVITY, self._activity), - (ATTR_HAZARDS, self._hazards), - (ATTR_LONGITUDE, self._longitude), - (ATTR_LATITUDE, self._latitude), - (ATTR_DISTANCE, self._distance), - (ATTR_LAST_UPDATE, self._feed_last_update), - (ATTR_LAST_UPDATE_SUCCESSFUL, self._feed_last_update_successful), - ): - if value or isinstance(value, bool): - attributes[key] = value - return attributes + return { + key: value + for key, value in ( + (ATTR_EXTERNAL_ID, self._external_id), + (ATTR_ACTIVITY, self._activity), + (ATTR_HAZARDS, self._hazards), + (ATTR_LONGITUDE, self._longitude), + (ATTR_LATITUDE, self._latitude), + (ATTR_DISTANCE, self._distance), + (ATTR_LAST_UPDATE, self._feed_last_update), + (ATTR_LAST_UPDATE_SUCCESSFUL, self._feed_last_update_successful), + ) + if value or isinstance(value, bool) + } diff --git a/homeassistant/components/google_assistant/smart_home.py b/homeassistant/components/google_assistant/smart_home.py index e362d1121c2..06b1a0251d8 100644 --- a/homeassistant/components/google_assistant/smart_home.py +++ b/homeassistant/components/google_assistant/smart_home.py @@ -262,9 +262,13 @@ async def handle_devices_execute( ), EXECUTE_LIMIT, ) - for entity_id, result in zip(executions, execute_results, strict=False): - if result is not None: - results[entity_id] = result + results.update( + { + entity_id: result + for entity_id, result in zip(executions, execute_results, strict=False) + if result is not None + } + ) except TimeoutError: pass diff --git a/homeassistant/components/html5/notify.py b/homeassistant/components/html5/notify.py index cc03202ae88..798589d2807 100644 --- a/homeassistant/components/html5/notify.py +++ b/homeassistant/components/html5/notify.py @@ -426,10 +426,7 @@ class HTML5NotificationService(BaseNotificationService): @property def targets(self): """Return a dictionary of registered targets.""" - targets = {} - for registration in self.registrations: - targets[registration] = registration - return targets + return {registration: registration for registration in self.registrations} def dismiss(self, **kwargs): """Dismisses a notification.""" diff --git a/homeassistant/components/ign_sismologia/geo_location.py b/homeassistant/components/ign_sismologia/geo_location.py index 779891f4bc2..7076d6a77a9 100644 --- a/homeassistant/components/ign_sismologia/geo_location.py +++ b/homeassistant/components/ign_sismologia/geo_location.py @@ -224,15 +224,15 @@ class IgnSismologiaLocationEvent(GeolocationEvent): @property def extra_state_attributes(self) -> dict[str, Any]: """Return the device state attributes.""" - attributes = {} - for key, value in ( - (ATTR_EXTERNAL_ID, self._external_id), - (ATTR_TITLE, self._title), - (ATTR_REGION, self._region), - (ATTR_MAGNITUDE, self._magnitude), - (ATTR_PUBLICATION_DATE, self._publication_date), - (ATTR_IMAGE_URL, self._image_url), - ): - if value or isinstance(value, bool): - attributes[key] = value - return attributes + return { + key: value + for key, value in ( + (ATTR_EXTERNAL_ID, self._external_id), + (ATTR_TITLE, self._title), + (ATTR_REGION, self._region), + (ATTR_MAGNITUDE, self._magnitude), + (ATTR_PUBLICATION_DATE, self._publication_date), + (ATTR_IMAGE_URL, self._image_url), + ) + if value or isinstance(value, bool) + } diff --git a/homeassistant/components/kaiterra/air_quality.py b/homeassistant/components/kaiterra/air_quality.py index 4d0d83a38eb..97553d6bda6 100644 --- a/homeassistant/components/kaiterra/air_quality.py +++ b/homeassistant/components/kaiterra/air_quality.py @@ -106,18 +106,15 @@ class KaiterraAirQuality(AirQualityEntity): @property def extra_state_attributes(self): """Return the device state attributes.""" - data = {} - attributes = [ - (ATTR_VOC, self.volatile_organic_compounds), - (ATTR_AQI_LEVEL, self.air_quality_index_level), - (ATTR_AQI_POLLUTANT, self.air_quality_index_pollutant), - ] - - for attr, value in attributes: - if value is not None: - data[attr] = value - - return data + return { + attr: value + for attr, value in ( + (ATTR_VOC, self.volatile_organic_compounds), + (ATTR_AQI_LEVEL, self.air_quality_index_level), + (ATTR_AQI_POLLUTANT, self.air_quality_index_pollutant), + ) + if value is not None + } async def async_added_to_hass(self): """Register callback.""" diff --git a/homeassistant/components/kraken/config_flow.py b/homeassistant/components/kraken/config_flow.py index 93c3c6606a3..67778515273 100644 --- a/homeassistant/components/kraken/config_flow.py +++ b/homeassistant/components/kraken/config_flow.py @@ -75,10 +75,12 @@ class KrakenOptionsFlowHandler(OptionsFlow): tracked_asset_pairs = self.config_entry.options.get( CONF_TRACKED_ASSET_PAIRS, [] ) - for tracked_asset_pair in tracked_asset_pairs: - tradable_asset_pairs_for_multi_select[tracked_asset_pair] = ( - tracked_asset_pair - ) + tradable_asset_pairs_for_multi_select.update( + { + tracked_asset_pair: tracked_asset_pair + for tracked_asset_pair in tracked_asset_pairs + } + ) options = { vol.Optional( diff --git a/homeassistant/components/microsoft_face/__init__.py b/homeassistant/components/microsoft_face/__init__.py index 23535911e5c..fa4de7f9c99 100644 --- a/homeassistant/components/microsoft_face/__init__.py +++ b/homeassistant/components/microsoft_face/__init__.py @@ -244,11 +244,7 @@ class MicrosoftFaceGroupEntity(Entity): @property def extra_state_attributes(self): """Return device specific state attributes.""" - attr = {} - for name, p_id in self._api.store[self._id].items(): - attr[name] = p_id - - return attr + return dict(self._api.store[self._id]) class MicrosoftFace: diff --git a/homeassistant/components/nsw_rural_fire_service_feed/geo_location.py b/homeassistant/components/nsw_rural_fire_service_feed/geo_location.py index 230141379e5..98efa90d780 100644 --- a/homeassistant/components/nsw_rural_fire_service_feed/geo_location.py +++ b/homeassistant/components/nsw_rural_fire_service_feed/geo_location.py @@ -269,19 +269,19 @@ class NswRuralFireServiceLocationEvent(GeolocationEvent): @property def extra_state_attributes(self) -> dict[str, Any]: """Return the device state attributes.""" - attributes = {} - for key, value in ( - (ATTR_EXTERNAL_ID, self._external_id), - (ATTR_CATEGORY, self._category), - (ATTR_LOCATION, self._location), - (ATTR_PUBLICATION_DATE, self._publication_date), - (ATTR_COUNCIL_AREA, self._council_area), - (ATTR_STATUS, self._status), - (ATTR_TYPE, self._type), - (ATTR_FIRE, self._fire), - (ATTR_SIZE, self._size), - (ATTR_RESPONSIBLE_AGENCY, self._responsible_agency), - ): - if value or isinstance(value, bool): - attributes[key] = value - return attributes + return { + key: value + for key, value in ( + (ATTR_EXTERNAL_ID, self._external_id), + (ATTR_CATEGORY, self._category), + (ATTR_LOCATION, self._location), + (ATTR_PUBLICATION_DATE, self._publication_date), + (ATTR_COUNCIL_AREA, self._council_area), + (ATTR_STATUS, self._status), + (ATTR_TYPE, self._type), + (ATTR_FIRE, self._fire), + (ATTR_SIZE, self._size), + (ATTR_RESPONSIBLE_AGENCY, self._responsible_agency), + ) + if value or isinstance(value, bool) + } diff --git a/homeassistant/components/qld_bushfire/geo_location.py b/homeassistant/components/qld_bushfire/geo_location.py index c8cfc30b2b5..c1266ab951b 100644 --- a/homeassistant/components/qld_bushfire/geo_location.py +++ b/homeassistant/components/qld_bushfire/geo_location.py @@ -223,14 +223,14 @@ class QldBushfireLocationEvent(GeolocationEvent): @property def extra_state_attributes(self) -> dict[str, Any]: """Return the device state attributes.""" - attributes = {} - for key, value in ( - (ATTR_EXTERNAL_ID, self._external_id), - (ATTR_CATEGORY, self._category), - (ATTR_PUBLICATION_DATE, self._publication_date), - (ATTR_UPDATED_DATE, self._updated_date), - (ATTR_STATUS, self._status), - ): - if value or isinstance(value, bool): - attributes[key] = value - return attributes + return { + key: value + for key, value in ( + (ATTR_EXTERNAL_ID, self._external_id), + (ATTR_CATEGORY, self._category), + (ATTR_PUBLICATION_DATE, self._publication_date), + (ATTR_UPDATED_DATE, self._updated_date), + (ATTR_STATUS, self._status), + ) + if value or isinstance(value, bool) + } diff --git a/homeassistant/components/usgs_earthquakes_feed/geo_location.py b/homeassistant/components/usgs_earthquakes_feed/geo_location.py index 33455dc11a9..aa9817eab7d 100644 --- a/homeassistant/components/usgs_earthquakes_feed/geo_location.py +++ b/homeassistant/components/usgs_earthquakes_feed/geo_location.py @@ -276,17 +276,17 @@ class UsgsEarthquakesEvent(GeolocationEvent): @property def extra_state_attributes(self) -> dict[str, Any]: """Return the device state attributes.""" - attributes = {} - for key, value in ( - (ATTR_EXTERNAL_ID, self._external_id), - (ATTR_PLACE, self._place), - (ATTR_MAGNITUDE, self._magnitude), - (ATTR_TIME, self._time), - (ATTR_UPDATED, self._updated), - (ATTR_STATUS, self._status), - (ATTR_TYPE, self._type), - (ATTR_ALERT, self._alert), - ): - if value or isinstance(value, bool): - attributes[key] = value - return attributes + return { + key: value + for key, value in ( + (ATTR_EXTERNAL_ID, self._external_id), + (ATTR_PLACE, self._place), + (ATTR_MAGNITUDE, self._magnitude), + (ATTR_TIME, self._time), + (ATTR_UPDATED, self._updated), + (ATTR_STATUS, self._status), + (ATTR_TYPE, self._type), + (ATTR_ALERT, self._alert), + ) + if value or isinstance(value, bool) + } diff --git a/homeassistant/components/zwave_js/lock.py b/homeassistant/components/zwave_js/lock.py index 5eb89e17402..b16c1090ef3 100644 --- a/homeassistant/components/zwave_js/lock.py +++ b/homeassistant/components/zwave_js/lock.py @@ -196,15 +196,19 @@ class ZWaveLock(ZWaveBaseEntity, LockEntity): ) -> None: """Set the lock configuration.""" params: dict[str, Any] = {"operation_type": operation_type} - for attr, val in ( - ("lock_timeout_configuration", lock_timeout), - ("auto_relock_time", auto_relock_time), - ("hold_and_release_time", hold_and_release_time), - ("twist_assist", twist_assist), - ("block_to_block", block_to_block), - ): - if val is not None: - params[attr] = val + params.update( + { + attr: val + for attr, val in ( + ("lock_timeout_configuration", lock_timeout), + ("auto_relock_time", auto_relock_time), + ("hold_and_release_time", hold_and_release_time), + ("twist_assist", twist_assist), + ("block_to_block", block_to_block), + ) + if val is not None + } + ) configuration = DoorLockCCConfigurationSetOptions(**params) result = await set_configuration( self.info.node.endpoints[self.info.primary_value.endpoint or 0], diff --git a/homeassistant/helpers/area_registry.py b/homeassistant/helpers/area_registry.py index 975750ebbdd..e6862428389 100644 --- a/homeassistant/helpers/area_registry.py +++ b/homeassistant/helpers/area_registry.py @@ -315,17 +315,17 @@ class AreaRegistry(BaseRegistry[AreasRegistryStoreData]): """Update name of area.""" old = self.areas[area_id] - new_values = {} - - for attr_name, value in ( - ("aliases", aliases), - ("icon", icon), - ("labels", labels), - ("picture", picture), - ("floor_id", floor_id), - ): - if value is not UNDEFINED and value != getattr(old, attr_name): - new_values[attr_name] = value + new_values = { + attr_name: value + for attr_name, value in ( + ("aliases", aliases), + ("icon", icon), + ("labels", labels), + ("picture", picture), + ("floor_id", floor_id), + ) + if value is not UNDEFINED and value != getattr(old, attr_name) + } if name is not UNDEFINED and name != old.name: new_values["name"] = name