diff --git a/homeassistant/components/avion/light.py b/homeassistant/components/avion/light.py index fcc780f77bcc..0bf1787aac73 100644 --- a/homeassistant/components/avion/light.py +++ b/homeassistant/components/avion/light.py @@ -95,9 +95,7 @@ class AvionLight(LightEntity): def turn_on(self, **kwargs): """Turn the specified or all lights on.""" - brightness = kwargs.get(ATTR_BRIGHTNESS) - - if brightness is not None: + if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is not None: self._attr_brightness = brightness self.set_state(self.brightness) diff --git a/homeassistant/components/aws/__init__.py b/homeassistant/components/aws/__init__.py index da8c27d74455..6dcbad748cc3 100644 --- a/homeassistant/components/aws/__init__.py +++ b/homeassistant/components/aws/__init__.py @@ -85,8 +85,7 @@ async def async_setup(hass, config): """Set up AWS component.""" hass.data[DATA_HASS_CONFIG] = config - conf = config.get(DOMAIN) - if conf is None: + if (conf := config.get(DOMAIN)) is None: # create a default conf using default profile conf = CONFIG_SCHEMA({ATTR_CREDENTIALS: DEFAULT_CREDENTIAL}) @@ -159,9 +158,7 @@ async def _validate_aws_credentials(hass, credential): del aws_config[CONF_NAME] del aws_config[CONF_VALIDATE] - profile = aws_config.get(CONF_PROFILE_NAME) - - if profile is not None: + if (profile := aws_config.get(CONF_PROFILE_NAME)) is not None: session = aiobotocore.AioSession(profile=profile) del aws_config[CONF_PROFILE_NAME] if CONF_ACCESS_KEY_ID in aws_config: diff --git a/homeassistant/components/aws/notify.py b/homeassistant/components/aws/notify.py index c9d6ca2faa72..b271a2a8786e 100644 --- a/homeassistant/components/aws/notify.py +++ b/homeassistant/components/aws/notify.py @@ -82,8 +82,7 @@ async def async_get_service(hass, config, discovery_info=None): del aws_config[CONF_CREDENTIAL_NAME] if session is None: - profile = aws_config.get(CONF_PROFILE_NAME) - if profile is not None: + if (profile := aws_config.get(CONF_PROFILE_NAME)) is not None: session = aiobotocore.AioSession(profile=profile) del aws_config[CONF_PROFILE_NAME] else: diff --git a/homeassistant/components/forked_daapd/media_player.py b/homeassistant/components/forked_daapd/media_player.py index 724db80fabda..aeb2350ce222 100644 --- a/homeassistant/components/forked_daapd/media_player.py +++ b/homeassistant/components/forked_daapd/media_player.py @@ -621,8 +621,7 @@ class ForkedDaapdMaster(MediaPlayerEntity): @property def media_image_url(self): """Image url of current playing media.""" - url = self._track_info.get("artwork_url") - if url: + if url := self._track_info.get("artwork_url"): url = self._api.full_url(url) return url @@ -769,11 +768,10 @@ class ForkedDaapdUpdater: async def async_init(self): """Perform async portion of class initialization.""" server_config = await self._api.get_request("config") - websocket_port = server_config.get("websocket_port") - if websocket_port: + if websocket_port := server_config.get("websocket_port"): self.websocket_handler = asyncio.create_task( self._api.start_websocket_handler( - server_config["websocket_port"], + websocket_port, WS_NOTIFY_EVENT_TYPES, self._update, WEBSOCKET_RECONNECT_TIME, diff --git a/homeassistant/components/here_travel_time/sensor.py b/homeassistant/components/here_travel_time/sensor.py index a47e28179b36..1d47bbaf89f6 100644 --- a/homeassistant/components/here_travel_time/sensor.py +++ b/homeassistant/components/here_travel_time/sensor.py @@ -326,9 +326,7 @@ class HERETravelTimeSensor(SensorEntity): async def _get_location_from_entity(self, entity_id: str) -> str | None: """Get the location from the entity state or attributes.""" - entity = self.hass.states.get(entity_id) - - if entity is None: + if (entity := self.hass.states.get(entity_id)) is None: _LOGGER.error("Unable to find entity %s", entity_id) return None @@ -484,8 +482,7 @@ class HERETravelTimeData: if suppliers is not None: supplier_titles = [] for supplier in suppliers: - title = supplier.get("title") - if title is not None: + if (title := supplier.get("title")) is not None: supplier_titles.append(title) joined_supplier_titles = ",".join(supplier_titles) attribution = f"With the support of {joined_supplier_titles}. All information is provided without warranty of any kind." diff --git a/homeassistant/components/izone/__init__.py b/homeassistant/components/izone/__init__.py index e3f4b62af632..2ac66963638d 100644 --- a/homeassistant/components/izone/__init__.py +++ b/homeassistant/components/izone/__init__.py @@ -28,8 +28,7 @@ CONFIG_SCHEMA = vol.Schema( async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Register the iZone component config.""" - conf = config.get(IZONE) - if not conf: + if not (conf := config.get(IZONE)): return True hass.data[DATA_CONFIG] = conf diff --git a/homeassistant/components/izone/climate.py b/homeassistant/components/izone/climate.py index 06dfee0e7fbc..bd1de0f935e8 100644 --- a/homeassistant/components/izone/climate.py +++ b/homeassistant/components/izone/climate.py @@ -429,8 +429,7 @@ class ControllerDevice(ClimateEntity): if not self.supported_features & SUPPORT_TARGET_TEMPERATURE: self.async_schedule_update_ha_state(True) return - temp = kwargs.get(ATTR_TEMPERATURE) - if temp is not None: + if (temp := kwargs.get(ATTR_TEMPERATURE)) is not None: await self.wrap_and_catch(self._controller.set_temp_setpoint(temp)) async def async_set_fan_mode(self, fan_mode: str) -> None: @@ -627,8 +626,7 @@ class ZoneDevice(ClimateEntity): """Set new target temperature.""" if self._zone.mode != Zone.Mode.AUTO: return - temp = kwargs.get(ATTR_TEMPERATURE) - if temp is not None: + if (temp := kwargs.get(ATTR_TEMPERATURE)) is not None: await self._controller.wrap_and_catch(self._zone.set_temp_setpoint(temp)) async def async_set_hvac_mode(self, hvac_mode: str) -> None: diff --git a/homeassistant/components/izone/discovery.py b/homeassistant/components/izone/discovery.py index 715c87bc7a8c..04b0760261e7 100644 --- a/homeassistant/components/izone/discovery.py +++ b/homeassistant/components/izone/discovery.py @@ -49,8 +49,7 @@ class DiscoveryService(pizone.Listener): async def async_start_discovery_service(hass: HomeAssistant): """Set up the pizone internal discovery.""" - disco = hass.data.get(DATA_DISCOVERY_SERVICE) - if disco: + if disco := hass.data.get(DATA_DISCOVERY_SERVICE): # Already started return disco @@ -75,8 +74,7 @@ async def async_start_discovery_service(hass: HomeAssistant): async def async_stop_discovery_service(hass: HomeAssistant): """Stop the discovery service.""" - disco = hass.data.get(DATA_DISCOVERY_SERVICE) - if not disco: + if not (disco := hass.data.get(DATA_DISCOVERY_SERVICE)): return await disco.pi_disco.close() diff --git a/homeassistant/components/kaiterra/api_data.py b/homeassistant/components/kaiterra/api_data.py index e0f4d817e035..b426a298ddbd 100644 --- a/homeassistant/components/kaiterra/api_data.py +++ b/homeassistant/components/kaiterra/api_data.py @@ -72,9 +72,7 @@ class KaiterraApiData: aqi, main_pollutant = None, None for sensor_name, sensor in device.items(): - points = sensor.get("points") - - if not points: + if not (points := sensor.get("points")): continue point = points[0] diff --git a/homeassistant/components/logentries/__init__.py b/homeassistant/components/logentries/__init__.py index 55d1ab7aae6c..9390bde240a9 100644 --- a/homeassistant/components/logentries/__init__.py +++ b/homeassistant/components/logentries/__init__.py @@ -28,8 +28,7 @@ def setup(hass, config): def logentries_event_listener(event): """Listen for new messages on the bus and sends them to Logentries.""" - state = event.data.get("new_state") - if state is None: + if (state := event.data.get("new_state")) is None: return try: _state = state_helper.state_as_number(state) diff --git a/homeassistant/components/motioneye/__init__.py b/homeassistant/components/motioneye/__init__.py index 51f1e316a87a..b0ee5241ec72 100644 --- a/homeassistant/components/motioneye/__init__.py +++ b/homeassistant/components/motioneye/__init__.py @@ -420,9 +420,8 @@ async def handle_webhook( event_type = data[ATTR_EVENT_TYPE] device_registry = dr.async_get(hass) device_id = data[ATTR_DEVICE_ID] - device = device_registry.async_get(device_id) - if not device: + if not (device := device_registry.async_get(device_id)): return Response( text=f"Device not found: {device_id}", status=HTTPStatus.BAD_REQUEST, diff --git a/homeassistant/components/netgear_lte/__init__.py b/homeassistant/components/netgear_lte/__init__.py index ed4733d66968..3ee4e14d5e1a 100644 --- a/homeassistant/components/netgear_lte/__init__.py +++ b/homeassistant/components/netgear_lte/__init__.py @@ -193,12 +193,9 @@ async def async_setup(hass, config): for sms_id in service.data[ATTR_SMS_ID]: await modem_data.modem.delete_sms(sms_id) elif service.service == SERVICE_SET_OPTION: - failover = service.data.get(ATTR_FAILOVER) - if failover: + if failover := service.data.get(ATTR_FAILOVER): await modem_data.modem.set_failover_mode(failover) - - autoconnect = service.data.get(ATTR_AUTOCONNECT) - if autoconnect: + if autoconnect := service.data.get(ATTR_AUTOCONNECT): await modem_data.modem.set_autoconnect_mode(autoconnect) elif service.service == SERVICE_CONNECT_LTE: await modem_data.modem.connect_lte() diff --git a/homeassistant/components/openhome/media_player.py b/homeassistant/components/openhome/media_player.py index 26393dad179d..d369eeffd8b0 100644 --- a/homeassistant/components/openhome/media_player.py +++ b/homeassistant/components/openhome/media_player.py @@ -263,8 +263,7 @@ class OpenhomeDevice(MediaPlayerEntity): @property def media_artist(self): """Artist of current playing media, music track only.""" - artists = self._track_information.get("artist") - if artists: + if artists := self._track_information.get("artist"): return artists[0] @property diff --git a/homeassistant/components/pilight/binary_sensor.py b/homeassistant/components/pilight/binary_sensor.py index e380d39bef4c..d964739212a5 100644 --- a/homeassistant/components/pilight/binary_sensor.py +++ b/homeassistant/components/pilight/binary_sensor.py @@ -39,8 +39,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def setup_platform(hass, config, add_entities, discovery_info=None): """Set up Pilight Binary Sensor.""" - disarm = config.get(CONF_DISARM_AFTER_TRIGGER) - if disarm: + if config.get(CONF_DISARM_AFTER_TRIGGER): add_entities( [ PilightTriggerSensor( diff --git a/homeassistant/components/proliphix/climate.py b/homeassistant/components/proliphix/climate.py index a293642038e4..da21410f1fce 100644 --- a/homeassistant/components/proliphix/climate.py +++ b/homeassistant/components/proliphix/climate.py @@ -131,7 +131,6 @@ class ProliphixThermostat(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._pdp.setback = temperature diff --git a/homeassistant/components/rocketchat/notify.py b/homeassistant/components/rocketchat/notify.py index efb2288f4d8d..90495cc6eb20 100644 --- a/homeassistant/components/rocketchat/notify.py +++ b/homeassistant/components/rocketchat/notify.py @@ -69,8 +69,7 @@ class RocketChatNotificationService(BaseNotificationService): data = kwargs.get(ATTR_DATA) or {} resp = self._server.chat_post_message(message, channel=self._room, **data) if resp.status_code == HTTP_OK: - success = resp.json()["success"] - if not success: + if not resp.json()["success"]: _LOGGER.error("Unable to post Rocket.Chat message") else: _LOGGER.error( diff --git a/homeassistant/components/smartthings/__init__.py b/homeassistant/components/smartthings/__init__.py index 1913751ba786..44a360a2e55d 100644 --- a/homeassistant/components/smartthings/__init__.py +++ b/homeassistant/components/smartthings/__init__.py @@ -367,8 +367,7 @@ class DeviceBroker: for evt in req.events: if evt.event_type != EVENT_TYPE_DEVICE: continue - device = self.devices.get(evt.device_id) - if not device: + if not (device := self.devices.get(evt.device_id)): continue device.status.apply_attribute_update( evt.component_id, diff --git a/homeassistant/components/smartthings/climate.py b/homeassistant/components/smartthings/climate.py index da9e0fd090ab..baa9ddbc1181 100644 --- a/homeassistant/components/smartthings/climate.py +++ b/homeassistant/components/smartthings/climate.py @@ -184,8 +184,7 @@ class SmartThingsThermostat(SmartThingsEntity, ClimateEntity): async def async_set_temperature(self, **kwargs): """Set new operation mode and target temperatures.""" # Operation state - operation_state = kwargs.get(ATTR_HVAC_MODE) - if operation_state: + if operation_state := kwargs.get(ATTR_HVAC_MODE): mode = STATE_TO_MODE[operation_state] await self._device.set_thermostat_mode(mode, set_status=True) await self.async_update() @@ -235,8 +234,7 @@ class SmartThingsThermostat(SmartThingsEntity, ClimateEntity): supported_modes = self._device.status.supported_thermostat_modes if isinstance(supported_modes, Iterable): for mode in supported_modes: - state = MODE_TO_STATE.get(mode) - if state is not None: + if (state := MODE_TO_STATE.get(mode)) is not None: modes.add(state) else: _LOGGER.debug( @@ -363,8 +361,7 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateEntity): """Set new target temperature.""" tasks = [] # operation mode - operation_mode = kwargs.get(ATTR_HVAC_MODE) - if operation_mode: + if operation_mode := kwargs.get(ATTR_HVAC_MODE): if operation_mode == HVAC_MODE_OFF: tasks.append(self._device.switch_off(set_status=True)) else: @@ -398,8 +395,7 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateEntity): """Update the calculated fields of the AC.""" modes = {HVAC_MODE_OFF} for mode in self._device.status.supported_ac_modes: - state = AC_MODE_TO_STATE.get(mode) - if state is not None: + if (state := AC_MODE_TO_STATE.get(mode)) is not None: modes.add(state) else: _LOGGER.debug( diff --git a/homeassistant/components/smartthings/lock.py b/homeassistant/components/smartthings/lock.py index 601e207a6f5f..4d4c48b1d9b5 100644 --- a/homeassistant/components/smartthings/lock.py +++ b/homeassistant/components/smartthings/lock.py @@ -67,7 +67,6 @@ class SmartThingsLock(SmartThingsEntity, LockEntity): state_attrs["lock_state"] = status.value if isinstance(status.data, dict): for st_attr, ha_attr in ST_LOCK_ATTR_MAP.items(): - data_val = status.data.get(st_attr) - if data_val is not None: + if (data_val := status.data.get(st_attr)) is not None: state_attrs[ha_attr] = data_val return state_attrs diff --git a/homeassistant/components/smartthings/smartapp.py b/homeassistant/components/smartthings/smartapp.py index 0225a17a62c3..36f2610b9813 100644 --- a/homeassistant/components/smartthings/smartapp.py +++ b/homeassistant/components/smartthings/smartapp.py @@ -188,8 +188,7 @@ def setup_smartapp(hass, app): for each SmartThings account that is configured in hass. """ manager = hass.data[DOMAIN][DATA_MANAGER] - smartapp = manager.smartapps.get(app.app_id) - if smartapp: + if smartapp := manager.smartapps.get(app.app_id): # already setup return smartapp smartapp = manager.register(app.app_id, app.webhook_public_key) @@ -206,8 +205,7 @@ async def setup_smartapp_endpoint(hass: HomeAssistant): SmartApps are an extension point within the SmartThings ecosystem and is used to receive push updates (i.e. device updates) from the cloud. """ - data = hass.data.get(DOMAIN) - if data: + if hass.data.get(DOMAIN): # already setup return