diff --git a/homeassistant/components/actiontec/device_tracker.py b/homeassistant/components/actiontec/device_tracker.py index 8dc3f095437..cc26c191c8c 100644 --- a/homeassistant/components/actiontec/device_tracker.py +++ b/homeassistant/components/actiontec/device_tracker.py @@ -71,8 +71,7 @@ class ActiontecDeviceScanner(DeviceScanner): if not self.success_init: return False - actiontec_data = self.get_actiontec_data() - if actiontec_data is None: + if (actiontec_data := self.get_actiontec_data()) is None: return False self.last_results = [ device for device in actiontec_data if device.timevalid > -60 diff --git a/homeassistant/components/avea/light.py b/homeassistant/components/avea/light.py index d1df7ba3e46..ceb66ff39b6 100644 --- a/homeassistant/components/avea/light.py +++ b/homeassistant/components/avea/light.py @@ -59,7 +59,6 @@ class AveaLight(LightEntity): This is the only method that should fetch new data for Home Assistant. """ - brightness = self._light.get_brightness() - if brightness is not None: + if (brightness := self._light.get_brightness()) is not None: self._attr_is_on = brightness != 0 self._attr_brightness = round(255 * (brightness / 4095)) diff --git a/homeassistant/components/google_assistant/helpers.py b/homeassistant/components/google_assistant/helpers.py index 76933cecd91..238ee8d9576 100644 --- a/homeassistant/components/google_assistant/helpers.py +++ b/homeassistant/components/google_assistant/helpers.py @@ -521,8 +521,7 @@ class GoogleEntity: if area and area.name: device["roomHint"] = area.name - device_info = await _get_device_info(device_entry) - if device_info: + if device_info := await _get_device_info(device_entry): device["deviceInfo"] = device_info return device diff --git a/homeassistant/components/hassio/addon_panel.py b/homeassistant/components/hassio/addon_panel.py index d6240896c84..41107a6fa55 100644 --- a/homeassistant/components/hassio/addon_panel.py +++ b/homeassistant/components/hassio/addon_panel.py @@ -21,8 +21,7 @@ async def async_setup_addon_panel(hass: HomeAssistant, hassio): hass.http.register_view(hassio_addon_panel) # If panels are exists - panels = await hassio_addon_panel.get_panels() - if not panels: + if not (panels := await hassio_addon_panel.get_panels()): return # Register available panels diff --git a/homeassistant/components/heos/__init__.py b/homeassistant/components/heos/__init__.py index a4cdb6cdddc..610292f0389 100644 --- a/homeassistant/components/heos/__init__.py +++ b/homeassistant/components/heos/__init__.py @@ -335,9 +335,8 @@ class SourceManager: heos_const.EVENT_USER_CHANGED, heos_const.EVENT_CONNECTED, ): - sources = await get_sources() # If throttled, it will return None - if sources: + if sources := await get_sources(): self.favorites, self.inputs = sources self.source_list = self._build_source_list() _LOGGER.debug("Sources updated due to changed event") diff --git a/homeassistant/components/homekit/type_cameras.py b/homeassistant/components/homekit/type_cameras.py index 6cf8735b075..14d065dc9bf 100644 --- a/homeassistant/components/homekit/type_cameras.py +++ b/homeassistant/components/homekit/type_cameras.py @@ -333,8 +333,7 @@ class Camera(HomeAccessory, PyhapCamera): session_info["id"], stream_config, ) - input_source = await self._async_get_stream_source() - if not input_source: + if not (input_source := await self._async_get_stream_source()): _LOGGER.error("Camera has no stream source") return False if "-i " not in input_source: diff --git a/homeassistant/components/homekit/type_sensors.py b/homeassistant/components/homekit/type_sensors.py index c309e42a0f0..e43a899a9b2 100644 --- a/homeassistant/components/homekit/type_sensors.py +++ b/homeassistant/components/homekit/type_sensors.py @@ -114,8 +114,7 @@ class TemperatureSensor(HomeAccessory): def async_update_state(self, new_state): """Update temperature after state changed.""" unit = new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS) - temperature = convert_to_float(new_state.state) - if temperature: + if temperature := convert_to_float(new_state.state): temperature = temperature_to_homekit(temperature, unit) self.char_temp.set_value(temperature) _LOGGER.debug( @@ -142,8 +141,7 @@ class HumiditySensor(HomeAccessory): @callback def async_update_state(self, new_state): """Update accessory after state change.""" - humidity = convert_to_float(new_state.state) - if humidity: + if humidity := convert_to_float(new_state.state): self.char_humidity.set_value(humidity) _LOGGER.debug("%s: Percent set to %d%%", self.entity_id, humidity) @@ -170,8 +168,7 @@ class AirQualitySensor(HomeAccessory): @callback def async_update_state(self, new_state): """Update accessory after state change.""" - density = convert_to_float(new_state.state) - if density: + if density := convert_to_float(new_state.state): if self.char_density.value != density: self.char_density.set_value(density) _LOGGER.debug("%s: Set density to %d", self.entity_id, density) @@ -206,8 +203,7 @@ class CarbonMonoxideSensor(HomeAccessory): @callback def async_update_state(self, new_state): """Update accessory after state change.""" - value = convert_to_float(new_state.state) - if value: + if value := convert_to_float(new_state.state): self.char_level.set_value(value) if value > self.char_peak.value: self.char_peak.set_value(value) @@ -242,8 +238,7 @@ class CarbonDioxideSensor(HomeAccessory): @callback def async_update_state(self, new_state): """Update accessory after state change.""" - value = convert_to_float(new_state.state) - if value: + if value := convert_to_float(new_state.state): self.char_level.set_value(value) if value > self.char_peak.value: self.char_peak.set_value(value) @@ -271,8 +266,7 @@ class LightSensor(HomeAccessory): @callback def async_update_state(self, new_state): """Update accessory after state change.""" - luminance = convert_to_float(new_state.state) - if luminance: + if luminance := convert_to_float(new_state.state): self.char_light.set_value(luminance) _LOGGER.debug("%s: Set to %d", self.entity_id, luminance) diff --git a/homeassistant/components/homekit/util.py b/homeassistant/components/homekit/util.py index a5c9f3937ea..7782c389e56 100644 --- a/homeassistant/components/homekit/util.py +++ b/homeassistant/components/homekit/util.py @@ -294,9 +294,7 @@ def get_media_player_features(state): def validate_media_player_features(state, feature_list): """Validate features for media players.""" - supported_modes = get_media_player_features(state) - - if not supported_modes: + if not (supported_modes := get_media_player_features(state)): _LOGGER.error("%s does not support any media_player features", state.entity_id) return False diff --git a/homeassistant/components/lastfm/sensor.py b/homeassistant/components/lastfm/sensor.py index 66f05c5d34d..10623924c90 100644 --- a/homeassistant/components/lastfm/sensor.py +++ b/homeassistant/components/lastfm/sensor.py @@ -86,20 +86,17 @@ class LastfmSensor(SensorEntity): self._cover = self._user.get_image() self._playcount = self._user.get_playcount() - recent_tracks = self._user.get_recent_tracks(limit=2) - if recent_tracks: + if recent_tracks := self._user.get_recent_tracks(limit=2): last = recent_tracks[0] self._lastplayed = f"{last.track.artist} - {last.track.title}" - top_tracks = self._user.get_top_tracks(limit=1) - if top_tracks: + if top_tracks := self._user.get_top_tracks(limit=1): top = top_tracks[0] toptitle = re.search("', '(.+?)',", str(top)) topartist = re.search("'(.+?)',", str(top)) self._topplayed = f"{topartist.group(1)} - {toptitle.group(1)}" - now_playing = self._user.get_now_playing() - if now_playing is None: + if (now_playing := self._user.get_now_playing()) is None: self._state = STATE_NOT_SCROBBLING return diff --git a/homeassistant/components/nx584/binary_sensor.py b/homeassistant/components/nx584/binary_sensor.py index 7a999263332..38787afb080 100644 --- a/homeassistant/components/nx584/binary_sensor.py +++ b/homeassistant/components/nx584/binary_sensor.py @@ -137,8 +137,7 @@ class NX584Watcher(threading.Thread): """Throw away any existing events so we don't replay history.""" self._client.get_events() while True: - events = self._client.get_events() - if events: + if events := self._client.get_events(): self._process_events(events) def run(self): diff --git a/homeassistant/components/philips_js/light.py b/homeassistant/components/philips_js/light.py index 799b3b41631..93b65db90fa 100644 --- a/homeassistant/components/philips_js/light.py +++ b/homeassistant/components/philips_js/light.py @@ -200,8 +200,7 @@ class PhilipsTVLightEntity(CoordinatorEntity, LightEntity): current = self._tv.ambilight_current_configuration if current and self._tv.ambilight_mode != "manual": if current["isExpert"]: - settings = _get_settings(current) - if settings: + if settings := _get_settings(current): return _get_effect( EFFECT_EXPERT, current["styleName"], settings["algorithm"] ) diff --git a/homeassistant/components/vera/climate.py b/homeassistant/components/vera/climate.py index 69d5a3ccbfa..f5dc16cf4ae 100644 --- a/homeassistant/components/vera/climate.py +++ b/homeassistant/components/vera/climate.py @@ -92,8 +92,7 @@ class VeraThermostat(VeraDevice[veraApi.VeraThermostat], ClimateEntity): @property def fan_mode(self) -> str | None: """Return the fan setting.""" - mode = self.vera_device.get_fan_mode() - if mode == "ContinuousOn": + if self.vera_device.get_fan_mode() == "ContinuousOn": return FAN_ON return FAN_AUTO diff --git a/homeassistant/components/yeelight/light.py b/homeassistant/components/yeelight/light.py index 3d84a30f44e..e71b75755c0 100644 --- a/homeassistant/components/yeelight/light.py +++ b/homeassistant/components/yeelight/light.py @@ -465,8 +465,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity): @property def color_temp(self) -> int: """Return the color temperature.""" - temp_in_k = self._get_property("ct") - if temp_in_k: + if temp_in_k := self._get_property("ct"): self._color_temp = kelvin_to_mired(int(temp_in_k)) return self._color_temp @@ -530,9 +529,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity): @property def rgb_color(self) -> tuple: """Return the color property.""" - rgb = self._get_property("rgb") - - if rgb is None: + if (rgb := self._get_property("rgb")) is None: return None rgb = int(rgb) diff --git a/homeassistant/components/zha/api.py b/homeassistant/components/zha/api.py index 403af7c6612..48e70c86c1f 100644 --- a/homeassistant/components/zha/api.py +++ b/homeassistant/components/zha/api.py @@ -1145,10 +1145,8 @@ def async_load_api(hass): strobe = service.data.get(ATTR_WARNING_DEVICE_STROBE) level = service.data.get(ATTR_LEVEL) - zha_device = zha_gateway.get_device(ieee) - if zha_device is not None: - channel = _get_ias_wd_channel(zha_device) - if channel: + if (zha_device := zha_gateway.get_device(ieee)) is not None: + if channel := _get_ias_wd_channel(zha_device): await channel.issue_squawk(mode, strobe, level) else: _LOGGER.error( @@ -1189,10 +1187,8 @@ def async_load_api(hass): duty_mode = service.data.get(ATTR_WARNING_DEVICE_STROBE_DUTY_CYCLE) intensity = service.data.get(ATTR_WARNING_DEVICE_STROBE_INTENSITY) - zha_device = zha_gateway.get_device(ieee) - if zha_device is not None: - channel = _get_ias_wd_channel(zha_device) - if channel: + if (zha_device := zha_gateway.get_device(ieee)) is not None: + if channel := _get_ias_wd_channel(zha_device): await channel.issue_start_warning( mode, strobe, level, duration, duty_mode, intensity ) diff --git a/homeassistant/components/zha/climate.py b/homeassistant/components/zha/climate.py index b82cccd5324..300fdb9ef66 100644 --- a/homeassistant/components/zha/climate.py +++ b/homeassistant/components/zha/climate.py @@ -405,8 +405,7 @@ class Thermostat(ZhaEntity, ClimateEntity): # occupancy attribute is an unreportable attribute, but if we get # an attribute update for an "occupied" setpoint, there's a chance # occupancy has changed - occupancy = await self._thrm.get_occupancy() - if occupancy is True: + if await self._thrm.get_occupancy() is True: self._preset = PRESET_NONE self.debug("Attribute '%s' = %s update", record.attr_name, record.value)