diff --git a/homeassistant/components/cast/__init__.py b/homeassistant/components/cast/__init__.py index 43b6b77ebd2..9ccac6e4f6c 100644 --- a/homeassistant/components/cast/__init__.py +++ b/homeassistant/components/cast/__init__.py @@ -18,9 +18,7 @@ _LOGGER = logging.getLogger(__name__) async def async_setup(hass, config): """Set up the Cast component.""" - conf = config.get(DOMAIN) - - if conf is not None: + if (conf := config.get(DOMAIN)) is not None: media_player_config_validated = [] media_player_config = conf.get("media_player", {}) if not isinstance(media_player_config, list): diff --git a/homeassistant/components/cast/media_player.py b/homeassistant/components/cast/media_player.py index 74c90f43372..57983808cbd 100644 --- a/homeassistant/components/cast/media_player.py +++ b/homeassistant/components/cast/media_player.py @@ -565,9 +565,7 @@ class CastDevice(MediaPlayerEntity): @property def state(self): """Return the state of the player.""" - media_status = self._media_status()[0] - - if media_status is None: + if (media_status := self._media_status()[0]) is None: return None if media_status.player_is_playing: return STATE_PLAYING @@ -588,8 +586,7 @@ class CastDevice(MediaPlayerEntity): @property def media_content_type(self): """Content type of current playing media.""" - media_status = self._media_status()[0] - if media_status is None: + if (media_status := self._media_status()[0]) is None: return None if media_status.media_is_tvshow: return MEDIA_TYPE_TVSHOW @@ -608,8 +605,7 @@ class CastDevice(MediaPlayerEntity): @property def media_image_url(self): """Image url of current playing media.""" - media_status = self._media_status()[0] - if media_status is None: + if (media_status := self._media_status()[0]) is None: return None images = media_status.images diff --git a/homeassistant/components/conversation/__init__.py b/homeassistant/components/conversation/__init__.py index 4d3297d8c65..401d240957e 100644 --- a/homeassistant/components/conversation/__init__.py +++ b/homeassistant/components/conversation/__init__.py @@ -154,8 +154,7 @@ class ConversationProcessView(http.HomeAssistantView): async def _get_agent(hass: core.HomeAssistant) -> AbstractConversationAgent: """Get the active conversation agent.""" - agent = hass.data.get(DATA_AGENT) - if agent is None: + if (agent := hass.data.get(DATA_AGENT)) is None: agent = hass.data[DATA_AGENT] = DefaultAgent(hass) await agent.async_initialize(hass.data.get(DATA_CONFIG)) return agent diff --git a/homeassistant/components/conversation/default_agent.py b/homeassistant/components/conversation/default_agent.py index 1773ca46cb5..d957eb8e0b2 100644 --- a/homeassistant/components/conversation/default_agent.py +++ b/homeassistant/components/conversation/default_agent.py @@ -66,9 +66,7 @@ class DefaultAgent(AbstractConversationAgent): intents = self.hass.data.setdefault(DOMAIN, {}) for intent_type, utterances in config.get("intents", {}).items(): - conf = intents.get(intent_type) - - if conf is None: + if (conf := intents.get(intent_type)) is None: conf = intents[intent_type] = [] conf.extend(create_matcher(utterance) for utterance in utterances) diff --git a/homeassistant/components/insteon/api/aldb.py b/homeassistant/components/insteon/api/aldb.py index 881cb0bb8c7..a3132570ccc 100644 --- a/homeassistant/components/insteon/api/aldb.py +++ b/homeassistant/components/insteon/api/aldb.py @@ -73,8 +73,7 @@ async def websocket_get_aldb( msg: dict, ) -> None: """Get the All-Link Database for an Insteon device.""" - device = devices[msg[DEVICE_ADDRESS]] - if not device: + if not (device := devices[msg[DEVICE_ADDRESS]]): notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND) return @@ -110,8 +109,7 @@ async def websocket_change_aldb_record( msg: dict, ) -> None: """Change an All-Link Database record for an Insteon device.""" - device = devices[msg[DEVICE_ADDRESS]] - if not device: + if not (device := devices[msg[DEVICE_ADDRESS]]): notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND) return @@ -144,8 +142,7 @@ async def websocket_create_aldb_record( msg: dict, ) -> None: """Create an All-Link Database record for an Insteon device.""" - device = devices[msg[DEVICE_ADDRESS]] - if not device: + if not (device := devices[msg[DEVICE_ADDRESS]]): notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND) return @@ -175,8 +172,7 @@ async def websocket_write_aldb( msg: dict, ) -> None: """Create an All-Link Database record for an Insteon device.""" - device = devices[msg[DEVICE_ADDRESS]] - if not device: + if not (device := devices[msg[DEVICE_ADDRESS]]): notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND) return @@ -199,8 +195,7 @@ async def websocket_load_aldb( msg: dict, ) -> None: """Create an All-Link Database record for an Insteon device.""" - device = devices[msg[DEVICE_ADDRESS]] - if not device: + if not (device := devices[msg[DEVICE_ADDRESS]]): notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND) return @@ -222,8 +217,7 @@ async def websocket_reset_aldb( msg: dict, ) -> None: """Create an All-Link Database record for an Insteon device.""" - device = devices[msg[DEVICE_ADDRESS]] - if not device: + if not (device := devices[msg[DEVICE_ADDRESS]]): notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND) return @@ -245,8 +239,7 @@ async def websocket_add_default_links( msg: dict, ) -> None: """Add the default All-Link Database records for an Insteon device.""" - device = devices[msg[DEVICE_ADDRESS]] - if not device: + if not (device := devices[msg[DEVICE_ADDRESS]]): notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND) return @@ -270,9 +263,7 @@ async def websocket_notify_on_aldb_status( msg: dict, ) -> None: """Tell Insteon a new ALDB record was added.""" - - device = devices[msg[DEVICE_ADDRESS]] - if not device: + if not (device := devices[msg[DEVICE_ADDRESS]]): notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND) return diff --git a/homeassistant/components/insteon/api/device.py b/homeassistant/components/insteon/api/device.py index 9d77e8b765c..6815ec43031 100644 --- a/homeassistant/components/insteon/api/device.py +++ b/homeassistant/components/insteon/api/device.py @@ -35,8 +35,7 @@ async def async_device_name(dev_registry, address): identifiers={(DOMAIN, str(address))}, connections=set() ) if not ha_device: - device = devices[address] - if device: + if device := devices[address]: return f"{device.description} ({device.model})" return "" return compute_device_name(ha_device) @@ -61,8 +60,7 @@ async def websocket_get_device( ) -> None: """Get an Insteon device.""" dev_registry = await hass.helpers.device_registry.async_get_registry() - ha_device = dev_registry.async_get(msg[DEVICE_ID]) - if not ha_device: + if not (ha_device := dev_registry.async_get(msg[DEVICE_ID])): notify_device_not_found(connection, msg, HA_DEVICE_NOT_FOUND) return device = get_insteon_device_from_ha_device(ha_device) diff --git a/homeassistant/components/insteon/api/properties.py b/homeassistant/components/insteon/api/properties.py index 0b3b643b617..6ec12a5fd89 100644 --- a/homeassistant/components/insteon/api/properties.py +++ b/homeassistant/components/insteon/api/properties.py @@ -295,8 +295,7 @@ async def websocket_get_properties( msg: dict, ) -> None: """Add the default All-Link Database records for an Insteon device.""" - device = devices[msg[DEVICE_ADDRESS]] - if not device: + if not (device := devices[msg[DEVICE_ADDRESS]]): notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND) return @@ -321,8 +320,7 @@ async def websocket_change_properties_record( msg: dict, ) -> None: """Add the default All-Link Database records for an Insteon device.""" - device = devices[msg[DEVICE_ADDRESS]] - if not device: + if not (device := devices[msg[DEVICE_ADDRESS]]): notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND) return @@ -344,8 +342,7 @@ async def websocket_write_properties( msg: dict, ) -> None: """Add the default All-Link Database records for an Insteon device.""" - device = devices[msg[DEVICE_ADDRESS]] - if not device: + if not (device := devices[msg[DEVICE_ADDRESS]]): notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND) return @@ -376,8 +373,7 @@ async def websocket_load_properties( msg: dict, ) -> None: """Add the default All-Link Database records for an Insteon device.""" - device = devices[msg[DEVICE_ADDRESS]] - if not device: + if not (device := devices[msg[DEVICE_ADDRESS]]): notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND) return @@ -408,8 +404,7 @@ async def websocket_reset_properties( msg: dict, ) -> None: """Add the default All-Link Database records for an Insteon device.""" - device = devices[msg[DEVICE_ADDRESS]] - if not device: + if not (device := devices[msg[DEVICE_ADDRESS]]): notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND) return diff --git a/homeassistant/components/insteon/schemas.py b/homeassistant/components/insteon/schemas.py index 626dc7dde4b..09315919052 100644 --- a/homeassistant/components/insteon/schemas.py +++ b/homeassistant/components/insteon/schemas.py @@ -57,8 +57,7 @@ def set_default_port(schema: dict) -> dict: """Set the default port based on the Hub version.""" # If the ip_port is found do nothing # If it is not found the set the default - ip_port = schema.get(CONF_IP_PORT) - if not ip_port: + if not schema.get(CONF_IP_PORT): hub_version = schema.get(CONF_HUB_VERSION) # Found hub_version but not ip_port schema[CONF_IP_PORT] = PORT_HUB_V1 if hub_version == 1 else PORT_HUB_V2 diff --git a/homeassistant/components/openuv/binary_sensor.py b/homeassistant/components/openuv/binary_sensor.py index 4d10aa53a39..913d844a7c3 100644 --- a/homeassistant/components/openuv/binary_sensor.py +++ b/homeassistant/components/openuv/binary_sensor.py @@ -45,9 +45,7 @@ class OpenUvBinarySensor(OpenUvEntity, BinarySensorEntity): @callback def update_from_latest_data(self) -> None: """Update the state.""" - data = self.openuv.data[DATA_PROTECTION_WINDOW] - - if not data: + if not (data := self.openuv.data[DATA_PROTECTION_WINDOW]): self._attr_available = False return diff --git a/homeassistant/components/openuv/sensor.py b/homeassistant/components/openuv/sensor.py index 2eac6ba41b2..f1d0ba9e0b1 100644 --- a/homeassistant/components/openuv/sensor.py +++ b/homeassistant/components/openuv/sensor.py @@ -134,9 +134,7 @@ class OpenUvSensor(OpenUvEntity, SensorEntity): @callback def update_from_latest_data(self) -> None: """Update the state.""" - data = self.openuv.data[DATA_UV].get("result") - - if not data: + if not (data := self.openuv.data[DATA_UV].get("result")): self._attr_available = False return diff --git a/homeassistant/components/sms/__init__.py b/homeassistant/components/sms/__init__.py index e2904825bbb..358f608be58 100644 --- a/homeassistant/components/sms/__init__.py +++ b/homeassistant/components/sms/__init__.py @@ -21,8 +21,7 @@ CONFIG_SCHEMA = vol.Schema( async def async_setup(hass, config): """Configure Gammu state machine.""" hass.data.setdefault(DOMAIN, {}) - sms_config = config.get(DOMAIN, {}) - if not sms_config: + if not (sms_config := config.get(DOMAIN, {})): return True hass.async_create_task( diff --git a/homeassistant/components/sql/sensor.py b/homeassistant/components/sql/sensor.py index 1b0ae5a9076..bcf7aea8e14 100644 --- a/homeassistant/components/sql/sensor.py +++ b/homeassistant/components/sql/sensor.py @@ -51,8 +51,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the SQL sensor platform.""" - db_url = config.get(CONF_DB_URL) - if not db_url: + if not (db_url := config.get(CONF_DB_URL)): db_url = DEFAULT_URL.format(hass_config_path=hass.config.path(DEFAULT_DB_FILE)) sess = None diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index 7380f15b983..36480e90f12 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -143,8 +143,7 @@ class LgWebOSMediaPlayerEntity(MediaPlayerEntity): async def async_signal_handler(self, data): """Handle domain-specific signal by calling appropriate method.""" - entity_ids = data[ATTR_ENTITY_ID] - if entity_ids == ENTITY_MATCH_NONE: + if (entity_ids := data[ATTR_ENTITY_ID]) == ENTITY_MATCH_NONE: return if entity_ids == ENTITY_MATCH_ALL or self.entity_id in entity_ids: @@ -368,8 +367,7 @@ class LgWebOSMediaPlayerEntity(MediaPlayerEntity): @cmd async def async_select_source(self, source): """Select input source.""" - source_dict = self._source_list.get(source) - if source_dict is None: + if (source_dict := self._source_list.get(source)) is None: _LOGGER.warning("Source %s not found for %s", source, self.name) return if source_dict.get("title"): diff --git a/homeassistant/components/wilight/fan.py b/homeassistant/components/wilight/fan.py index e55413926ac..b549eb2f813 100644 --- a/homeassistant/components/wilight/fan.py +++ b/homeassistant/components/wilight/fan.py @@ -86,8 +86,7 @@ class WiLightFan(WiLightDevice, FanEntity): ): return 0 - wl_speed = self._status.get("speed") - if wl_speed is None: + if (wl_speed := self._status.get("speed")) is None: return None return ordered_list_item_to_percentage(ORDERED_NAMED_FAN_SPEEDS, wl_speed)