diff --git a/homeassistant/components/buienradar/camera.py b/homeassistant/components/buienradar/camera.py index 91e4bcffb17..e68b096ca05 100644 --- a/homeassistant/components/buienradar/camera.py +++ b/homeassistant/components/buienradar/camera.py @@ -131,8 +131,7 @@ class BuienradarCam(Camera): _LOGGER.debug("HTTP 304 - success") return True - last_modified = res.headers.get("Last-Modified") - if last_modified: + if last_modified := res.headers.get("Last-Modified"): self._last_modified = last_modified self._last_image = await res.read() diff --git a/homeassistant/components/buienradar/sensor.py b/homeassistant/components/buienradar/sensor.py index 2c6390f959b..0affe1e2c62 100644 --- a/homeassistant/components/buienradar/sensor.py +++ b/homeassistant/components/buienradar/sensor.py @@ -786,8 +786,7 @@ class BrSensor(SensorEntity): if sensor_type == SYMBOL or sensor_type.startswith(CONDITION): # update weather symbol & status text - condition = data.get(CONDITION) - if condition: + if condition := data.get(CONDITION): if sensor_type == SYMBOL: new_state = condition.get(EXACTNL) if sensor_type == CONDITION: diff --git a/homeassistant/components/buienradar/weather.py b/homeassistant/components/buienradar/weather.py index a1546120064..aa336d3929c 100644 --- a/homeassistant/components/buienradar/weather.py +++ b/homeassistant/components/buienradar/weather.py @@ -133,12 +133,13 @@ class BrWeather(WeatherEntity): @property def condition(self): """Return the current condition.""" - if self._data and self._data.condition: - ccode = self._data.condition.get(CONDCODE) - if ccode: - conditions = self.hass.data[DOMAIN].get(DATA_CONDITION) - if conditions: - return conditions.get(ccode) + if ( + self._data + and self._data.condition + and (ccode := self._data.condition.get(CONDCODE)) + and (conditions := self.hass.data[DOMAIN].get(DATA_CONDITION)) + ): + return conditions.get(ccode) @property def temperature(self): diff --git a/homeassistant/components/debugpy/__init__.py b/homeassistant/components/debugpy/__init__.py index 613ecfd8ffa..21cfeb15a80 100644 --- a/homeassistant/components/debugpy/__init__.py +++ b/homeassistant/components/debugpy/__init__.py @@ -48,8 +48,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: debugpy.listen((conf[CONF_HOST], conf[CONF_PORT])) - wait = conf[CONF_WAIT] - if wait: + if conf[CONF_WAIT]: _LOGGER.warning( "Waiting for remote debug connection on %s:%s", conf[CONF_HOST], diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index 9ddf50aad43..994ae2d108a 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -598,8 +598,7 @@ class MQTT: """ self = hass.data[DATA_MQTT] - conf = hass.data.get(DATA_MQTT_CONFIG) - if conf is None: + if (conf := hass.data.get(DATA_MQTT_CONFIG)) is None: conf = CONFIG_SCHEMA({DOMAIN: dict(entry.data)})[DOMAIN] self.conf = _merge_config(entry, conf) @@ -622,8 +621,7 @@ class MQTT: else: proto = mqtt.MQTTv311 - client_id = self.conf.get(CONF_CLIENT_ID) - if client_id is None: + if (client_id := self.conf.get(CONF_CLIENT_ID)) is None: # PAHO MQTT relies on the MQTT server to generate random client IDs. # However, that feature is not mandatory so we generate our own. client_id = mqtt.base62(uuid.uuid4().int, padding=22) @@ -637,9 +635,7 @@ class MQTT: if username is not None: self._mqttc.username_pw_set(username, password) - certificate = self.conf.get(CONF_CERTIFICATE) - - if certificate == "auto": + if (certificate := self.conf.get(CONF_CERTIFICATE)) == "auto": certificate = certifi.where() client_key = self.conf.get(CONF_CLIENT_KEY) @@ -1002,8 +998,7 @@ async def websocket_remove_device(hass, connection, msg): device_id = msg["device_id"] dev_registry = await hass.helpers.device_registry.async_get_registry() - device = dev_registry.async_get(device_id) - if not device: + if not (device := dev_registry.async_get(device_id)): connection.send_error( msg["id"], websocket_api.const.ERR_NOT_FOUND, "Device not found" ) diff --git a/homeassistant/components/mqtt/alarm_control_panel.py b/homeassistant/components/mqtt/alarm_control_panel.py index 3d632baf0f7..825ad345272 100644 --- a/homeassistant/components/mqtt/alarm_control_panel.py +++ b/homeassistant/components/mqtt/alarm_control_panel.py @@ -205,8 +205,7 @@ class MqttAlarm(MqttEntity, alarm.AlarmControlPanelEntity): @property def code_format(self): """Return one or more digits/characters.""" - code = self._config.get(CONF_CODE) - if code is None: + if (code := self._config.get(CONF_CODE)) is None: return None if code == REMOTE_CODE or (isinstance(code, str) and re.search("^\\d+$", code)): return alarm.FORMAT_NUMBER diff --git a/homeassistant/components/mqtt/discovery.py b/homeassistant/components/mqtt/discovery.py index 5678f31f5b2..a237ea7aea1 100644 --- a/homeassistant/components/mqtt/discovery.py +++ b/homeassistant/components/mqtt/discovery.py @@ -142,8 +142,7 @@ async def async_start( # noqa: C901 payload[key] = f"{value[:-1]}{base}" if payload.get(CONF_AVAILABILITY): for availability_conf in payload[CONF_AVAILABILITY]: - topic = availability_conf.get(CONF_TOPIC) - if topic: + if topic := availability_conf.get(CONF_TOPIC): if topic[0] == TOPIC_BASE: availability_conf[CONF_TOPIC] = f"{base}{topic[1:]}" if topic[-1] == TOPIC_BASE: diff --git a/homeassistant/components/mqtt/light/schema_basic.py b/homeassistant/components/mqtt/light/schema_basic.py index 409eb9d648c..cb350ae4c9c 100644 --- a/homeassistant/components/mqtt/light/schema_basic.py +++ b/homeassistant/components/mqtt/light/schema_basic.py @@ -826,8 +826,7 @@ class MqttLight(MqttEntity, LightEntity, RestoreEntity): def render_rgbx(color, template, color_mode): """Render RGBx payload.""" - tpl = self._command_templates[template] - if tpl: + if tpl := self._command_templates[template]: keys = ["red", "green", "blue"] if color_mode == COLOR_MODE_RGBW: keys.append("white") diff --git a/homeassistant/components/upb/__init__.py b/homeassistant/components/upb/__init__.py index 7b3b30fdb29..a3c3016dc05 100644 --- a/homeassistant/components/upb/__init__.py +++ b/homeassistant/components/upb/__init__.py @@ -31,8 +31,7 @@ async def async_setup_entry(hass, config_entry): hass.config_entries.async_setup_platforms(config_entry, PLATFORMS) def _element_changed(element, changeset): - change = changeset.get("last_change") - if change is None: + if (change := changeset.get("last_change")) is None: return if change.get("command") is None: return diff --git a/homeassistant/components/upb/config_flow.py b/homeassistant/components/upb/config_flow.py index 3268b5af9ab..c920fa405ef 100644 --- a/homeassistant/components/upb/config_flow.py +++ b/homeassistant/components/upb/config_flow.py @@ -62,8 +62,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/upb/light.py b/homeassistant/components/upb/light.py index 404e45e0c62..22ae5925a72 100644 --- a/homeassistant/components/upb/light.py +++ b/homeassistant/components/upb/light.py @@ -67,8 +67,7 @@ class UpbLight(UpbAttachedEntity, LightEntity): async def async_turn_on(self, **kwargs): """Turn on the light.""" - flash = kwargs.get(ATTR_FLASH) - if flash: + if flash := kwargs.get(ATTR_FLASH): await self.async_light_blink(0.5 if flash == "short" else 1.5) else: rate = kwargs.get(ATTR_TRANSITION, -1) diff --git a/homeassistant/components/zha/core/channels/homeautomation.py b/homeassistant/components/zha/core/channels/homeautomation.py index e25cc3eb0da..89a9d51395e 100644 --- a/homeassistant/components/zha/core/channels/homeautomation.py +++ b/homeassistant/components/zha/core/channels/homeautomation.py @@ -139,8 +139,7 @@ class ElectricalMeasurementChannel(ZigbeeChannel): @property def measurement_type(self) -> str | None: """Return Measurement type.""" - meas_type = self.cluster.get("measurement_type") - if meas_type is None: + if (meas_type := self.cluster.get("measurement_type")) is None: return None meas_type = self.MeasurementType(meas_type) diff --git a/homeassistant/components/zha/core/channels/smartenergy.py b/homeassistant/components/zha/core/channels/smartenergy.py index f3f0e76a5fb..5877dad14fa 100644 --- a/homeassistant/components/zha/core/channels/smartenergy.py +++ b/homeassistant/components/zha/core/channels/smartenergy.py @@ -138,8 +138,7 @@ class Metering(ZigbeeChannel): @property def status(self) -> int | None: """Return metering device status.""" - status = self.cluster.get("status") - if status is None: + if (status := self.cluster.get("status")) is None: return None if self.cluster.get("metering_device_type") == 0: # Electric metering device type diff --git a/homeassistant/components/zha/core/discovery.py b/homeassistant/components/zha/core/discovery.py index 43a0186d88b..df257dbbecc 100644 --- a/homeassistant/components/zha/core/discovery.py +++ b/homeassistant/components/zha/core/discovery.py @@ -206,8 +206,7 @@ class ProbeEndpoint: def initialize(self, hass: HomeAssistant) -> None: """Update device overrides config.""" zha_config = hass.data[zha_const.DATA_ZHA].get(zha_const.DATA_ZHA_CONFIG, {}) - overrides = zha_config.get(zha_const.CONF_DEVICE_CONFIG) - if overrides: + if overrides := zha_config.get(zha_const.CONF_DEVICE_CONFIG): self._device_configs.update(overrides) @@ -237,8 +236,7 @@ class GroupProbe: def _reprobe_group(self, group_id: int) -> None: """Reprobe a group for entities after its members change.""" zha_gateway = self._hass.data[zha_const.DATA_ZHA][zha_const.DATA_ZHA_GATEWAY] - zha_group = zha_gateway.groups.get(group_id) - if zha_group is None: + if (zha_group := zha_gateway.groups.get(group_id)) is None: return self.discover_group_entities(zha_group) diff --git a/homeassistant/components/zha/core/gateway.py b/homeassistant/components/zha/core/gateway.py index 4e793b39a8a..252893683ef 100644 --- a/homeassistant/components/zha/core/gateway.py +++ b/homeassistant/components/zha/core/gateway.py @@ -494,8 +494,7 @@ class ZHAGateway: self, zigpy_device: zha_typing.ZigpyDeviceType, restored: bool = False ): """Get or create a ZHA device.""" - zha_device = self._devices.get(zigpy_device.ieee) - if zha_device is None: + if (zha_device := self._devices.get(zigpy_device.ieee)) is None: zha_device = ZHADevice.new(self._hass, zigpy_device, self, restored) self._devices[zigpy_device.ieee] = zha_device device_registry_device = self.ha_device_registry.async_get_or_create( @@ -649,8 +648,7 @@ class ZHAGateway: async def async_remove_zigpy_group(self, group_id: int) -> None: """Remove a Zigbee group from Zigpy.""" - group = self.groups.get(group_id) - if not group: + if not (group := self.groups.get(group_id)): _LOGGER.debug("Group: %s:0x%04x could not be found", group.name, group_id) return if group.members: diff --git a/homeassistant/components/zha/core/helpers.py b/homeassistant/components/zha/core/helpers.py index 47ee682b46e..d150ab9df45 100644 --- a/homeassistant/components/zha/core/helpers.py +++ b/homeassistant/components/zha/core/helpers.py @@ -167,8 +167,7 @@ async def async_get_zha_device(hass, device_id): def find_state_attributes(states: list[State], key: str) -> Iterator[Any]: """Find attributes with matching key from states.""" for state in states: - value = state.attributes.get(key) - if value is not None: + if (value := state.attributes.get(key)) is not None: yield value diff --git a/homeassistant/components/zha/core/store.py b/homeassistant/components/zha/core/store.py index f1b2ee57aee..5d33375ace2 100644 --- a/homeassistant/components/zha/core/store.py +++ b/homeassistant/components/zha/core/store.py @@ -131,9 +131,7 @@ class ZhaStorage: @bind_hass async def async_get_registry(hass: HomeAssistant) -> ZhaStorage: """Return zha device storage instance.""" - task = hass.data.get(DATA_REGISTRY) - - if task is None: + if (task := hass.data.get(DATA_REGISTRY)) is None: async def _load_reg() -> ZhaStorage: registry = ZhaStorage(hass) diff --git a/homeassistant/components/zha/light.py b/homeassistant/components/zha/light.py index a340ffae736..9398d0fde17 100644 --- a/homeassistant/components/zha/light.py +++ b/homeassistant/components/zha/light.py @@ -481,8 +481,7 @@ class Light(BaseLight, ZhaEntity): attributes, from_cache=False ) - color_mode = results.get("color_mode") - if color_mode is not None: + if (color_mode := results.get("color_mode")) is not None: if color_mode == LightColorMode.COLOR_TEMP: color_temp = results.get("color_temperature") if color_temp is not None and color_mode: