mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 10:47:51 +00:00
Use assignment expressions 38 (#58828)
This commit is contained in:
parent
b6d9e517c2
commit
72801867d6
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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"]
|
||||
)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user