diff --git a/homeassistant/components/emulated_roku/__init__.py b/homeassistant/components/emulated_roku/__init__.py index 45c9355603f..32e08342191 100644 --- a/homeassistant/components/emulated_roku/__init__.py +++ b/homeassistant/components/emulated_roku/__init__.py @@ -46,9 +46,7 @@ CONFIG_SCHEMA = vol.Schema( async def async_setup(hass, config): """Set up the emulated roku component.""" - conf = config.get(DOMAIN) - - if conf is None: + if (conf := config.get(DOMAIN)) is None: return True existing_servers = configured_servers(hass) diff --git a/homeassistant/components/ephember/climate.py b/homeassistant/components/ephember/climate.py index 787677a6605..022c91c96f3 100644 --- a/homeassistant/components/ephember/climate.py +++ b/homeassistant/components/ephember/climate.py @@ -161,8 +161,7 @@ class EphEmberThermostat(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 if self._hot_water: diff --git a/homeassistant/components/fjaraskupan/__init__.py b/homeassistant/components/fjaraskupan/__init__.py index ac22e788a6e..40113744977 100644 --- a/homeassistant/components/fjaraskupan/__init__.py +++ b/homeassistant/components/fjaraskupan/__init__.py @@ -64,9 +64,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: "Detection: %s %s - %s", ble_device.name, ble_device, advertisement_data ) - data = state.devices.get(ble_device.address) - - if data: + if data := state.devices.get(ble_device.address): data.device.detection_callback(ble_device, advertisement_data) data.coordinator.async_set_updated_data(data.device.state) else: diff --git a/homeassistant/components/google_travel_time/helpers.py b/homeassistant/components/google_travel_time/helpers.py index cf5f6e8b0af..00d3119e868 100644 --- a/homeassistant/components/google_travel_time/helpers.py +++ b/homeassistant/components/google_travel_time/helpers.py @@ -30,9 +30,7 @@ def resolve_location(hass, logger, loc): def get_location_from_entity(hass, logger, entity_id): """Get the location from the entity state or attributes.""" - entity = hass.states.get(entity_id) - - if entity is None: + if (entity := hass.states.get(entity_id)) is None: logger.error("Unable to find entity %s", entity_id) return None diff --git a/homeassistant/components/graphite/__init__.py b/homeassistant/components/graphite/__init__.py index 9405b576b4d..b63e461e76a 100644 --- a/homeassistant/components/graphite/__init__.py +++ b/homeassistant/components/graphite/__init__.py @@ -149,8 +149,7 @@ class GraphiteFeeder(threading.Thread): def run(self): """Run the process to export the data.""" while True: - event = self._queue.get() - if event == self._quit_object: + if (event := self._queue.get()) == self._quit_object: _LOGGER.debug("Event processing thread stopped") self._queue.task_done() return diff --git a/homeassistant/components/harmony/remote.py b/homeassistant/components/harmony/remote.py index 6a13093ec25..3431eff7994 100644 --- a/homeassistant/components/harmony/remote.py +++ b/homeassistant/components/harmony/remote.py @@ -227,8 +227,7 @@ class HarmonyRemote(HarmonyEntity, remote.RemoteEntity, RestoreEntity): async def async_send_command(self, command, **kwargs): """Send a list of commands to one device.""" _LOGGER.debug("%s: Send Command", self.name) - device = kwargs.get(ATTR_DEVICE) - if device is None: + if (device := kwargs.get(ATTR_DEVICE)) is None: _LOGGER.error("%s: Missing required argument: device", self.name) return diff --git a/homeassistant/components/humidifier/device_trigger.py b/homeassistant/components/humidifier/device_trigger.py index a049af9afec..9c6ca5cea55 100644 --- a/homeassistant/components/humidifier/device_trigger.py +++ b/homeassistant/components/humidifier/device_trigger.py @@ -86,9 +86,7 @@ async def async_attach_trigger( automation_info: AutomationTriggerInfo, ) -> CALLBACK_TYPE: """Attach a trigger.""" - trigger_type = config[CONF_TYPE] - - if trigger_type == "target_humidity_changed": + if config[CONF_TYPE] == "target_humidity_changed": numeric_state_config = { numeric_state_trigger.CONF_PLATFORM: "numeric_state", numeric_state_trigger.CONF_ENTITY_ID: config[CONF_ENTITY_ID], @@ -118,9 +116,7 @@ async def async_get_trigger_capabilities( hass: HomeAssistant, config: ConfigType ) -> dict[str, vol.Schema]: """List trigger capabilities.""" - trigger_type = config[CONF_TYPE] - - if trigger_type == "target_humidity_changed": + if config[CONF_TYPE] == "target_humidity_changed": return { "extra_fields": vol.Schema( { diff --git a/homeassistant/components/humidifier/reproduce_state.py b/homeassistant/components/humidifier/reproduce_state.py index 1303dee4518..e6d4fddafbc 100644 --- a/homeassistant/components/humidifier/reproduce_state.py +++ b/homeassistant/components/humidifier/reproduce_state.py @@ -28,9 +28,7 @@ async def _async_reproduce_states( reproduce_options: dict[str, Any] | None = None, ) -> None: """Reproduce component states.""" - 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/matrix/notify.py b/homeassistant/components/matrix/notify.py index 8643d7511bc..197d84352df 100644 --- a/homeassistant/components/matrix/notify.py +++ b/homeassistant/components/matrix/notify.py @@ -33,8 +33,7 @@ class MatrixNotificationService(BaseNotificationService): """Send the message to the Matrix server.""" target_rooms = kwargs.get(ATTR_TARGET) or [self._default_room] service_data = {ATTR_TARGET: target_rooms, ATTR_MESSAGE: message} - data = kwargs.get(ATTR_DATA) - if data is not None: + if (data := kwargs.get(ATTR_DATA)) is not None: service_data[ATTR_DATA] = data return self.hass.services.call( DOMAIN, SERVICE_SEND_MESSAGE, service_data=service_data diff --git a/homeassistant/components/onewire/onewirehub.py b/homeassistant/components/onewire/onewirehub.py index 26d08594055..d3b6773e74e 100644 --- a/homeassistant/components/onewire/onewirehub.py +++ b/homeassistant/components/onewire/onewirehub.py @@ -79,8 +79,7 @@ class OneWireHub: for device_path in self.owproxy.dir(path): device_family = self.owproxy.read(f"{device_path}family").decode() device_type = self.owproxy.read(f"{device_path}type").decode() - device_branches = DEVICE_COUPLERS.get(device_family) - if device_branches: + if device_branches := DEVICE_COUPLERS.get(device_family): for branch in device_branches: devices += self._discover_devices_owserver(f"{device_path}{branch}") else: diff --git a/homeassistant/components/opengarage/cover.py b/homeassistant/components/opengarage/cover.py index b80e1c82079..6952e4bff24 100644 --- a/homeassistant/components/opengarage/cover.py +++ b/homeassistant/components/opengarage/cover.py @@ -138,8 +138,7 @@ class OpenGarageCover(CoordinatorEntity, CoverEntity): @callback def _update_attr(self) -> None: """Update the state and attributes.""" - status = self.coordinator.data - if status is None: + if (status := self.coordinator.data) is None: _LOGGER.error("Unable to connect to OpenGarage device") self._attr_available = False return diff --git a/homeassistant/components/rachio/webhooks.py b/homeassistant/components/rachio/webhooks.py index 94c79a1504f..b0ac1a86d4a 100644 --- a/homeassistant/components/rachio/webhooks.py +++ b/homeassistant/components/rachio/webhooks.py @@ -109,15 +109,13 @@ async def async_get_or_create_registered_webhook_id_and_url(hass, entry): updated_config = False webhook_url = None - webhook_id = config.get(CONF_WEBHOOK_ID) - if not webhook_id: + if not (webhook_id := config.get(CONF_WEBHOOK_ID)): webhook_id = hass.components.webhook.async_generate_id() config[CONF_WEBHOOK_ID] = webhook_id updated_config = True if hass.components.cloud.async_active_subscription(): - cloudhook_url = config.get(CONF_CLOUDHOOK_URL) - if not cloudhook_url: + if not (cloudhook_url := config.get(CONF_CLOUDHOOK_URL)): cloudhook_url = await hass.components.cloud.async_create_cloudhook( webhook_id ) diff --git a/homeassistant/components/slide/cover.py b/homeassistant/components/slide/cover.py index 9e925af3391..470cde8ac94 100644 --- a/homeassistant/components/slide/cover.py +++ b/homeassistant/components/slide/cover.py @@ -94,8 +94,7 @@ class SlideCover(CoverEntity): @property def current_cover_position(self): """Return the current position of cover shutter.""" - pos = self._slide["pos"] - if pos is not None: + if (pos := self._slide["pos"]) is not None: if (1 - pos) <= DEFAULT_OFFSET or pos <= DEFAULT_OFFSET: pos = round(pos) if not self._invert: diff --git a/homeassistant/components/statsd/__init__.py b/homeassistant/components/statsd/__init__.py index b4657838683..9830279a5e2 100644 --- a/homeassistant/components/statsd/__init__.py +++ b/homeassistant/components/statsd/__init__.py @@ -54,9 +54,7 @@ def setup(hass, config): def statsd_event_listener(event): """Listen for new messages on the bus and sends them to StatsD.""" - state = event.data.get("new_state") - - if state is None: + if (state := event.data.get("new_state")) is None: return try: diff --git a/homeassistant/components/stream/__init__.py b/homeassistant/components/stream/__init__.py index d06d60aa48b..cef70a2e809 100644 --- a/homeassistant/components/stream/__init__.py +++ b/homeassistant/components/stream/__init__.py @@ -348,8 +348,7 @@ class Stream: raise HomeAssistantError(f"Can't write {video_path}, no access to path!") # Add recorder - recorder = self.outputs().get(RECORDER_PROVIDER) - if recorder: + if recorder := self.outputs().get(RECORDER_PROVIDER): assert isinstance(recorder, RecorderOutput) raise HomeAssistantError( f"Stream already recording to {recorder.video_path}!" diff --git a/homeassistant/components/tellduslive/entry.py b/homeassistant/components/tellduslive/entry.py index 67a59fc8dab..edb4537aac3 100644 --- a/homeassistant/components/tellduslive/entry.py +++ b/homeassistant/components/tellduslive/entry.py @@ -123,13 +123,10 @@ class TelldusLiveEntity(Entity): "identifiers": {("tellduslive", self.device.device_id)}, "name": self.device.name, } - model = device.get("model") - if model is not None: + if (model := device.get("model")) is not None: device_info["model"] = model.title() - protocol = device.get("protocol") - if protocol is not None: + if (protocol := device.get("protocol")) is not None: device_info["manufacturer"] = protocol.title() - client = device.get("client") - if client is not None: + if (client := device.get("client")) is not None: device_info["via_device"] = ("tellduslive", client) return device_info diff --git a/homeassistant/components/velbus/climate.py b/homeassistant/components/velbus/climate.py index cdb049266b5..318dff463f0 100644 --- a/homeassistant/components/velbus/climate.py +++ b/homeassistant/components/velbus/climate.py @@ -61,8 +61,7 @@ class VelbusClimate(VelbusEntity, ClimateEntity): def set_temperature(self, **kwargs): """Set new target temperatures.""" - temp = kwargs.get(ATTR_TEMPERATURE) - if temp is None: + if (temp := kwargs.get(ATTR_TEMPERATURE)) is None: return self._channel.set_temp(temp) self.schedule_update_ha_state() diff --git a/homeassistant/components/viaggiatreno/sensor.py b/homeassistant/components/viaggiatreno/sensor.py index dc20ea3edbc..ee02eaa63e1 100644 --- a/homeassistant/components/viaggiatreno/sensor.py +++ b/homeassistant/components/viaggiatreno/sensor.py @@ -60,8 +60,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= """Set up the ViaggiaTreno platform.""" train_id = config.get(CONF_TRAIN_ID) station_id = config.get(CONF_STATION_ID) - name = config.get(CONF_NAME) - if not name: + if not (name := config.get(CONF_NAME)): name = DEFAULT_NAME.format(train_id) async_add_entities([ViaggiaTrenoSensor(train_id, station_id, name)]) diff --git a/homeassistant/components/vlc_telnet/media_player.py b/homeassistant/components/vlc_telnet/media_player.py index 75b55b5f77b..ad88cfc2627 100644 --- a/homeassistant/components/vlc_telnet/media_player.py +++ b/homeassistant/components/vlc_telnet/media_player.py @@ -179,8 +179,7 @@ class VlcDevice(MediaPlayerEntity): if not self._media_title: # Fall back to filename. - data_info = data.get("data") - if data_info: + if data_info := data.get("data"): self._media_title = data_info["filename"] except CommandError as err: @@ -282,8 +281,7 @@ class VlcDevice(MediaPlayerEntity): async def async_media_pause(self) -> None: """Send pause command.""" status = await self._vlc.status() - current_state = status.state - if current_state != "paused": + if status.state != "paused": # Make sure we're not already paused since VLCTelnet.pause() toggles # pause. await self._vlc.pause() diff --git a/homeassistant/components/waze_travel_time/helpers.py b/homeassistant/components/waze_travel_time/helpers.py index 326a6018c96..26e529b8e93 100644 --- a/homeassistant/components/waze_travel_time/helpers.py +++ b/homeassistant/components/waze_travel_time/helpers.py @@ -29,9 +29,7 @@ def resolve_location(hass, logger, loc): def get_location_from_entity(hass, logger, entity_id): """Get the location from the entity_id.""" - state = hass.states.get(entity_id) - - if state is None: + if (state := hass.states.get(entity_id)) is None: logger.error("Unable to find entity %s", entity_id) return None diff --git a/homeassistant/components/xiaomi_miio/config_flow.py b/homeassistant/components/xiaomi_miio/config_flow.py index 5256b37ccda..96a06f6a33d 100644 --- a/homeassistant/components/xiaomi_miio/config_flow.py +++ b/homeassistant/components/xiaomi_miio/config_flow.py @@ -256,8 +256,7 @@ class XiaomiMiioFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): self.cloud_devices = {} for device in devices_raw: - parent_id = device.get("parent_id") - if not parent_id: + if not device.get("parent_id"): name = device["name"] model = device["model"] list_name = f"{name} - {model}" diff --git a/homeassistant/components/xiaomi_miio/fan.py b/homeassistant/components/xiaomi_miio/fan.py index 04cdc4573db..01304008b76 100644 --- a/homeassistant/components/xiaomi_miio/fan.py +++ b/homeassistant/components/xiaomi_miio/fan.py @@ -229,8 +229,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): 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): filtered_entities = [ entity for entity in hass.data[DATA_KEY].values() diff --git a/homeassistant/components/xiaomi_miio/light.py b/homeassistant/components/xiaomi_miio/light.py index b916de899b9..04597eadf81 100644 --- a/homeassistant/components/xiaomi_miio/light.py +++ b/homeassistant/components/xiaomi_miio/light.py @@ -194,8 +194,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): 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_devices = [ dev for dev in hass.data[DATA_KEY].values() diff --git a/homeassistant/components/xiaomi_miio/switch.py b/homeassistant/components/xiaomi_miio/switch.py index 6f68e5652db..5c29253ae73 100644 --- a/homeassistant/components/xiaomi_miio/switch.py +++ b/homeassistant/components/xiaomi_miio/switch.py @@ -414,8 +414,7 @@ async def async_setup_other_entry(hass, config_entry, async_add_entities): 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): devices = [ device for device in hass.data[DATA_KEY].values()