diff --git a/homeassistant/components/knx/__init__.py b/homeassistant/components/knx/__init__.py index 02e54c9dd73..5c2d7e3b68c 100644 --- a/homeassistant/components/knx/__init__.py +++ b/homeassistant/components/knx/__init__.py @@ -225,9 +225,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Load a config entry.""" - conf = hass.data.get(DATA_KNX_CONFIG) # `conf` is None when reloading the integration or no `knx` key in configuration.yaml - if conf is None: + if (conf := hass.data.get(DATA_KNX_CONFIG)) is None: _conf = await async_integration_yaml_config(hass, DOMAIN) if not _conf or DOMAIN not in _conf: _LOGGER.warning( diff --git a/homeassistant/components/kostal_plenticore/helper.py b/homeassistant/components/kostal_plenticore/helper.py index 6dd72412fd8..e047c0dafba 100644 --- a/homeassistant/components/kostal_plenticore/helper.py +++ b/homeassistant/components/kostal_plenticore/helper.py @@ -123,9 +123,7 @@ class DataUpdateCoordinatorMixin: async def async_read_data(self, module_id: str, data_id: str) -> list[str, bool]: """Write settings back to Plenticore.""" - client = self._plenticore.client - - if client is None: + if (client := self._plenticore.client) is None: return False try: @@ -137,9 +135,7 @@ class DataUpdateCoordinatorMixin: async def async_write_data(self, module_id: str, value: dict[str, str]) -> bool: """Write settings back to Plenticore.""" - client = self._plenticore.client - - if client is None: + if (client := self._plenticore.client) is None: return False try: @@ -272,9 +268,7 @@ class SelectDataUpdateCoordinator( """Implementation of PlenticoreUpdateCoordinator for select data.""" async def _async_update_data(self) -> dict[str, dict[str, str]]: - client = self._plenticore.client - - if client is None: + if self._plenticore.client is None: return {} _LOGGER.debug("Fetching select %s for %s", self.name, self._fetch) diff --git a/homeassistant/components/lcn/device_trigger.py b/homeassistant/components/lcn/device_trigger.py index b82724f05d6..35575a442b2 100644 --- a/homeassistant/components/lcn/device_trigger.py +++ b/homeassistant/components/lcn/device_trigger.py @@ -56,8 +56,7 @@ async def async_get_triggers( ) -> list[dict[str, Any]]: """List device triggers for LCN devices.""" device_registry = dr.async_get(hass) - device = device_registry.async_get(device_id) - if device is None: + if (device := device_registry.async_get(device_id)) is None: return [] identifier = next(iter(device.identifiers)) diff --git a/homeassistant/components/lookin/climate.py b/homeassistant/components/lookin/climate.py index e661c14a151..79cac79cb17 100644 --- a/homeassistant/components/lookin/climate.py +++ b/homeassistant/components/lookin/climate.py @@ -152,8 +152,7 @@ class ConditionerEntity(LookinCoordinatorEntity, ClimateEntity): # an educated guess. # meteo_data: MeteoSensor = self._meteo_coordinator.data - current_temp = meteo_data.temperature - if not current_temp: + if not (current_temp := meteo_data.temperature): self._climate.hvac_mode = lookin_index.index(HVAC_MODE_AUTO) elif current_temp >= self._climate.temp_celsius: self._climate.hvac_mode = lookin_index.index(HVAC_MODE_COOL) diff --git a/homeassistant/components/lutron_caseta/__init__.py b/homeassistant/components/lutron_caseta/__init__.py index 0408f547f25..ebd9e041332 100644 --- a/homeassistant/components/lutron_caseta/__init__.py +++ b/homeassistant/components/lutron_caseta/__init__.py @@ -221,9 +221,7 @@ def _async_subscribe_pico_remote_events( @callback def _async_button_event(button_id, event_type): - device = button_devices_by_id.get(button_id) - - if not device: + if not (device := button_devices_by_id.get(button_id)): return if event_type == BUTTON_STATUS_PRESSED: diff --git a/homeassistant/components/moehlenhoff_alpha2/climate.py b/homeassistant/components/moehlenhoff_alpha2/climate.py index da536c4bd06..d99eb0e4c8c 100644 --- a/homeassistant/components/moehlenhoff_alpha2/climate.py +++ b/homeassistant/components/moehlenhoff_alpha2/climate.py @@ -101,8 +101,7 @@ class Alpha2Climate(CoordinatorEntity, ClimateEntity): async def async_set_temperature(self, **kwargs) -> None: """Set new target temperatures.""" - target_temperature = kwargs.get(ATTR_TEMPERATURE) - if target_temperature is None: + if (target_temperature := kwargs.get(ATTR_TEMPERATURE)) is None: return await self.coordinator.async_set_target_temperature( diff --git a/homeassistant/components/mold_indicator/sensor.py b/homeassistant/components/mold_indicator/sensor.py index fe8a7c2431d..bbd609f5fb8 100644 --- a/homeassistant/components/mold_indicator/sensor.py +++ b/homeassistant/components/mold_indicator/sensor.py @@ -205,9 +205,8 @@ class MoldIndicator(SensorEntity): return None unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) - temp = util.convert(state.state, float) - if temp is None: + if (temp := util.convert(state.state, float)) is None: _LOGGER.error( "Unable to parse temperature sensor %s with state: %s", state.entity_id, diff --git a/homeassistant/components/motioneye/media_source.py b/homeassistant/components/motioneye/media_source.py index 8c7b86ca173..915cc30897e 100644 --- a/homeassistant/components/motioneye/media_source.py +++ b/homeassistant/components/motioneye/media_source.py @@ -134,8 +134,7 @@ class MotionEyeMediaSource(MediaSource): def _get_device_or_raise(self, device_id: str) -> dr.DeviceEntry: """Get a config entry from a URL.""" device_registry = dr.async_get(self.hass) - device = device_registry.async_get(device_id) - if not device: + if not (device := device_registry.async_get(device_id)): raise MediaSourceError(f"Unable to find device with id: {device_id}") return device diff --git a/homeassistant/components/nest/__init__.py b/homeassistant/components/nest/__init__.py index 1083b80ac47..2a5f3850fe4 100644 --- a/homeassistant/components/nest/__init__.py +++ b/homeassistant/components/nest/__init__.py @@ -356,8 +356,7 @@ class NestEventMediaThumbnailView(NestEventViewBase): async def handle_media(self, media: Media) -> web.StreamResponse: """Start a GET request.""" contents = media.contents - content_type = media.content_type - if content_type == "image/jpeg": + if (content_type := media.content_type) == "image/jpeg": image = Image(media.event_image_type.content_type, contents) contents = img_util.scale_jpeg_camera_image( image, THUMBNAIL_SIZE_PX, THUMBNAIL_SIZE_PX diff --git a/homeassistant/components/nest/config_flow.py b/homeassistant/components/nest/config_flow.py index aac8c263ef1..b257c7b51bb 100644 --- a/homeassistant/components/nest/config_flow.py +++ b/homeassistant/components/nest/config_flow.py @@ -319,8 +319,7 @@ class NestFlowHandler( if user_input is not None and not errors: # Create the subscriber id and/or verify it already exists. Note that # the existing id is used, and create call below is idempotent - subscriber_id = data.get(CONF_SUBSCRIBER_ID, "") - if not subscriber_id: + if not (subscriber_id := data.get(CONF_SUBSCRIBER_ID, "")): subscriber_id = _generate_subscription_id(cloud_project_id) _LOGGER.debug("Creating subscriber id '%s'", subscriber_id) # Create a placeholder ConfigEntry to use since with the auth we've already created. diff --git a/homeassistant/components/nest/media_source.py b/homeassistant/components/nest/media_source.py index 2676929f2de..af8a4af8ba5 100644 --- a/homeassistant/components/nest/media_source.py +++ b/homeassistant/components/nest/media_source.py @@ -134,8 +134,7 @@ class NestEventMediaStore(EventMediaStore): """Load data.""" if self._data is None: self._devices = await self._get_devices() - data = await self._store.async_load() - if data is None: + if (data := await self._store.async_load()) is None: _LOGGER.debug("Loaded empty event store") self._data = {} elif isinstance(data, dict): diff --git a/homeassistant/components/open_meteo/__init__.py b/homeassistant/components/open_meteo/__init__.py index 653ccff6980..de42d19d8c9 100644 --- a/homeassistant/components/open_meteo/__init__.py +++ b/homeassistant/components/open_meteo/__init__.py @@ -28,8 +28,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: open_meteo = OpenMeteo(session=session) async def async_update_forecast() -> Forecast: - zone = hass.states.get(entry.data[CONF_ZONE]) - if zone is None: + if (zone := hass.states.get(entry.data[CONF_ZONE])) is None: raise UpdateFailed(f"Zone '{entry.data[CONF_ZONE]}' not found") try: diff --git a/homeassistant/components/picnic/coordinator.py b/homeassistant/components/picnic/coordinator.py index 71a6559975c..24f3086134f 100644 --- a/homeassistant/components/picnic/coordinator.py +++ b/homeassistant/components/picnic/coordinator.py @@ -59,9 +59,7 @@ class PicnicUpdateCoordinator(DataUpdateCoordinator): def fetch_data(self): """Fetch the data from the Picnic API and return a flat dict with only needed sensor data.""" # Fetch from the API and pre-process the data - cart = self.picnic_api_client.get_cart() - - if not cart: + if not (cart := self.picnic_api_client.get_cart()): raise UpdateFailed("API response doesn't contain expected data.") last_order = self._get_last_order() diff --git a/homeassistant/components/synology_dsm/service.py b/homeassistant/components/synology_dsm/service.py index a7a336e0c1b..130ad110b46 100644 --- a/homeassistant/components/synology_dsm/service.py +++ b/homeassistant/components/synology_dsm/service.py @@ -45,8 +45,7 @@ async def async_setup_services(hass: HomeAssistant) -> None: return if call.service in [SERVICE_REBOOT, SERVICE_SHUTDOWN]: - dsm_device = hass.data[DOMAIN].get(serial) - if not dsm_device: + if not (dsm_device := hass.data[DOMAIN].get(serial)): LOGGER.error("DSM with specified serial %s not found", serial) return LOGGER.debug("%s DSM with serial %s", call.service, serial) diff --git a/homeassistant/components/tolo/climate.py b/homeassistant/components/tolo/climate.py index 659dfcbda16..4c02cdb74dc 100644 --- a/homeassistant/components/tolo/climate.py +++ b/homeassistant/components/tolo/climate.py @@ -144,8 +144,7 @@ class SaunaClimate(ToloSaunaCoordinatorEntity, ClimateEntity): def set_temperature(self, **kwargs: Any) -> None: """Set desired target temperature.""" - temperature = kwargs.get(ATTR_TEMPERATURE) - if temperature is None: + if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None: return self.coordinator.client.set_target_temperature(round(temperature)) diff --git a/homeassistant/components/venstar/sensor.py b/homeassistant/components/venstar/sensor.py index 68d5bad27d6..824774f3e31 100644 --- a/homeassistant/components/venstar/sensor.py +++ b/homeassistant/components/venstar/sensor.py @@ -75,8 +75,7 @@ async def async_setup_entry( coordinator = hass.data[DOMAIN][config_entry.entry_id] entities: list[Entity] = [] - sensors = coordinator.client.get_sensor_list() - if not sensors: + if not (sensors := coordinator.client.get_sensor_list()): return for sensor_name in sensors: diff --git a/homeassistant/components/webostv/device_trigger.py b/homeassistant/components/webostv/device_trigger.py index 47cdf974cc7..feb5bae98fe 100644 --- a/homeassistant/components/webostv/device_trigger.py +++ b/homeassistant/components/webostv/device_trigger.py @@ -79,9 +79,7 @@ async def async_attach_trigger( automation_info: AutomationTriggerInfo, ) -> CALLBACK_TYPE | None: """Attach a trigger.""" - trigger_type = config[CONF_TYPE] - - if trigger_type == TURN_ON_PLATFORM_TYPE: + if (trigger_type := config[CONF_TYPE]) == TURN_ON_PLATFORM_TYPE: trigger_config = { CONF_PLATFORM: trigger_type, CONF_DEVICE_ID: config[CONF_DEVICE_ID], diff --git a/homeassistant/components/webostv/helpers.py b/homeassistant/components/webostv/helpers.py index 70a253d5ceb..0ee3805f42f 100644 --- a/homeassistant/components/webostv/helpers.py +++ b/homeassistant/components/webostv/helpers.py @@ -20,9 +20,7 @@ def async_get_device_entry_by_device_id( Raises ValueError if device ID is invalid. """ device_reg = dr.async_get(hass) - device = device_reg.async_get(device_id) - - if device is None: + if (device := device_reg.async_get(device_id)) is None: raise ValueError(f"Device {device_id} is not a valid {DOMAIN} device.") return device diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index 95e0b059538..67125c45ef5 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -248,8 +248,7 @@ class LgWebOSMediaPlayerEntity(RestoreEntity, MediaPlayerEntity): if maj_v and min_v: self._attr_device_info["sw_version"] = f"{maj_v}.{min_v}" - model = self._client.system_info.get("modelName") - if model: + if model := self._client.system_info.get("modelName"): self._attr_device_info["model"] = model self._attr_extra_state_attributes = {} diff --git a/homeassistant/components/xiaomi_aqara/binary_sensor.py b/homeassistant/components/xiaomi_aqara/binary_sensor.py index ae4059728fe..0a21bb37d44 100644 --- a/homeassistant/components/xiaomi_aqara/binary_sensor.py +++ b/homeassistant/components/xiaomi_aqara/binary_sensor.py @@ -333,8 +333,7 @@ class XiaomiDoorSensor(XiaomiBinarySensor, RestoreEntity): async def async_added_to_hass(self) -> None: """Handle entity which will be added.""" await super().async_added_to_hass() - state = await self.async_get_last_state() - if state is None: + if (state := await self.async_get_last_state()) is None: return self._state = state.state == "on"