diff --git a/homeassistant/components/cloud/alexa_config.py b/homeassistant/components/cloud/alexa_config.py index f578a114dfc..3e82e662fe9 100644 --- a/homeassistant/components/cloud/alexa_config.py +++ b/homeassistant/components/cloud/alexa_config.py @@ -134,8 +134,7 @@ class AlexaConfig(alexa_config.AbstractConfig): return entity_expose entity_registry = er.async_get(self.hass) - registry_entry = entity_registry.async_get(entity_id) - if registry_entry: + if registry_entry := entity_registry.async_get(entity_id): auxiliary_entity = registry_entry.entity_category in ( ENTITY_CATEGORY_CONFIG, ENTITY_CATEGORY_DIAGNOSTIC, diff --git a/homeassistant/components/cloud/google_config.py b/homeassistant/components/cloud/google_config.py index bfb6510fcda..4f71aeeb9a0 100644 --- a/homeassistant/components/cloud/google_config.py +++ b/homeassistant/components/cloud/google_config.py @@ -132,8 +132,7 @@ class CloudGoogleConfig(AbstractConfig): return entity_expose entity_registry = er.async_get(self.hass) - registry_entry = entity_registry.async_get(entity_id) - if registry_entry: + if registry_entry := entity_registry.async_get(entity_id): auxiliary_entity = registry_entry.entity_category in ( ENTITY_CATEGORY_CONFIG, ENTITY_CATEGORY_DIAGNOSTIC, diff --git a/homeassistant/components/dlna_dmr/config_flow.py b/homeassistant/components/dlna_dmr/config_flow.py index 551faf2815f..3958ca9e3e5 100644 --- a/homeassistant/components/dlna_dmr/config_flow.py +++ b/homeassistant/components/dlna_dmr/config_flow.py @@ -352,8 +352,7 @@ class DlnaDmrOptionsFlowHandler(config_entries.OptionsFlow): def _add_with_suggestion(key: str, validator: Callable) -> None: """Add a field to with a suggested, not default, value.""" - suggested_value = options.get(key) - if suggested_value is None: + if (suggested_value := options.get(key)) is None: fields[vol.Optional(key)] = validator else: fields[ diff --git a/homeassistant/components/eq3btsmart/climate.py b/homeassistant/components/eq3btsmart/climate.py index 3c3d41d090c..b7c39ec996c 100644 --- a/homeassistant/components/eq3btsmart/climate.py +++ b/homeassistant/components/eq3btsmart/climate.py @@ -123,8 +123,7 @@ class EQ3BTSmartThermostat(ClimateEntity): def set_temperature(self, **kwargs): """Set new target temperature.""" - temperature = kwargs.get(ATTR_TEMPERATURE) - if temperature is None: + if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None: return self._thermostat.target_temperature = temperature diff --git a/homeassistant/components/fitbit/sensor.py b/homeassistant/components/fitbit/sensor.py index 96de36a1f29..2de121920af 100644 --- a/homeassistant/components/fitbit/sensor.py +++ b/homeassistant/components/fitbit/sensor.py @@ -377,12 +377,13 @@ class FitbitSensor(SensorEntity): @property def icon(self) -> str | None: """Icon to use in the frontend, if any.""" - if self.entity_description.key == "devices/battery" and self.extra is not None: - extra_battery = self.extra.get("battery") - if extra_battery is not None: - battery_level = BATTERY_LEVELS.get(extra_battery) - if battery_level is not None: - return icon_for_battery_level(battery_level=battery_level) + if ( + self.entity_description.key == "devices/battery" + and self.extra is not None + and (extra_battery := self.extra.get("battery")) is not None + and (battery_level := BATTERY_LEVELS.get(extra_battery)) is not None + ): + return icon_for_battery_level(battery_level=battery_level) return self.entity_description.icon @property diff --git a/homeassistant/components/generic_thermostat/climate.py b/homeassistant/components/generic_thermostat/climate.py index c48deba12d8..4d52240535f 100644 --- a/homeassistant/components/generic_thermostat/climate.py +++ b/homeassistant/components/generic_thermostat/climate.py @@ -364,8 +364,7 @@ class GenericThermostat(ClimateEntity, RestoreEntity): async def async_set_temperature(self, **kwargs): """Set new target temperature.""" - temperature = kwargs.get(ATTR_TEMPERATURE) - if temperature is None: + if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None: return self._target_temp = temperature await self._async_control_heating(force=True) diff --git a/homeassistant/components/honeywell/climate.py b/homeassistant/components/honeywell/climate.py index 8088a73506d..7c40a0bb684 100644 --- a/homeassistant/components/honeywell/climate.py +++ b/homeassistant/components/honeywell/climate.py @@ -282,8 +282,7 @@ class HoneywellUSThermostat(ClimateEntity): def _set_temperature(self, **kwargs) -> None: """Set new target temperature.""" - temperature = kwargs.get(ATTR_TEMPERATURE) - if temperature is None: + if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None: return try: # Get current mode @@ -310,11 +309,9 @@ class HoneywellUSThermostat(ClimateEntity): try: if HVAC_MODE_HEAT_COOL in self._hvac_mode_map: - temperature = kwargs.get(ATTR_TARGET_TEMP_HIGH) - if temperature: + if temperature := kwargs.get(ATTR_TARGET_TEMP_HIGH): self._device.setpoint_cool = temperature - temperature = kwargs.get(ATTR_TARGET_TEMP_LOW) - if temperature: + if temperature := kwargs.get(ATTR_TARGET_TEMP_LOW): self._device.setpoint_heat = temperature except somecomfort.SomeComfortError as err: _LOGGER.error("Invalid temperature %s: %s", temperature, err) diff --git a/homeassistant/components/html5/notify.py b/homeassistant/components/html5/notify.py index 594d84a8068..6c3a10757bb 100644 --- a/homeassistant/components/html5/notify.py +++ b/homeassistant/components/html5/notify.py @@ -186,9 +186,8 @@ def get_service(hass, config, discovery_info=None): hass.http.register_view(HTML5PushCallbackView(registrations)) gcm_api_key = config.get(ATTR_GCM_API_KEY) - gcm_sender_id = config.get(ATTR_GCM_SENDER_ID) - if gcm_sender_id is not None: + if config.get(ATTR_GCM_SENDER_ID) is not None: add_manifest_json_key(ATTR_GCM_SENDER_ID, config.get(ATTR_GCM_SENDER_ID)) return HTML5NotificationService( @@ -332,9 +331,7 @@ class HTML5PushCallbackView(HomeAssistantView): # https://auth0.com/docs/quickstart/backend/python def check_authorization_header(self, request): """Check the authorization header.""" - - auth = request.headers.get(AUTHORIZATION) - if not auth: + if not (auth := request.headers.get(AUTHORIZATION)): return self.json_message( "Authorization header is expected", status_code=HTTPStatus.UNAUTHORIZED ) @@ -463,9 +460,7 @@ class HTML5NotificationService(BaseNotificationService): ATTR_TITLE: kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT), } - data = kwargs.get(ATTR_DATA) - - if data: + if data := kwargs.get(ATTR_DATA): # Pick out fields that should go into the notification directly vs # into the notification data dictionary. @@ -496,9 +491,8 @@ class HTML5NotificationService(BaseNotificationService): if priority not in ["normal", "high"]: priority = DEFAULT_PRIORITY payload["timestamp"] = timestamp * 1000 # Javascript ms since epoch - targets = kwargs.get(ATTR_TARGET) - if not targets: + if not (targets := kwargs.get(ATTR_TARGET)): targets = self.registrations.keys() for target in list(targets): diff --git a/homeassistant/components/knx/climate.py b/homeassistant/components/knx/climate.py index 91342cca839..22289738711 100644 --- a/homeassistant/components/knx/climate.py +++ b/homeassistant/components/knx/climate.py @@ -218,8 +218,7 @@ class KNXClimate(KnxEntity, ClimateEntity): async def async_set_temperature(self, **kwargs: Any) -> None: """Set new target temperature.""" - temperature = kwargs.get(ATTR_TEMPERATURE) - if temperature is None: + if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None: return await self._device.set_target_temperature(temperature) self.async_write_ha_state() diff --git a/homeassistant/components/mobile_app/device_tracker.py b/homeassistant/components/mobile_app/device_tracker.py index 1deebf6b531..f4b5866eacd 100644 --- a/homeassistant/components/mobile_app/device_tracker.py +++ b/homeassistant/components/mobile_app/device_tracker.py @@ -60,8 +60,7 @@ class MobileAppEntity(TrackerEntity, RestoreEntity): """Return device specific attributes.""" attrs = {} for key in ATTR_KEYS: - value = self._data.get(key) - if value is not None: + if (value := self._data.get(key)) is not None: attrs[key] = value return attrs @@ -74,9 +73,7 @@ class MobileAppEntity(TrackerEntity, RestoreEntity): @property def latitude(self): """Return latitude value of the device.""" - gps = self._data.get(ATTR_GPS) - - if gps is None: + if (gps := self._data.get(ATTR_GPS)) is None: return None return gps[0] @@ -84,9 +81,7 @@ class MobileAppEntity(TrackerEntity, RestoreEntity): @property def longitude(self): """Return longitude value of the device.""" - gps = self._data.get(ATTR_GPS) - - if gps is None: + if (gps := self._data.get(ATTR_GPS)) is None: return None return gps[1] diff --git a/homeassistant/components/mobile_app/notify.py b/homeassistant/components/mobile_app/notify.py index 36afbac71c8..21f92d73020 100644 --- a/homeassistant/components/mobile_app/notify.py +++ b/homeassistant/components/mobile_app/notify.py @@ -114,9 +114,7 @@ class MobileAppNotificationService(BaseNotificationService): ): data[ATTR_TITLE] = kwargs.get(ATTR_TITLE) - targets = kwargs.get(ATTR_TARGET) - - if not targets: + if not (targets := kwargs.get(ATTR_TARGET)): targets = push_registrations(self.hass).values() if kwargs.get(ATTR_DATA) is not None: diff --git a/homeassistant/components/mobile_app/webhook.py b/homeassistant/components/mobile_app/webhook.py index 8a06b693e9a..7d8b6ad4b53 100644 --- a/homeassistant/components/mobile_app/webhook.py +++ b/homeassistant/components/mobile_app/webhook.py @@ -264,9 +264,7 @@ async def webhook_fire_event(hass, config_entry, data): @validate_schema({vol.Required(ATTR_CAMERA_ENTITY_ID): cv.string}) async def webhook_stream_camera(hass, config_entry, data): """Handle a request to HLS-stream a camera.""" - camera = hass.states.get(data[ATTR_CAMERA_ENTITY_ID]) - - if camera is None: + if (camera := hass.states.get(data[ATTR_CAMERA_ENTITY_ID])) is None: return webhook_response( {"success": False}, registration=config_entry.data, diff --git a/homeassistant/components/rss_feed_template/__init__.py b/homeassistant/components/rss_feed_template/__init__.py index 222b533235d..fb830bccee7 100644 --- a/homeassistant/components/rss_feed_template/__init__.py +++ b/homeassistant/components/rss_feed_template/__init__.py @@ -43,8 +43,7 @@ def setup(hass, config): requires_auth = feedconfig.get("requires_api_password") - title = feedconfig.get("title") - if title is not None: + if (title := feedconfig.get("title")) is not None: title.hass = hass items = feedconfig.get("items") diff --git a/homeassistant/components/sensibo/climate.py b/homeassistant/components/sensibo/climate.py index c4589205e34..b0b211e4a7d 100644 --- a/homeassistant/components/sensibo/climate.py +++ b/homeassistant/components/sensibo/climate.py @@ -112,8 +112,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= async def async_assume_state(service): """Set state according to external service call..""" - entity_ids = service.data.get(ATTR_ENTITY_ID) - if entity_ids: + if entity_ids := service.data.get(ATTR_ENTITY_ID): target_climate = [ device for device in devices if device.entity_id in entity_ids ] @@ -299,8 +298,7 @@ class SensiboClimate(ClimateEntity): async def async_set_temperature(self, **kwargs): """Set new target temperature.""" - temperature = kwargs.get(ATTR_TEMPERATURE) - if temperature is None: + if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None: return temperature = int(temperature) if temperature not in self._temperatures_list: diff --git a/homeassistant/components/universal/media_player.py b/homeassistant/components/universal/media_player.py index 59cef93de49..925a76140f3 100644 --- a/homeassistant/components/universal/media_player.py +++ b/homeassistant/components/universal/media_player.py @@ -216,9 +216,7 @@ class UniversalMediaPlayer(MediaPlayerEntity): def _entity_lkp(self, entity_id, state_attr=None): """Look up an entity state.""" - state_obj = self.hass.states.get(entity_id) - - if state_obj is None: + if (state_obj := self.hass.states.get(entity_id)) is None: return if state_attr: