diff --git a/homeassistant/components/alarm_control_panel/reproduce_state.py b/homeassistant/components/alarm_control_panel/reproduce_state.py index 3fcc540d04b..ad992012c04 100644 --- a/homeassistant/components/alarm_control_panel/reproduce_state.py +++ b/homeassistant/components/alarm_control_panel/reproduce_state.py @@ -48,9 +48,7 @@ async def _async_reproduce_state( reproduce_options: dict[str, Any] | None = None, ) -> None: """Reproduce a single state.""" - cur_state = hass.states.get(state.entity_id) - - if cur_state is None: + if (cur_state := hass.states.get(state.entity_id)) is None: _LOGGER.warning("Unable to find entity %s", state.entity_id) return diff --git a/homeassistant/components/climacell/sensor.py b/homeassistant/components/climacell/sensor.py index 07bc4790b5f..f934449fdb0 100644 --- a/homeassistant/components/climacell/sensor.py +++ b/homeassistant/components/climacell/sensor.py @@ -28,9 +28,8 @@ async def async_setup_entry( ) -> None: """Set up a config entry.""" coordinator = hass.data[DOMAIN][config_entry.entry_id] - api_version = config_entry.data[CONF_API_VERSION] - if api_version == 3: + if (api_version := config_entry.data[CONF_API_VERSION]) == 3: api_class = ClimaCellV3SensorEntity sensor_types = CC_V3_SENSOR_TYPES else: diff --git a/homeassistant/components/emulated_kasa/__init__.py b/homeassistant/components/emulated_kasa/__init__.py index d513669cd00..967edc8d157 100644 --- a/homeassistant/components/emulated_kasa/__init__.py +++ b/homeassistant/components/emulated_kasa/__init__.py @@ -51,8 +51,7 @@ CONFIG_SCHEMA = vol.Schema( async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the emulated_kasa component.""" - conf = config.get(DOMAIN) - if not conf: + if not (conf := config.get(DOMAIN)): return True entity_configs = conf[CONF_ENTITIES] @@ -83,13 +82,11 @@ async def validate_configs(hass, entity_configs): """Validate that entities exist and ensure templates are ready to use.""" entity_registry = await hass.helpers.entity_registry.async_get_registry() for entity_id, entity_config in entity_configs.items(): - state = hass.states.get(entity_id) - if state is None: + if (state := hass.states.get(entity_id)) is None: _LOGGER.debug("Entity not found: %s", entity_id) continue - entity = entity_registry.async_get(entity_id) - if entity: + if entity := entity_registry.async_get(entity_id): entity_config[CONF_UNIQUE_ID] = get_system_unique_id(entity) else: entity_config[CONF_UNIQUE_ID] = entity_id @@ -122,8 +119,7 @@ def get_system_unique_id(entity: RegistryEntry): def get_plug_devices(hass, entity_configs): """Produce list of plug devices from config entities.""" for entity_id, entity_config in entity_configs.items(): - state = hass.states.get(entity_id) - if state is None: + if (state := hass.states.get(entity_id)) is None: continue name = entity_config.get(CONF_NAME, state.name) diff --git a/homeassistant/components/evohome/climate.py b/homeassistant/components/evohome/climate.py index 6dc2809630d..c293034e05a 100644 --- a/homeassistant/components/evohome/climate.py +++ b/homeassistant/components/evohome/climate.py @@ -230,9 +230,8 @@ class EvoZone(EvoChild, EvoClimateEntity): async def async_set_temperature(self, **kwargs) -> None: """Set a new target temperature.""" temperature = kwargs["temperature"] - until = kwargs.get("until") - if until is None: + if (until := kwargs.get("until")) is None: if self._evo_device.setpointStatus["setpointMode"] == EVO_FOLLOW: await self._update_schedule() until = dt_util.parse_datetime(self.setpoints.get("next_sp_from", "")) diff --git a/homeassistant/components/frontend/storage.py b/homeassistant/components/frontend/storage.py index 0b04655bd86..d7aabbec9b8 100644 --- a/homeassistant/components/frontend/storage.py +++ b/homeassistant/components/frontend/storage.py @@ -33,9 +33,8 @@ def with_store(orig_func: Callable) -> Callable: """Provide user specific data and store to function.""" stores, data = hass.data[DATA_STORAGE] user_id = connection.user.id - store = stores.get(user_id) - if store is None: + if (store := stores.get(user_id)) is None: store = stores[user_id] = hass.helpers.storage.Store( STORAGE_VERSION_USER_DATA, f"frontend.user_data_{connection.user.id}" ) diff --git a/homeassistant/components/google/__init__.py b/homeassistant/components/google/__init__.py index 7e157d238d5..08663a297d2 100644 --- a/homeassistant/components/google/__init__.py +++ b/homeassistant/components/google/__init__.py @@ -233,8 +233,7 @@ def setup(hass, config): if DATA_INDEX not in hass.data: hass.data[DATA_INDEX] = {} - conf = config.get(DOMAIN, {}) - if not conf: + if not (conf := config.get(DOMAIN, {})): # component is set up by tts platform return True diff --git a/homeassistant/components/homematic/climate.py b/homeassistant/components/homematic/climate.py index aa5fb4a8e44..84c722db1df 100644 --- a/homeassistant/components/homematic/climate.py +++ b/homeassistant/components/homematic/climate.py @@ -133,8 +133,7 @@ class HMThermostat(HMDevice, 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 None self._hmdevice.writeNodeData(self._state, float(temperature)) diff --git a/homeassistant/components/image_processing/__init__.py b/homeassistant/components/image_processing/__init__.py index d1220a84cdd..5c09e0b0bc7 100644 --- a/homeassistant/components/image_processing/__init__.py +++ b/homeassistant/components/image_processing/__init__.py @@ -161,8 +161,7 @@ class ImageProcessingFaceEntity(ImageProcessingEntity): if ATTR_CONFIDENCE not in face: continue - f_co = face[ATTR_CONFIDENCE] - if f_co > confidence: + if (f_co := face[ATTR_CONFIDENCE]) > confidence: confidence = f_co for attr in (ATTR_NAME, ATTR_MOTION): if attr in face: diff --git a/homeassistant/components/ipp/__init__.py b/homeassistant/components/ipp/__init__.py index 242390b55b8..d5930ac5f56 100644 --- a/homeassistant/components/ipp/__init__.py +++ b/homeassistant/components/ipp/__init__.py @@ -15,8 +15,7 @@ PLATFORMS = [SENSOR_DOMAIN] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up IPP from a config entry.""" hass.data.setdefault(DOMAIN, {}) - coordinator = hass.data[DOMAIN].get(entry.entry_id) - if not coordinator: + if not (coordinator := hass.data[DOMAIN].get(entry.entry_id)): # Create IPP instance for this entry coordinator = IPPDataUpdateCoordinator( hass, diff --git a/homeassistant/components/mpd/media_player.py b/homeassistant/components/mpd/media_player.py index baf57844eaf..c89378f20de 100644 --- a/homeassistant/components/mpd/media_player.py +++ b/homeassistant/components/mpd/media_player.py @@ -140,9 +140,7 @@ class MpdDevice(MediaPlayerEntity): self._status = await self._client.status() self._currentsong = await self._client.currentsong() - position = self._status.get("elapsed") - - if position is None: + if (position := self._status.get("elapsed")) is None: position = self._status.get("time") if isinstance(position, str) and ":" in position: @@ -257,16 +255,14 @@ class MpdDevice(MediaPlayerEntity): @property def media_image_hash(self): """Hash value for media image.""" - file = self._currentsong.get("file") - if file: + if file := self._currentsong.get("file"): return hashlib.sha256(file.encode("utf-8")).hexdigest()[:16] return None async def async_get_media_image(self): """Fetch media image of current playing track.""" - file = self._currentsong.get("file") - if not file: + if not (file := self._currentsong.get("file")): return None, None # not all MPD implementations and versions support the `albumart` and `fetchpicture` commands diff --git a/homeassistant/components/pushover/notify.py b/homeassistant/components/pushover/notify.py index 3f599ac2d8a..8a18597c2ca 100644 --- a/homeassistant/components/pushover/notify.py +++ b/homeassistant/components/pushover/notify.py @@ -68,9 +68,8 @@ class PushoverNotificationService(BaseNotificationService): sound = data.get(ATTR_SOUND) html = 1 if data.get(ATTR_HTML, False) else 0 - image = data.get(ATTR_ATTACHMENT) # Check for attachment - if image is not None: + if (image := data.get(ATTR_ATTACHMENT)) is not None: # Only allow attachments from whitelisted paths, check valid path if self._hass.config.is_allowed_path(data[ATTR_ATTACHMENT]): # try to open it as a normal file. diff --git a/homeassistant/components/raspihats/__init__.py b/homeassistant/components/raspihats/__init__.py index c9e862a0672..478bd9147ef 100644 --- a/homeassistant/components/raspihats/__init__.py +++ b/homeassistant/components/raspihats/__init__.py @@ -118,8 +118,7 @@ class I2CHatsManager(threading.Thread): def register_board(self, board, address): """Register I2C-HAT.""" with self._lock: - i2c_hat = self._i2c_hats.get(address) - if i2c_hat is None: + if (i2c_hat := self._i2c_hats.get(address)) is None: # This is a Pi module and can't be installed in CI without # breaking the build. # pylint: disable=import-outside-toplevel,import-error diff --git a/homeassistant/components/sabnzbd/__init__.py b/homeassistant/components/sabnzbd/__init__.py index f6e15bd074c..f2b1ce882c7 100644 --- a/homeassistant/components/sabnzbd/__init__.py +++ b/homeassistant/components/sabnzbd/__init__.py @@ -206,8 +206,7 @@ async def async_setup(hass, config): discovery.async_listen(hass, SERVICE_SABNZBD, sabnzbd_discovered) - conf = config.get(DOMAIN) - if conf is not None: + if (conf := config.get(DOMAIN)) is not None: use_ssl = conf[CONF_SSL] name = conf.get(CONF_NAME) api_key = conf.get(CONF_API_KEY) diff --git a/homeassistant/components/scrape/sensor.py b/homeassistant/components/scrape/sensor.py index 1f5b543f9ee..2e118bf744f 100644 --- a/homeassistant/components/scrape/sensor.py +++ b/homeassistant/components/scrape/sensor.py @@ -66,8 +66,8 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= unit = config.get(CONF_UNIT_OF_MEASUREMENT) username = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) - value_template = config.get(CONF_VALUE_TEMPLATE) - if value_template is not None: + + if (value_template := config.get(CONF_VALUE_TEMPLATE)) is not None: value_template.hass = hass if username and password: diff --git a/homeassistant/components/serial/sensor.py b/homeassistant/components/serial/sensor.py index cbdba50b6b6..37d9c689ce7 100644 --- a/homeassistant/components/serial/sensor.py +++ b/homeassistant/components/serial/sensor.py @@ -81,8 +81,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= rtscts = config.get(CONF_RTSCTS) dsrdtr = config.get(CONF_DSRDTR) - value_template = config.get(CONF_VALUE_TEMPLATE) - if value_template is not None: + if (value_template := config.get(CONF_VALUE_TEMPLATE)) is not None: value_template.hass = hass sensor = SerialSensor( diff --git a/homeassistant/components/songpal/__init__.py b/homeassistant/components/songpal/__init__.py index 2053d2857c2..eb93dafb123 100644 --- a/homeassistant/components/songpal/__init__.py +++ b/homeassistant/components/songpal/__init__.py @@ -24,8 +24,7 @@ PLATFORMS = ["media_player"] async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up songpal environment.""" - conf = config.get(DOMAIN) - if conf is None: + if (conf := config.get(DOMAIN)) is None: return True for config_entry in conf: hass.async_create_task( diff --git a/homeassistant/components/supla/__init__.py b/homeassistant/components/supla/__init__.py index c8862a37b61..51e6c377bdc 100644 --- a/homeassistant/components/supla/__init__.py +++ b/homeassistant/components/supla/__init__.py @@ -190,8 +190,7 @@ class SuplaChannel(CoordinatorEntity): """Return True if entity is available.""" if self.channel_data is None: return False - state = self.channel_data.get("state") - if state is None: + if (state := self.channel_data.get("state")) is None: return False return state.get("connected") diff --git a/homeassistant/components/supla/cover.py b/homeassistant/components/supla/cover.py index ac71bc4ea8f..a4c2fc95792 100644 --- a/homeassistant/components/supla/cover.py +++ b/homeassistant/components/supla/cover.py @@ -59,8 +59,7 @@ class SuplaCover(SuplaChannel, CoverEntity): @property def current_cover_position(self): """Return current position of cover. 0 is closed, 100 is open.""" - state = self.channel_data.get("state") - if state: + if state := self.channel_data.get("state"): return 100 - state["shut"] return None diff --git a/homeassistant/components/supla/switch.py b/homeassistant/components/supla/switch.py index 9122d9d1970..32ff208f10e 100644 --- a/homeassistant/components/supla/switch.py +++ b/homeassistant/components/supla/switch.py @@ -49,7 +49,6 @@ class SuplaSwitch(SuplaChannel, SwitchEntity): @property def is_on(self): """Return true if switch is on.""" - state = self.channel_data.get("state") - if state: + if state := self.channel_data.get("state"): return state["on"] return False diff --git a/homeassistant/components/watson_iot/__init__.py b/homeassistant/components/watson_iot/__init__.py index 99f6b63ec90..8b81a9d741b 100644 --- a/homeassistant/components/watson_iot/__init__.py +++ b/homeassistant/components/watson_iot/__init__.py @@ -177,9 +177,7 @@ class WatsonIOTThread(threading.Thread): events = [] try: - item = self.queue.get() - - if item is None: + if (item := self.queue.get()) is None: self.shutdown = True else: event_json = self.event_to_json(item[1]) diff --git a/homeassistant/components/whirlpool/climate.py b/homeassistant/components/whirlpool/climate.py index ccfa11b3ee4..eb1b88dcc13 100644 --- a/homeassistant/components/whirlpool/climate.py +++ b/homeassistant/components/whirlpool/climate.py @@ -156,8 +156,7 @@ class AirConEntity(ClimateEntity): await self._aircon.set_power_on(False) return - mode = HVAC_MODE_TO_AIRCON_MODE.get(hvac_mode) - if not mode: + if not (mode := HVAC_MODE_TO_AIRCON_MODE.get(hvac_mode)): raise ValueError(f"Invalid hvac mode {hvac_mode}") await self._aircon.set_mode(mode) @@ -172,8 +171,7 @@ class AirConEntity(ClimateEntity): async def async_set_fan_mode(self, fan_mode): """Set fan mode.""" - fanspeed = FAN_MODE_TO_AIRCON_FANSPEED.get(fan_mode) - if not fanspeed: + if not (fanspeed := FAN_MODE_TO_AIRCON_FANSPEED.get(fan_mode)): raise ValueError(f"Invalid fan mode {fan_mode}") await self._aircon.set_fanspeed(fanspeed) diff --git a/homeassistant/components/wirelesstag/__init__.py b/homeassistant/components/wirelesstag/__init__.py index 519663d1261..24afb6b0465 100644 --- a/homeassistant/components/wirelesstag/__init__.py +++ b/homeassistant/components/wirelesstag/__init__.py @@ -199,8 +199,7 @@ class WirelessTagBaseSensor(Entity): return updated_tags = self._api.load_tags() - updated_tag = updated_tags[self._uuid] - if updated_tag is None: + if (updated_tag := updated_tags[self._uuid]) is None: _LOGGER.error('Unable to update tag: "%s"', self.name) return