mirror of
https://github.com/home-assistant/core.git
synced 2025-04-28 19:27: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:
|
if not self.success_init:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
actiontec_data = self.get_actiontec_data()
|
if (actiontec_data := self.get_actiontec_data()) is None:
|
||||||
if actiontec_data is None:
|
|
||||||
return False
|
return False
|
||||||
self.last_results = [
|
self.last_results = [
|
||||||
device for device in actiontec_data if device.timevalid > -60
|
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.
|
This is the only method that should fetch new data for Home Assistant.
|
||||||
"""
|
"""
|
||||||
brightness = self._light.get_brightness()
|
if (brightness := self._light.get_brightness()) is not None:
|
||||||
if brightness is not None:
|
|
||||||
self._attr_is_on = brightness != 0
|
self._attr_is_on = brightness != 0
|
||||||
self._attr_brightness = round(255 * (brightness / 4095))
|
self._attr_brightness = round(255 * (brightness / 4095))
|
||||||
|
@ -521,8 +521,7 @@ class GoogleEntity:
|
|||||||
if area and area.name:
|
if area and area.name:
|
||||||
device["roomHint"] = area.name
|
device["roomHint"] = area.name
|
||||||
|
|
||||||
device_info = await _get_device_info(device_entry)
|
if device_info := await _get_device_info(device_entry):
|
||||||
if device_info:
|
|
||||||
device["deviceInfo"] = device_info
|
device["deviceInfo"] = device_info
|
||||||
|
|
||||||
return device
|
return device
|
||||||
|
@ -21,8 +21,7 @@ async def async_setup_addon_panel(hass: HomeAssistant, hassio):
|
|||||||
hass.http.register_view(hassio_addon_panel)
|
hass.http.register_view(hassio_addon_panel)
|
||||||
|
|
||||||
# If panels are exists
|
# If panels are exists
|
||||||
panels = await hassio_addon_panel.get_panels()
|
if not (panels := await hassio_addon_panel.get_panels()):
|
||||||
if not panels:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Register available panels
|
# Register available panels
|
||||||
|
@ -335,9 +335,8 @@ class SourceManager:
|
|||||||
heos_const.EVENT_USER_CHANGED,
|
heos_const.EVENT_USER_CHANGED,
|
||||||
heos_const.EVENT_CONNECTED,
|
heos_const.EVENT_CONNECTED,
|
||||||
):
|
):
|
||||||
sources = await get_sources()
|
|
||||||
# If throttled, it will return None
|
# If throttled, it will return None
|
||||||
if sources:
|
if sources := await get_sources():
|
||||||
self.favorites, self.inputs = sources
|
self.favorites, self.inputs = sources
|
||||||
self.source_list = self._build_source_list()
|
self.source_list = self._build_source_list()
|
||||||
_LOGGER.debug("Sources updated due to changed event")
|
_LOGGER.debug("Sources updated due to changed event")
|
||||||
|
@ -333,8 +333,7 @@ class Camera(HomeAccessory, PyhapCamera):
|
|||||||
session_info["id"],
|
session_info["id"],
|
||||||
stream_config,
|
stream_config,
|
||||||
)
|
)
|
||||||
input_source = await self._async_get_stream_source()
|
if not (input_source := await self._async_get_stream_source()):
|
||||||
if not input_source:
|
|
||||||
_LOGGER.error("Camera has no stream source")
|
_LOGGER.error("Camera has no stream source")
|
||||||
return False
|
return False
|
||||||
if "-i " not in input_source:
|
if "-i " not in input_source:
|
||||||
|
@ -114,8 +114,7 @@ class TemperatureSensor(HomeAccessory):
|
|||||||
def async_update_state(self, new_state):
|
def async_update_state(self, new_state):
|
||||||
"""Update temperature after state changed."""
|
"""Update temperature after state changed."""
|
||||||
unit = new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS)
|
unit = new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS)
|
||||||
temperature = convert_to_float(new_state.state)
|
if temperature := convert_to_float(new_state.state):
|
||||||
if temperature:
|
|
||||||
temperature = temperature_to_homekit(temperature, unit)
|
temperature = temperature_to_homekit(temperature, unit)
|
||||||
self.char_temp.set_value(temperature)
|
self.char_temp.set_value(temperature)
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
@ -142,8 +141,7 @@ class HumiditySensor(HomeAccessory):
|
|||||||
@callback
|
@callback
|
||||||
def async_update_state(self, new_state):
|
def async_update_state(self, new_state):
|
||||||
"""Update accessory after state change."""
|
"""Update accessory after state change."""
|
||||||
humidity = convert_to_float(new_state.state)
|
if humidity := convert_to_float(new_state.state):
|
||||||
if humidity:
|
|
||||||
self.char_humidity.set_value(humidity)
|
self.char_humidity.set_value(humidity)
|
||||||
_LOGGER.debug("%s: Percent set to %d%%", self.entity_id, humidity)
|
_LOGGER.debug("%s: Percent set to %d%%", self.entity_id, humidity)
|
||||||
|
|
||||||
@ -170,8 +168,7 @@ class AirQualitySensor(HomeAccessory):
|
|||||||
@callback
|
@callback
|
||||||
def async_update_state(self, new_state):
|
def async_update_state(self, new_state):
|
||||||
"""Update accessory after state change."""
|
"""Update accessory after state change."""
|
||||||
density = convert_to_float(new_state.state)
|
if density := convert_to_float(new_state.state):
|
||||||
if density:
|
|
||||||
if self.char_density.value != density:
|
if self.char_density.value != density:
|
||||||
self.char_density.set_value(density)
|
self.char_density.set_value(density)
|
||||||
_LOGGER.debug("%s: Set density to %d", self.entity_id, density)
|
_LOGGER.debug("%s: Set density to %d", self.entity_id, density)
|
||||||
@ -206,8 +203,7 @@ class CarbonMonoxideSensor(HomeAccessory):
|
|||||||
@callback
|
@callback
|
||||||
def async_update_state(self, new_state):
|
def async_update_state(self, new_state):
|
||||||
"""Update accessory after state change."""
|
"""Update accessory after state change."""
|
||||||
value = convert_to_float(new_state.state)
|
if value := convert_to_float(new_state.state):
|
||||||
if value:
|
|
||||||
self.char_level.set_value(value)
|
self.char_level.set_value(value)
|
||||||
if value > self.char_peak.value:
|
if value > self.char_peak.value:
|
||||||
self.char_peak.set_value(value)
|
self.char_peak.set_value(value)
|
||||||
@ -242,8 +238,7 @@ class CarbonDioxideSensor(HomeAccessory):
|
|||||||
@callback
|
@callback
|
||||||
def async_update_state(self, new_state):
|
def async_update_state(self, new_state):
|
||||||
"""Update accessory after state change."""
|
"""Update accessory after state change."""
|
||||||
value = convert_to_float(new_state.state)
|
if value := convert_to_float(new_state.state):
|
||||||
if value:
|
|
||||||
self.char_level.set_value(value)
|
self.char_level.set_value(value)
|
||||||
if value > self.char_peak.value:
|
if value > self.char_peak.value:
|
||||||
self.char_peak.set_value(value)
|
self.char_peak.set_value(value)
|
||||||
@ -271,8 +266,7 @@ class LightSensor(HomeAccessory):
|
|||||||
@callback
|
@callback
|
||||||
def async_update_state(self, new_state):
|
def async_update_state(self, new_state):
|
||||||
"""Update accessory after state change."""
|
"""Update accessory after state change."""
|
||||||
luminance = convert_to_float(new_state.state)
|
if luminance := convert_to_float(new_state.state):
|
||||||
if luminance:
|
|
||||||
self.char_light.set_value(luminance)
|
self.char_light.set_value(luminance)
|
||||||
_LOGGER.debug("%s: Set to %d", self.entity_id, 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):
|
def validate_media_player_features(state, feature_list):
|
||||||
"""Validate features for media players."""
|
"""Validate features for media players."""
|
||||||
supported_modes = get_media_player_features(state)
|
if not (supported_modes := get_media_player_features(state)):
|
||||||
|
|
||||||
if not supported_modes:
|
|
||||||
_LOGGER.error("%s does not support any media_player features", state.entity_id)
|
_LOGGER.error("%s does not support any media_player features", state.entity_id)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -86,20 +86,17 @@ class LastfmSensor(SensorEntity):
|
|||||||
self._cover = self._user.get_image()
|
self._cover = self._user.get_image()
|
||||||
self._playcount = self._user.get_playcount()
|
self._playcount = self._user.get_playcount()
|
||||||
|
|
||||||
recent_tracks = self._user.get_recent_tracks(limit=2)
|
if recent_tracks := self._user.get_recent_tracks(limit=2):
|
||||||
if recent_tracks:
|
|
||||||
last = recent_tracks[0]
|
last = recent_tracks[0]
|
||||||
self._lastplayed = f"{last.track.artist} - {last.track.title}"
|
self._lastplayed = f"{last.track.artist} - {last.track.title}"
|
||||||
|
|
||||||
top_tracks = self._user.get_top_tracks(limit=1)
|
if top_tracks := self._user.get_top_tracks(limit=1):
|
||||||
if top_tracks:
|
|
||||||
top = top_tracks[0]
|
top = top_tracks[0]
|
||||||
toptitle = re.search("', '(.+?)',", str(top))
|
toptitle = re.search("', '(.+?)',", str(top))
|
||||||
topartist = re.search("'(.+?)',", str(top))
|
topartist = re.search("'(.+?)',", str(top))
|
||||||
self._topplayed = f"{topartist.group(1)} - {toptitle.group(1)}"
|
self._topplayed = f"{topartist.group(1)} - {toptitle.group(1)}"
|
||||||
|
|
||||||
now_playing = self._user.get_now_playing()
|
if (now_playing := self._user.get_now_playing()) is None:
|
||||||
if now_playing is None:
|
|
||||||
self._state = STATE_NOT_SCROBBLING
|
self._state = STATE_NOT_SCROBBLING
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -137,8 +137,7 @@ class NX584Watcher(threading.Thread):
|
|||||||
"""Throw away any existing events so we don't replay history."""
|
"""Throw away any existing events so we don't replay history."""
|
||||||
self._client.get_events()
|
self._client.get_events()
|
||||||
while True:
|
while True:
|
||||||
events = self._client.get_events()
|
if events := self._client.get_events():
|
||||||
if events:
|
|
||||||
self._process_events(events)
|
self._process_events(events)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
@ -200,8 +200,7 @@ class PhilipsTVLightEntity(CoordinatorEntity, LightEntity):
|
|||||||
current = self._tv.ambilight_current_configuration
|
current = self._tv.ambilight_current_configuration
|
||||||
if current and self._tv.ambilight_mode != "manual":
|
if current and self._tv.ambilight_mode != "manual":
|
||||||
if current["isExpert"]:
|
if current["isExpert"]:
|
||||||
settings = _get_settings(current)
|
if settings := _get_settings(current):
|
||||||
if settings:
|
|
||||||
return _get_effect(
|
return _get_effect(
|
||||||
EFFECT_EXPERT, current["styleName"], settings["algorithm"]
|
EFFECT_EXPERT, current["styleName"], settings["algorithm"]
|
||||||
)
|
)
|
||||||
|
@ -92,8 +92,7 @@ class VeraThermostat(VeraDevice[veraApi.VeraThermostat], ClimateEntity):
|
|||||||
@property
|
@property
|
||||||
def fan_mode(self) -> str | None:
|
def fan_mode(self) -> str | None:
|
||||||
"""Return the fan setting."""
|
"""Return the fan setting."""
|
||||||
mode = self.vera_device.get_fan_mode()
|
if self.vera_device.get_fan_mode() == "ContinuousOn":
|
||||||
if mode == "ContinuousOn":
|
|
||||||
return FAN_ON
|
return FAN_ON
|
||||||
return FAN_AUTO
|
return FAN_AUTO
|
||||||
|
|
||||||
|
@ -465,8 +465,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
|
|||||||
@property
|
@property
|
||||||
def color_temp(self) -> int:
|
def color_temp(self) -> int:
|
||||||
"""Return the color temperature."""
|
"""Return the color temperature."""
|
||||||
temp_in_k = self._get_property("ct")
|
if temp_in_k := self._get_property("ct"):
|
||||||
if temp_in_k:
|
|
||||||
self._color_temp = kelvin_to_mired(int(temp_in_k))
|
self._color_temp = kelvin_to_mired(int(temp_in_k))
|
||||||
return self._color_temp
|
return self._color_temp
|
||||||
|
|
||||||
@ -530,9 +529,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
|
|||||||
@property
|
@property
|
||||||
def rgb_color(self) -> tuple:
|
def rgb_color(self) -> tuple:
|
||||||
"""Return the color property."""
|
"""Return the color property."""
|
||||||
rgb = self._get_property("rgb")
|
if (rgb := self._get_property("rgb")) is None:
|
||||||
|
|
||||||
if rgb is None:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
rgb = int(rgb)
|
rgb = int(rgb)
|
||||||
|
@ -1145,10 +1145,8 @@ def async_load_api(hass):
|
|||||||
strobe = service.data.get(ATTR_WARNING_DEVICE_STROBE)
|
strobe = service.data.get(ATTR_WARNING_DEVICE_STROBE)
|
||||||
level = service.data.get(ATTR_LEVEL)
|
level = service.data.get(ATTR_LEVEL)
|
||||||
|
|
||||||
zha_device = zha_gateway.get_device(ieee)
|
if (zha_device := zha_gateway.get_device(ieee)) is not None:
|
||||||
if zha_device is not None:
|
if channel := _get_ias_wd_channel(zha_device):
|
||||||
channel = _get_ias_wd_channel(zha_device)
|
|
||||||
if channel:
|
|
||||||
await channel.issue_squawk(mode, strobe, level)
|
await channel.issue_squawk(mode, strobe, level)
|
||||||
else:
|
else:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
@ -1189,10 +1187,8 @@ def async_load_api(hass):
|
|||||||
duty_mode = service.data.get(ATTR_WARNING_DEVICE_STROBE_DUTY_CYCLE)
|
duty_mode = service.data.get(ATTR_WARNING_DEVICE_STROBE_DUTY_CYCLE)
|
||||||
intensity = service.data.get(ATTR_WARNING_DEVICE_STROBE_INTENSITY)
|
intensity = service.data.get(ATTR_WARNING_DEVICE_STROBE_INTENSITY)
|
||||||
|
|
||||||
zha_device = zha_gateway.get_device(ieee)
|
if (zha_device := zha_gateway.get_device(ieee)) is not None:
|
||||||
if zha_device is not None:
|
if channel := _get_ias_wd_channel(zha_device):
|
||||||
channel = _get_ias_wd_channel(zha_device)
|
|
||||||
if channel:
|
|
||||||
await channel.issue_start_warning(
|
await channel.issue_start_warning(
|
||||||
mode, strobe, level, duration, duty_mode, intensity
|
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
|
# occupancy attribute is an unreportable attribute, but if we get
|
||||||
# an attribute update for an "occupied" setpoint, there's a chance
|
# an attribute update for an "occupied" setpoint, there's a chance
|
||||||
# occupancy has changed
|
# occupancy has changed
|
||||||
occupancy = await self._thrm.get_occupancy()
|
if await self._thrm.get_occupancy() is True:
|
||||||
if occupancy is True:
|
|
||||||
self._preset = PRESET_NONE
|
self._preset = PRESET_NONE
|
||||||
|
|
||||||
self.debug("Attribute '%s' = %s update", record.attr_name, record.value)
|
self.debug("Attribute '%s' = %s update", record.attr_name, record.value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user