Use assignment expressions 22 (#57971)
parent
ea2bc3fde1
commit
62c20860ac
|
@ -70,8 +70,7 @@ class AlexaConfig(AbstractConfig):
|
|||
return self._config[CONF_FILTER](entity_id)
|
||||
|
||||
entity_registry = er.async_get(self.hass)
|
||||
registry_entry = entity_registry.async_get(entity_id)
|
||||
if registry_entry:
|
||||
if registry_entry := entity_registry.async_get(entity_id):
|
||||
auxiliary_entity = registry_entry.entity_category in (
|
||||
ENTITY_CATEGORY_CONFIG,
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
|
|
|
@ -14,20 +14,14 @@ from .gateway import AugustGateway
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_validate_input(
|
||||
data,
|
||||
august_gateway,
|
||||
):
|
||||
async def async_validate_input(data, august_gateway):
|
||||
"""Validate the user input allows us to connect.
|
||||
|
||||
Data has the keys from DATA_SCHEMA with values provided by the user.
|
||||
|
||||
Request configuration steps from the user.
|
||||
"""
|
||||
|
||||
code = data.get(VERIFICATION_CODE_KEY)
|
||||
|
||||
if code is not None:
|
||||
if (code := data.get(VERIFICATION_CODE_KEY)) is not None:
|
||||
result = await august_gateway.authenticator.async_validate_verification_code(
|
||||
code
|
||||
)
|
||||
|
|
|
@ -90,8 +90,7 @@ class ServiceBusNotificationService(BaseNotificationService):
|
|||
if ATTR_TARGET in kwargs:
|
||||
dto[ATTR_ASB_TARGET] = kwargs[ATTR_TARGET]
|
||||
|
||||
data = kwargs.get(ATTR_DATA)
|
||||
if data:
|
||||
if data := kwargs.get(ATTR_DATA):
|
||||
dto.update(data)
|
||||
|
||||
queue_message = Message(json.dumps(dto))
|
||||
|
|
|
@ -160,8 +160,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
)
|
||||
return
|
||||
|
||||
hosts = config.get(CONF_HOSTS)
|
||||
if hosts:
|
||||
if hosts := config.get(CONF_HOSTS):
|
||||
for host in hosts:
|
||||
_add_player(
|
||||
hass,
|
||||
|
@ -173,15 +172,13 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
|
||||
async def async_service_handler(service):
|
||||
"""Map services to method of Bluesound devices."""
|
||||
method = SERVICE_TO_METHOD.get(service.service)
|
||||
if not method:
|
||||
if not (method := SERVICE_TO_METHOD.get(service.service)):
|
||||
return
|
||||
|
||||
params = {
|
||||
key: value for key, value in service.data.items() if key != ATTR_ENTITY_ID
|
||||
}
|
||||
entity_ids = service.data.get(ATTR_ENTITY_ID)
|
||||
if entity_ids:
|
||||
if entity_ids := service.data.get(ATTR_ENTITY_ID):
|
||||
target_players = [
|
||||
player
|
||||
for player in hass.data[DATA_BLUESOUND]
|
||||
|
@ -259,8 +256,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
if not self._icon:
|
||||
self._icon = self._sync_status.get("@icon", self.host)
|
||||
|
||||
master = self._sync_status.get("master")
|
||||
if master is not None:
|
||||
if (master := self._sync_status.get("master")) is not None:
|
||||
self._is_master = False
|
||||
master_host = master.get("#text")
|
||||
master_device = [
|
||||
|
@ -580,8 +576,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
if self.is_grouped and not self.is_master:
|
||||
return self._group_name
|
||||
|
||||
artist = self._status.get("artist")
|
||||
if not artist:
|
||||
if not (artist := self._status.get("artist")):
|
||||
artist = self._status.get("title2")
|
||||
return artist
|
||||
|
||||
|
@ -591,8 +586,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
if self._status is None or (self.is_grouped and not self.is_master):
|
||||
return None
|
||||
|
||||
album = self._status.get("album")
|
||||
if not album:
|
||||
if not (album := self._status.get("album")):
|
||||
album = self._status.get("title3")
|
||||
return album
|
||||
|
||||
|
@ -602,8 +596,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
if self._status is None or (self.is_grouped and not self.is_master):
|
||||
return None
|
||||
|
||||
url = self._status.get("image")
|
||||
if not url:
|
||||
if not (url := self._status.get("image")):
|
||||
return
|
||||
if url[0] == "/":
|
||||
url = f"http://{self.host}:{self.port}{url}"
|
||||
|
@ -620,8 +613,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
if self._last_status_update is None or mediastate == STATE_IDLE:
|
||||
return None
|
||||
|
||||
position = self._status.get("secs")
|
||||
if position is None:
|
||||
if (position := self._status.get("secs")) is None:
|
||||
return None
|
||||
|
||||
position = float(position)
|
||||
|
@ -636,8 +628,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
if self._status is None or (self.is_grouped and not self.is_master):
|
||||
return None
|
||||
|
||||
duration = self._status.get("totlen")
|
||||
if duration is None:
|
||||
if (duration := self._status.get("totlen")) is None:
|
||||
return None
|
||||
return float(duration)
|
||||
|
||||
|
@ -712,8 +703,7 @@ class BluesoundPlayer(MediaPlayerEntity):
|
|||
if self._status is None or (self.is_grouped and not self.is_master):
|
||||
return None
|
||||
|
||||
current_service = self._status.get("service", "")
|
||||
if current_service == "":
|
||||
if (current_service := self._status.get("service", "")) == "":
|
||||
return ""
|
||||
stream_url = self._status.get("streamUrl", "")
|
||||
|
||||
|
|
|
@ -140,8 +140,7 @@ class ECSensor(SensorEntity):
|
|||
else:
|
||||
self._unit = sensor_data.get("unit")
|
||||
|
||||
timestamp = metadata.get("timestamp")
|
||||
if timestamp:
|
||||
if timestamp := metadata.get("timestamp"):
|
||||
updated_utc = datetime.strptime(timestamp, "%Y%m%d%H%M%S").isoformat()
|
||||
else:
|
||||
updated_utc = None
|
||||
|
|
|
@ -125,8 +125,7 @@ class FritzboxConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
assert isinstance(host, str)
|
||||
self.context[CONF_HOST] = host
|
||||
|
||||
uuid = discovery_info.get(ATTR_UPNP_UDN)
|
||||
if uuid:
|
||||
if uuid := discovery_info.get(ATTR_UPNP_UDN):
|
||||
if uuid.startswith("uuid:"):
|
||||
uuid = uuid[5:]
|
||||
await self.async_set_unique_id(uuid)
|
||||
|
|
|
@ -57,8 +57,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||
|
||||
async def async_setup(hass, config):
|
||||
"""Set up the Hangouts bot component."""
|
||||
config = config.get(DOMAIN)
|
||||
if config is None:
|
||||
if (config := config.get(DOMAIN)) is None:
|
||||
hass.data[DOMAIN] = {
|
||||
CONF_INTENTS: {},
|
||||
CONF_DEFAULT_CONVERSATIONS: [],
|
||||
|
|
|
@ -211,8 +211,7 @@ class Life360Scanner:
|
|||
prev_seen = self._prev_seen(dev_id, last_seen)
|
||||
|
||||
if not loc:
|
||||
err_msg = member["issues"]["title"]
|
||||
if err_msg:
|
||||
if err_msg := member["issues"]["title"]:
|
||||
if member["issues"]["dialog"]:
|
||||
err_msg += f": {member['issues']['dialog']}"
|
||||
else:
|
||||
|
|
|
@ -208,8 +208,7 @@ class EventManager:
|
|||
continue
|
||||
|
||||
topic = msg.Topic._value_1
|
||||
parser = PARSERS.get(topic)
|
||||
if not parser:
|
||||
if not (parser := PARSERS.get(topic)):
|
||||
if topic not in UNHANDLED_TOPICS:
|
||||
LOGGER.info(
|
||||
"No registered handler for event from %s: %s",
|
||||
|
|
|
@ -164,9 +164,7 @@ class Proximity(Entity):
|
|||
|
||||
# Check for devices in the monitored zone.
|
||||
for device in self.proximity_devices:
|
||||
device_state = self.hass.states.get(device)
|
||||
|
||||
if device_state is None:
|
||||
if (device_state := self.hass.states.get(device)) is None:
|
||||
devices_to_calculate = True
|
||||
continue
|
||||
|
||||
|
|
|
@ -201,8 +201,7 @@ class RadioThermostat(ClimateEntity):
|
|||
|
||||
def set_fan_mode(self, fan_mode):
|
||||
"""Turn fan on/off."""
|
||||
code = FAN_MODE_TO_CODE.get(fan_mode)
|
||||
if code is not None:
|
||||
if (code := FAN_MODE_TO_CODE.get(fan_mode)) is not None:
|
||||
self.device.fmode = code
|
||||
|
||||
@property
|
||||
|
@ -322,8 +321,7 @@ class RadioThermostat(ClimateEntity):
|
|||
|
||||
def set_temperature(self, **kwargs):
|
||||
"""Set new target temperature."""
|
||||
temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||
if temperature is None:
|
||||
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||
return
|
||||
|
||||
temperature = round_temp(temperature)
|
||||
|
|
|
@ -24,8 +24,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Roku from a config entry."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
coordinator = hass.data[DOMAIN].get(entry.entry_id)
|
||||
if not coordinator:
|
||||
if not (coordinator := hass.data[DOMAIN].get(entry.entry_id)):
|
||||
coordinator = RokuDataUpdateCoordinator(hass, host=entry.data[CONF_HOST])
|
||||
hass.data[DOMAIN][entry.entry_id] = coordinator
|
||||
|
||||
|
|
|
@ -404,8 +404,7 @@ class ScriptEntity(ToggleEntity, RestoreEntity):
|
|||
script_trace.set_trace(trace_get())
|
||||
with trace_path("sequence"):
|
||||
this = None
|
||||
state = self.hass.states.get(self.entity_id)
|
||||
if state:
|
||||
if state := self.hass.states.get(self.entity_id):
|
||||
this = state.as_dict()
|
||||
script_vars = {"this": this, **(variables or {})}
|
||||
return await self.script.async_run(script_vars, context)
|
||||
|
|
|
@ -446,8 +446,7 @@ class TibberRtDataCoordinator(update_coordinator.DataUpdateCoordinator):
|
|||
|
||||
def get_live_measurement(self):
|
||||
"""Get live measurement data."""
|
||||
errors = self.data.get("errors")
|
||||
if errors:
|
||||
if errors := self.data.get("errors"):
|
||||
_LOGGER.error(errors[0])
|
||||
return None
|
||||
return self.data.get("data", {}).get("liveMeasurement")
|
||||
|
|
|
@ -89,8 +89,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
"""Handle the initial step."""
|
||||
errors = {}
|
||||
if user_input is not None:
|
||||
host = user_input[CONF_HOST]
|
||||
if not host:
|
||||
if not (host := user_input[CONF_HOST]):
|
||||
return await self.async_step_pick_device()
|
||||
try:
|
||||
device = await self._async_try_connect(host, raise_on_progress=False)
|
||||
|
|
|
@ -169,8 +169,7 @@ class SensorTrend(BinarySensorEntity):
|
|||
@callback
|
||||
def trend_sensor_state_listener(event):
|
||||
"""Handle state changes on the observed device."""
|
||||
new_state = event.data.get("new_state")
|
||||
if new_state is None:
|
||||
if (new_state := event.data.get("new_state")) is None:
|
||||
return
|
||||
try:
|
||||
if self._attribute:
|
||||
|
|
|
@ -313,8 +313,7 @@ async def async_send_message( # noqa: C901
|
|||
filesize = len(input_file)
|
||||
_LOGGER.debug("Filesize is %s bytes", filesize)
|
||||
|
||||
content_type = mimetypes.guess_type(path)[0]
|
||||
if content_type is None:
|
||||
if (content_type := mimetypes.guess_type(path)[0]) is None:
|
||||
content_type = DEFAULT_CONTENT_TYPE
|
||||
_LOGGER.debug("Content type is %s", content_type)
|
||||
|
||||
|
|
|
@ -1075,9 +1075,7 @@ class YeelightAmbientLight(YeelightColorLightWithoutNightlightSwitch):
|
|||
return "bright"
|
||||
|
||||
def _get_property(self, prop, default=None):
|
||||
bg_prop = self.PROPERTIES_MAPPING.get(prop)
|
||||
|
||||
if not bg_prop:
|
||||
if not (bg_prop := self.PROPERTIES_MAPPING.get(prop)):
|
||||
bg_prop = f"bg_{prop}"
|
||||
|
||||
return super()._get_property(bg_prop, default)
|
||||
|
|
Loading…
Reference in New Issue