diff --git a/homeassistant/components/acer_projector/switch.py b/homeassistant/components/acer_projector/switch.py index 947b774b7bd..747c7c98d73 100644 --- a/homeassistant/components/acer_projector/switch.py +++ b/homeassistant/components/acer_projector/switch.py @@ -129,8 +129,7 @@ class AcerSwitch(SwitchEntity): self._attr_available = False for key in self._attributes: - msg = CMD_DICT.get(key) - if msg: + if msg := CMD_DICT.get(key): awns = self._write_read_format(msg) self._attributes[key] = awns self._attr_extra_state_attributes = self._attributes diff --git a/homeassistant/components/arlo/sensor.py b/homeassistant/components/arlo/sensor.py index 0cbb7c95f65..7fbc57f9c6b 100644 --- a/homeassistant/components/arlo/sensor.py +++ b/homeassistant/components/arlo/sensor.py @@ -89,8 +89,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def setup_platform(hass, config, add_entities, discovery_info=None): """Set up an Arlo IP sensor.""" - arlo = hass.data.get(DATA_ARLO) - if not arlo: + if not (arlo := hass.data.get(DATA_ARLO)): return sensors = [] diff --git a/homeassistant/components/coolmaster/climate.py b/homeassistant/components/coolmaster/climate.py index 0b717697a1a..ceab74b2139 100644 --- a/homeassistant/components/coolmaster/climate.py +++ b/homeassistant/components/coolmaster/climate.py @@ -142,8 +142,7 @@ class CoolmasterClimate(CoordinatorEntity, ClimateEntity): async def async_set_temperature(self, **kwargs): """Set new target temperatures.""" - temp = kwargs.get(ATTR_TEMPERATURE) - if temp is not None: + if (temp := kwargs.get(ATTR_TEMPERATURE)) is not None: _LOGGER.debug("Setting temp of %s to %s", self.unique_id, str(temp)) self._unit = await self._unit.set_thermostat(temp) self.async_write_ha_state() diff --git a/homeassistant/components/elkm1/__init__.py b/homeassistant/components/elkm1/__init__.py index 0eb34b2fc61..0b4fa26e833 100644 --- a/homeassistant/components/elkm1/__init__.py +++ b/homeassistant/components/elkm1/__init__.py @@ -236,8 +236,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: elk.connect() def _element_changed(element, changeset): - keypress = changeset.get("last_keypress") - if keypress is None: + if (keypress := changeset.get("last_keypress")) is None: return hass.bus.async_fire( diff --git a/homeassistant/components/elkm1/alarm_control_panel.py b/homeassistant/components/elkm1/alarm_control_panel.py index c3ed6bbc40d..5b3a20b3448 100644 --- a/homeassistant/components/elkm1/alarm_control_panel.py +++ b/homeassistant/components/elkm1/alarm_control_panel.py @@ -141,8 +141,7 @@ class ElkArea(ElkAttachedEntity, AlarmControlPanelEntity, RestoreEntity): self.async_write_ha_state() def _watch_area(self, area, changeset): - last_log = changeset.get("last_log") - if not last_log: + if not (last_log := changeset.get("last_log")): return # user_number only set for arm/disarm logs if not last_log.get("user_number"): diff --git a/homeassistant/components/elkm1/config_flow.py b/homeassistant/components/elkm1/config_flow.py index f8cfdbe9851..905aa35ad19 100644 --- a/homeassistant/components/elkm1/config_flow.py +++ b/homeassistant/components/elkm1/config_flow.py @@ -79,8 +79,7 @@ async def validate_input(data): def _make_url_from_data(data): - host = data.get(CONF_HOST) - if host: + if host := data.get(CONF_HOST): return host protocol = PROTOCOL_MAP[data[CONF_PROTOCOL]] diff --git a/homeassistant/components/emoncms/sensor.py b/homeassistant/components/emoncms/sensor.py index 033f7878b5e..125e5e6c333 100644 --- a/homeassistant/components/emoncms/sensor.py +++ b/homeassistant/components/emoncms/sensor.py @@ -109,8 +109,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): if sensor_names is not None: name = sensor_names.get(int(elem["id"]), None) - unit = elem.get("unit") - if unit: + if unit := elem.get("unit"): unit_of_measurement = unit else: unit_of_measurement = config_unit diff --git a/homeassistant/components/hassio/http.py b/homeassistant/components/hassio/http.py index 2012725c7f4..532b947ac49 100644 --- a/homeassistant/components/hassio/http.py +++ b/homeassistant/components/hassio/http.py @@ -129,8 +129,7 @@ def _init_header(request: web.Request) -> dict[str, str]: } # Add user data - user = request.get("hass_user") - if user is not None: + if request.get("hass_user") is not None: headers[X_HASS_USER_ID] = request["hass_user"].id headers[X_HASS_IS_ADMIN] = str(int(request["hass_user"].is_admin)) diff --git a/homeassistant/components/hassio/ingress.py b/homeassistant/components/hassio/ingress.py index e58c2d790f2..620c69f543d 100644 --- a/homeassistant/components/hassio/ingress.py +++ b/homeassistant/components/hassio/ingress.py @@ -197,8 +197,7 @@ def _init_header(request: web.Request, token: str) -> CIMultiDict | dict[str, st headers[hdrs.X_FORWARDED_FOR] = forward_for # Set X-Forwarded-Host - forward_host = request.headers.get(hdrs.X_FORWARDED_HOST) - if not forward_host: + if not (forward_host := request.headers.get(hdrs.X_FORWARDED_HOST)): forward_host = request.host headers[hdrs.X_FORWARDED_HOST] = forward_host diff --git a/homeassistant/components/input_number/reproduce_state.py b/homeassistant/components/input_number/reproduce_state.py index c198236789c..368f68b5178 100644 --- a/homeassistant/components/input_number/reproduce_state.py +++ b/homeassistant/components/input_number/reproduce_state.py @@ -24,9 +24,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/message_bird/notify.py b/homeassistant/components/message_bird/notify.py index ce1d275a832..9a542836011 100644 --- a/homeassistant/components/message_bird/notify.py +++ b/homeassistant/components/message_bird/notify.py @@ -48,8 +48,7 @@ class MessageBirdNotificationService(BaseNotificationService): def send_message(self, message=None, **kwargs): """Send a message to a specified target.""" - targets = kwargs.get(ATTR_TARGET) - if not targets: + if not (targets := kwargs.get(ATTR_TARGET)): _LOGGER.error("No target specified") return diff --git a/homeassistant/components/mysensors/__init__.py b/homeassistant/components/mysensors/__init__.py index b6ad78f5dc8..6c2d2f710e6 100644 --- a/homeassistant/components/mysensors/__init__.py +++ b/homeassistant/components/mysensors/__init__.py @@ -62,8 +62,7 @@ DEFAULT_VERSION = "1.4" def set_default_persistence_file(value: dict) -> dict: """Set default persistence file.""" for idx, gateway in enumerate(value): - fil = gateway.get(CONF_PERSISTENCE_FILE) - if fil is not None: + if gateway.get(CONF_PERSISTENCE_FILE) is not None: continue new_name = f"mysensors{idx + 1}.pickle" gateway[CONF_PERSISTENCE_FILE] = new_name diff --git a/homeassistant/components/mysensors/handler.py b/homeassistant/components/mysensors/handler.py index 0fb86fd0eec..98242615f67 100644 --- a/homeassistant/components/mysensors/handler.py +++ b/homeassistant/components/mysensors/handler.py @@ -27,8 +27,7 @@ async def handle_internal( ) -> None: """Handle a mysensors internal message.""" internal = msg.gateway.const.Internal(msg.sub_type) - handler = HANDLERS.get(internal.name) - if handler is None: + if (handler := HANDLERS.get(internal.name)) is None: return await handler(hass, gateway_id, msg) diff --git a/homeassistant/components/nx584/binary_sensor.py b/homeassistant/components/nx584/binary_sensor.py index 058ac6c5795..7a999263332 100644 --- a/homeassistant/components/nx584/binary_sensor.py +++ b/homeassistant/components/nx584/binary_sensor.py @@ -122,9 +122,8 @@ class NX584Watcher(threading.Thread): def _process_zone_event(self, event): zone = event["zone"] - zone_sensor = self._zone_sensors.get(zone) # pylint: disable=protected-access - if not zone_sensor: + if not (zone_sensor := self._zone_sensors.get(zone)): return zone_sensor._zone["state"] = event["zone_state"] zone_sensor.schedule_update_ha_state() diff --git a/homeassistant/components/pyload/sensor.py b/homeassistant/components/pyload/sensor.py index f568b41776f..b10abd282b4 100644 --- a/homeassistant/components/pyload/sensor.py +++ b/homeassistant/components/pyload/sensor.py @@ -116,8 +116,7 @@ class PyLoadSensor(SensorEntity): ) return - value = self.api.status.get(self.type) - if value is None: + if (value := self.api.status.get(self.type)) is None: _LOGGER.warning("Unable to locate value for %s", self.type) return diff --git a/homeassistant/components/radarr/sensor.py b/homeassistant/components/radarr/sensor.py index fc4fff6c274..8364dd670e4 100644 --- a/homeassistant/components/radarr/sensor.py +++ b/homeassistant/components/radarr/sensor.py @@ -248,8 +248,7 @@ def get_date(zone, offset=0): def get_release_date(data): """Get release date.""" - date = data.get("physicalRelease") - if not date: + if not (date := data.get("physicalRelease")): date = data.get("inCinemas") return date diff --git a/homeassistant/components/select/reproduce_state.py b/homeassistant/components/select/reproduce_state.py index 8af4b94fd6f..d41fd5dae46 100644 --- a/homeassistant/components/select/reproduce_state.py +++ b/homeassistant/components/select/reproduce_state.py @@ -23,9 +23,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/sighthound/image_processing.py b/homeassistant/components/sighthound/image_processing.py index e31b30f1174..77d9e33b043 100644 --- a/homeassistant/components/sighthound/image_processing.py +++ b/homeassistant/components/sighthound/image_processing.py @@ -55,8 +55,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): _LOGGER.error("Sighthound error %s setup aborted", exc) return - save_file_folder = config.get(CONF_SAVE_FILE_FOLDER) - if save_file_folder: + if save_file_folder := config.get(CONF_SAVE_FILE_FOLDER): save_file_folder = Path(save_file_folder) entities = [] diff --git a/homeassistant/components/tradfri/__init__.py b/homeassistant/components/tradfri/__init__.py index 4f5997b2fa1..3988775ad2b 100644 --- a/homeassistant/components/tradfri/__init__.py +++ b/homeassistant/components/tradfri/__init__.py @@ -58,9 +58,7 @@ CONFIG_SCHEMA = vol.Schema( async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Tradfri component.""" - conf = config.get(DOMAIN) - - if conf is None: + if (conf := config.get(DOMAIN)) is None: return True configured_hosts = [ diff --git a/homeassistant/components/tradfri/light.py b/homeassistant/components/tradfri/light.py index b3f73cebc82..53309e144ff 100644 --- a/homeassistant/components/tradfri/light.py +++ b/homeassistant/components/tradfri/light.py @@ -53,10 +53,8 @@ async def async_setup_entry( if lights: async_add_entities(TradfriLight(light, api, gateway_id) for light in lights) - if config_entry.data[CONF_IMPORT_GROUPS]: - groups = tradfri_data[GROUPS] - if groups: - async_add_entities(TradfriGroup(group, api, gateway_id) for group in groups) + if config_entry.data[CONF_IMPORT_GROUPS] and (groups := tradfri_data[GROUPS]): + async_add_entities(TradfriGroup(group, api, gateway_id) for group in groups) class TradfriGroup(TradfriBaseClass, LightEntity): diff --git a/homeassistant/components/vicare/climate.py b/homeassistant/components/vicare/climate.py index 2822d048152..a6aa757e124 100644 --- a/homeassistant/components/vicare/climate.py +++ b/homeassistant/components/vicare/climate.py @@ -262,8 +262,7 @@ class ViCareClimate(ClimateEntity): def set_temperature(self, **kwargs): """Set new target temperatures.""" - temp = kwargs.get(ATTR_TEMPERATURE) - if temp is not None: + if (temp := kwargs.get(ATTR_TEMPERATURE)) is not None: self._api.setProgramTemperature(self._current_program, temp) self._target_temperature = temp diff --git a/homeassistant/components/vicare/water_heater.py b/homeassistant/components/vicare/water_heater.py index af373c6ee6e..557d5257427 100644 --- a/homeassistant/components/vicare/water_heater.py +++ b/homeassistant/components/vicare/water_heater.py @@ -124,8 +124,7 @@ class ViCareWater(WaterHeaterEntity): def set_temperature(self, **kwargs): """Set new target temperatures.""" - temp = kwargs.get(ATTR_TEMPERATURE) - if temp is not None: + if (temp := kwargs.get(ATTR_TEMPERATURE)) is not None: self._api.setDomesticHotWaterTemperature(temp) self._target_temperature = temp diff --git a/homeassistant/components/wallbox/__init__.py b/homeassistant/components/wallbox/__init__.py index 9f07329a1dd..02c1cec668e 100644 --- a/homeassistant/components/wallbox/__init__.py +++ b/homeassistant/components/wallbox/__init__.py @@ -58,8 +58,7 @@ class WallboxHub: filtered_data = {k: data[k] for k in CONF_SENSOR_TYPES if k in data} for key, value in filtered_data.items(): - sensor_round = CONF_SENSOR_TYPES[key][CONF_ROUND] - if sensor_round: + if sensor_round := CONF_SENSOR_TYPES[key][CONF_ROUND]: try: filtered_data[key] = round(value, sensor_round) except TypeError: