diff --git a/homeassistant/components/alexa/smart_home_http.py b/homeassistant/components/alexa/smart_home_http.py index 6d6b9f54533..df4f95f12f2 100644 --- a/homeassistant/components/alexa/smart_home_http.py +++ b/homeassistant/components/alexa/smart_home_http.py @@ -70,8 +70,7 @@ class AlexaConfig(AbstractConfig): return self._config[CONF_FILTER](entity_id) 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/august/config_flow.py b/homeassistant/components/august/config_flow.py index af048f9dc46..eb7bac9ae1a 100644 --- a/homeassistant/components/august/config_flow.py +++ b/homeassistant/components/august/config_flow.py @@ -14,20 +14,14 @@ from .gateway import AugustGateway _LOGGER = logging.getLogger(__name__) -async def async_validate_input( - data, - august_gateway, -): +async def async_validate_input(data, august_gateway): """Validate the user input allows us to connect. Data has the keys from DATA_SCHEMA with values provided by the user. Request configuration steps from the user. """ - - code = data.get(VERIFICATION_CODE_KEY) - - if code is not None: + if (code := data.get(VERIFICATION_CODE_KEY)) is not None: result = await august_gateway.authenticator.async_validate_verification_code( code ) diff --git a/homeassistant/components/azure_service_bus/notify.py b/homeassistant/components/azure_service_bus/notify.py index e7c85adede8..0d48ff6b2d6 100644 --- a/homeassistant/components/azure_service_bus/notify.py +++ b/homeassistant/components/azure_service_bus/notify.py @@ -90,8 +90,7 @@ class ServiceBusNotificationService(BaseNotificationService): if ATTR_TARGET in kwargs: dto[ATTR_ASB_TARGET] = kwargs[ATTR_TARGET] - data = kwargs.get(ATTR_DATA) - if data: + if data := kwargs.get(ATTR_DATA): dto.update(data) queue_message = Message(json.dumps(dto)) diff --git a/homeassistant/components/bluesound/media_player.py b/homeassistant/components/bluesound/media_player.py index 86d0be72bdc..04261a4137c 100644 --- a/homeassistant/components/bluesound/media_player.py +++ b/homeassistant/components/bluesound/media_player.py @@ -160,8 +160,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= ) return - hosts = config.get(CONF_HOSTS) - if hosts: + if hosts := config.get(CONF_HOSTS): for host in hosts: _add_player( hass, @@ -173,15 +172,13 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= async def async_service_handler(service): """Map services to method of Bluesound devices.""" - method = SERVICE_TO_METHOD.get(service.service) - if not method: + if not (method := SERVICE_TO_METHOD.get(service.service)): return params = { key: value for key, value in service.data.items() if key != ATTR_ENTITY_ID } - entity_ids = service.data.get(ATTR_ENTITY_ID) - if entity_ids: + if entity_ids := service.data.get(ATTR_ENTITY_ID): target_players = [ player for player in hass.data[DATA_BLUESOUND] @@ -259,8 +256,7 @@ class BluesoundPlayer(MediaPlayerEntity): if not self._icon: self._icon = self._sync_status.get("@icon", self.host) - master = self._sync_status.get("master") - if master is not None: + if (master := self._sync_status.get("master")) is not None: self._is_master = False master_host = master.get("#text") master_device = [ @@ -580,8 +576,7 @@ class BluesoundPlayer(MediaPlayerEntity): if self.is_grouped and not self.is_master: return self._group_name - artist = self._status.get("artist") - if not artist: + if not (artist := self._status.get("artist")): artist = self._status.get("title2") return artist @@ -591,8 +586,7 @@ class BluesoundPlayer(MediaPlayerEntity): if self._status is None or (self.is_grouped and not self.is_master): return None - album = self._status.get("album") - if not album: + if not (album := self._status.get("album")): album = self._status.get("title3") return album @@ -602,8 +596,7 @@ class BluesoundPlayer(MediaPlayerEntity): if self._status is None or (self.is_grouped and not self.is_master): return None - url = self._status.get("image") - if not url: + if not (url := self._status.get("image")): return if url[0] == "/": url = f"http://{self.host}:{self.port}{url}" @@ -620,8 +613,7 @@ class BluesoundPlayer(MediaPlayerEntity): if self._last_status_update is None or mediastate == STATE_IDLE: return None - position = self._status.get("secs") - if position is None: + if (position := self._status.get("secs")) is None: return None position = float(position) @@ -636,8 +628,7 @@ class BluesoundPlayer(MediaPlayerEntity): if self._status is None or (self.is_grouped and not self.is_master): return None - duration = self._status.get("totlen") - if duration is None: + if (duration := self._status.get("totlen")) is None: return None return float(duration) @@ -712,8 +703,7 @@ class BluesoundPlayer(MediaPlayerEntity): if self._status is None or (self.is_grouped and not self.is_master): return None - current_service = self._status.get("service", "") - if current_service == "": + if (current_service := self._status.get("service", "")) == "": return "" stream_url = self._status.get("streamUrl", "") diff --git a/homeassistant/components/environment_canada/sensor.py b/homeassistant/components/environment_canada/sensor.py index 8e4c1483261..48c9ed57dee 100644 --- a/homeassistant/components/environment_canada/sensor.py +++ b/homeassistant/components/environment_canada/sensor.py @@ -140,8 +140,7 @@ class ECSensor(SensorEntity): else: self._unit = sensor_data.get("unit") - timestamp = metadata.get("timestamp") - if timestamp: + if timestamp := metadata.get("timestamp"): updated_utc = datetime.strptime(timestamp, "%Y%m%d%H%M%S").isoformat() else: updated_utc = None diff --git a/homeassistant/components/fritzbox/config_flow.py b/homeassistant/components/fritzbox/config_flow.py index 3ae3368f4ae..bcf17a1a958 100644 --- a/homeassistant/components/fritzbox/config_flow.py +++ b/homeassistant/components/fritzbox/config_flow.py @@ -125,8 +125,7 @@ class FritzboxConfigFlow(ConfigFlow, domain=DOMAIN): assert isinstance(host, str) self.context[CONF_HOST] = host - uuid = discovery_info.get(ATTR_UPNP_UDN) - if uuid: + if uuid := discovery_info.get(ATTR_UPNP_UDN): if uuid.startswith("uuid:"): uuid = uuid[5:] await self.async_set_unique_id(uuid) diff --git a/homeassistant/components/hangouts/__init__.py b/homeassistant/components/hangouts/__init__.py index 04814a9c3e9..820aab8cb73 100644 --- a/homeassistant/components/hangouts/__init__.py +++ b/homeassistant/components/hangouts/__init__.py @@ -57,8 +57,7 @@ CONFIG_SCHEMA = vol.Schema( async def async_setup(hass, config): """Set up the Hangouts bot component.""" - config = config.get(DOMAIN) - if config is None: + if (config := config.get(DOMAIN)) is None: hass.data[DOMAIN] = { CONF_INTENTS: {}, CONF_DEFAULT_CONVERSATIONS: [], diff --git a/homeassistant/components/life360/device_tracker.py b/homeassistant/components/life360/device_tracker.py index 6697dd50893..f293ab2aca3 100644 --- a/homeassistant/components/life360/device_tracker.py +++ b/homeassistant/components/life360/device_tracker.py @@ -211,8 +211,7 @@ class Life360Scanner: prev_seen = self._prev_seen(dev_id, last_seen) if not loc: - err_msg = member["issues"]["title"] - if err_msg: + if err_msg := member["issues"]["title"]: if member["issues"]["dialog"]: err_msg += f": {member['issues']['dialog']}" else: diff --git a/homeassistant/components/onvif/event.py b/homeassistant/components/onvif/event.py index f76efb2bc8e..fcb8e39cf54 100644 --- a/homeassistant/components/onvif/event.py +++ b/homeassistant/components/onvif/event.py @@ -208,8 +208,7 @@ class EventManager: continue topic = msg.Topic._value_1 - parser = PARSERS.get(topic) - if not parser: + if not (parser := PARSERS.get(topic)): if topic not in UNHANDLED_TOPICS: LOGGER.info( "No registered handler for event from %s: %s", diff --git a/homeassistant/components/proximity/__init__.py b/homeassistant/components/proximity/__init__.py index 1840162f896..eb64de56df5 100644 --- a/homeassistant/components/proximity/__init__.py +++ b/homeassistant/components/proximity/__init__.py @@ -164,9 +164,7 @@ class Proximity(Entity): # Check for devices in the monitored zone. for device in self.proximity_devices: - device_state = self.hass.states.get(device) - - if device_state is None: + if (device_state := self.hass.states.get(device)) is None: devices_to_calculate = True continue diff --git a/homeassistant/components/radiotherm/climate.py b/homeassistant/components/radiotherm/climate.py index 112e9f3a76d..d68072229ac 100644 --- a/homeassistant/components/radiotherm/climate.py +++ b/homeassistant/components/radiotherm/climate.py @@ -201,8 +201,7 @@ class RadioThermostat(ClimateEntity): def set_fan_mode(self, fan_mode): """Turn fan on/off.""" - code = FAN_MODE_TO_CODE.get(fan_mode) - if code is not None: + if (code := FAN_MODE_TO_CODE.get(fan_mode)) is not None: self.device.fmode = code @property @@ -322,8 +321,7 @@ class RadioThermostat(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 temperature = round_temp(temperature) diff --git a/homeassistant/components/roku/__init__.py b/homeassistant/components/roku/__init__.py index 55da7484aba..f1c30ec2af7 100644 --- a/homeassistant/components/roku/__init__.py +++ b/homeassistant/components/roku/__init__.py @@ -24,8 +24,7 @@ _LOGGER = logging.getLogger(__name__) async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Roku 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)): coordinator = RokuDataUpdateCoordinator(hass, host=entry.data[CONF_HOST]) hass.data[DOMAIN][entry.entry_id] = coordinator diff --git a/homeassistant/components/script/__init__.py b/homeassistant/components/script/__init__.py index f3f34a0ad53..b07cc2325b1 100644 --- a/homeassistant/components/script/__init__.py +++ b/homeassistant/components/script/__init__.py @@ -404,8 +404,7 @@ class ScriptEntity(ToggleEntity, RestoreEntity): script_trace.set_trace(trace_get()) with trace_path("sequence"): this = None - state = self.hass.states.get(self.entity_id) - if state: + if state := self.hass.states.get(self.entity_id): this = state.as_dict() script_vars = {"this": this, **(variables or {})} return await self.script.async_run(script_vars, context) diff --git a/homeassistant/components/tibber/sensor.py b/homeassistant/components/tibber/sensor.py index 120432e0608..9a19e5a7602 100644 --- a/homeassistant/components/tibber/sensor.py +++ b/homeassistant/components/tibber/sensor.py @@ -446,8 +446,7 @@ class TibberRtDataCoordinator(update_coordinator.DataUpdateCoordinator): def get_live_measurement(self): """Get live measurement data.""" - errors = self.data.get("errors") - if errors: + if errors := self.data.get("errors"): _LOGGER.error(errors[0]) return None return self.data.get("data", {}).get("liveMeasurement") diff --git a/homeassistant/components/tplink/config_flow.py b/homeassistant/components/tplink/config_flow.py index d9bed10ee42..8abc00d7fdb 100644 --- a/homeassistant/components/tplink/config_flow.py +++ b/homeassistant/components/tplink/config_flow.py @@ -89,8 +89,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Handle the initial step.""" errors = {} if user_input is not None: - host = user_input[CONF_HOST] - if not host: + if not (host := user_input[CONF_HOST]): return await self.async_step_pick_device() try: device = await self._async_try_connect(host, raise_on_progress=False) diff --git a/homeassistant/components/trend/binary_sensor.py b/homeassistant/components/trend/binary_sensor.py index 52a72eca8c9..302201b5516 100644 --- a/homeassistant/components/trend/binary_sensor.py +++ b/homeassistant/components/trend/binary_sensor.py @@ -169,8 +169,7 @@ class SensorTrend(BinarySensorEntity): @callback def trend_sensor_state_listener(event): """Handle state changes on the observed device.""" - new_state = event.data.get("new_state") - if new_state is None: + if (new_state := event.data.get("new_state")) is None: return try: if self._attribute: diff --git a/homeassistant/components/xmpp/notify.py b/homeassistant/components/xmpp/notify.py index 29624f37ffa..1e022c9e72f 100644 --- a/homeassistant/components/xmpp/notify.py +++ b/homeassistant/components/xmpp/notify.py @@ -313,8 +313,7 @@ async def async_send_message( # noqa: C901 filesize = len(input_file) _LOGGER.debug("Filesize is %s bytes", filesize) - content_type = mimetypes.guess_type(path)[0] - if content_type is None: + if (content_type := mimetypes.guess_type(path)[0]) is None: content_type = DEFAULT_CONTENT_TYPE _LOGGER.debug("Content type is %s", content_type) diff --git a/homeassistant/components/yeelight/light.py b/homeassistant/components/yeelight/light.py index abe1285f609..67f55c7f737 100644 --- a/homeassistant/components/yeelight/light.py +++ b/homeassistant/components/yeelight/light.py @@ -1075,9 +1075,7 @@ class YeelightAmbientLight(YeelightColorLightWithoutNightlightSwitch): return "bright" def _get_property(self, prop, default=None): - bg_prop = self.PROPERTIES_MAPPING.get(prop) - - if not bg_prop: + if not (bg_prop := self.PROPERTIES_MAPPING.get(prop)): bg_prop = f"bg_{prop}" return super()._get_property(bg_prop, default)