Use assignment expressions 18 (#57967)
This commit is contained in:
parent
ff853b2d53
commit
f149bef9f3
14 changed files with 29 additions and 64 deletions
|
@ -18,9 +18,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
async def async_setup(hass, config):
|
||||
"""Set up the Cast component."""
|
||||
conf = config.get(DOMAIN)
|
||||
|
||||
if conf is not None:
|
||||
if (conf := config.get(DOMAIN)) is not None:
|
||||
media_player_config_validated = []
|
||||
media_player_config = conf.get("media_player", {})
|
||||
if not isinstance(media_player_config, list):
|
||||
|
|
|
@ -565,9 +565,7 @@ class CastDevice(MediaPlayerEntity):
|
|||
@property
|
||||
def state(self):
|
||||
"""Return the state of the player."""
|
||||
media_status = self._media_status()[0]
|
||||
|
||||
if media_status is None:
|
||||
if (media_status := self._media_status()[0]) is None:
|
||||
return None
|
||||
if media_status.player_is_playing:
|
||||
return STATE_PLAYING
|
||||
|
@ -588,8 +586,7 @@ class CastDevice(MediaPlayerEntity):
|
|||
@property
|
||||
def media_content_type(self):
|
||||
"""Content type of current playing media."""
|
||||
media_status = self._media_status()[0]
|
||||
if media_status is None:
|
||||
if (media_status := self._media_status()[0]) is None:
|
||||
return None
|
||||
if media_status.media_is_tvshow:
|
||||
return MEDIA_TYPE_TVSHOW
|
||||
|
@ -608,8 +605,7 @@ class CastDevice(MediaPlayerEntity):
|
|||
@property
|
||||
def media_image_url(self):
|
||||
"""Image url of current playing media."""
|
||||
media_status = self._media_status()[0]
|
||||
if media_status is None:
|
||||
if (media_status := self._media_status()[0]) is None:
|
||||
return None
|
||||
|
||||
images = media_status.images
|
||||
|
|
|
@ -154,8 +154,7 @@ class ConversationProcessView(http.HomeAssistantView):
|
|||
|
||||
async def _get_agent(hass: core.HomeAssistant) -> AbstractConversationAgent:
|
||||
"""Get the active conversation agent."""
|
||||
agent = hass.data.get(DATA_AGENT)
|
||||
if agent is None:
|
||||
if (agent := hass.data.get(DATA_AGENT)) is None:
|
||||
agent = hass.data[DATA_AGENT] = DefaultAgent(hass)
|
||||
await agent.async_initialize(hass.data.get(DATA_CONFIG))
|
||||
return agent
|
||||
|
|
|
@ -66,9 +66,7 @@ class DefaultAgent(AbstractConversationAgent):
|
|||
intents = self.hass.data.setdefault(DOMAIN, {})
|
||||
|
||||
for intent_type, utterances in config.get("intents", {}).items():
|
||||
conf = intents.get(intent_type)
|
||||
|
||||
if conf is None:
|
||||
if (conf := intents.get(intent_type)) is None:
|
||||
conf = intents[intent_type] = []
|
||||
|
||||
conf.extend(create_matcher(utterance) for utterance in utterances)
|
||||
|
|
|
@ -73,8 +73,7 @@ async def websocket_get_aldb(
|
|||
msg: dict,
|
||||
) -> None:
|
||||
"""Get the All-Link Database for an Insteon device."""
|
||||
device = devices[msg[DEVICE_ADDRESS]]
|
||||
if not device:
|
||||
if not (device := devices[msg[DEVICE_ADDRESS]]):
|
||||
notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND)
|
||||
return
|
||||
|
||||
|
@ -110,8 +109,7 @@ async def websocket_change_aldb_record(
|
|||
msg: dict,
|
||||
) -> None:
|
||||
"""Change an All-Link Database record for an Insteon device."""
|
||||
device = devices[msg[DEVICE_ADDRESS]]
|
||||
if not device:
|
||||
if not (device := devices[msg[DEVICE_ADDRESS]]):
|
||||
notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND)
|
||||
return
|
||||
|
||||
|
@ -144,8 +142,7 @@ async def websocket_create_aldb_record(
|
|||
msg: dict,
|
||||
) -> None:
|
||||
"""Create an All-Link Database record for an Insteon device."""
|
||||
device = devices[msg[DEVICE_ADDRESS]]
|
||||
if not device:
|
||||
if not (device := devices[msg[DEVICE_ADDRESS]]):
|
||||
notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND)
|
||||
return
|
||||
|
||||
|
@ -175,8 +172,7 @@ async def websocket_write_aldb(
|
|||
msg: dict,
|
||||
) -> None:
|
||||
"""Create an All-Link Database record for an Insteon device."""
|
||||
device = devices[msg[DEVICE_ADDRESS]]
|
||||
if not device:
|
||||
if not (device := devices[msg[DEVICE_ADDRESS]]):
|
||||
notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND)
|
||||
return
|
||||
|
||||
|
@ -199,8 +195,7 @@ async def websocket_load_aldb(
|
|||
msg: dict,
|
||||
) -> None:
|
||||
"""Create an All-Link Database record for an Insteon device."""
|
||||
device = devices[msg[DEVICE_ADDRESS]]
|
||||
if not device:
|
||||
if not (device := devices[msg[DEVICE_ADDRESS]]):
|
||||
notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND)
|
||||
return
|
||||
|
||||
|
@ -222,8 +217,7 @@ async def websocket_reset_aldb(
|
|||
msg: dict,
|
||||
) -> None:
|
||||
"""Create an All-Link Database record for an Insteon device."""
|
||||
device = devices[msg[DEVICE_ADDRESS]]
|
||||
if not device:
|
||||
if not (device := devices[msg[DEVICE_ADDRESS]]):
|
||||
notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND)
|
||||
return
|
||||
|
||||
|
@ -245,8 +239,7 @@ async def websocket_add_default_links(
|
|||
msg: dict,
|
||||
) -> None:
|
||||
"""Add the default All-Link Database records for an Insteon device."""
|
||||
device = devices[msg[DEVICE_ADDRESS]]
|
||||
if not device:
|
||||
if not (device := devices[msg[DEVICE_ADDRESS]]):
|
||||
notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND)
|
||||
return
|
||||
|
||||
|
@ -270,9 +263,7 @@ async def websocket_notify_on_aldb_status(
|
|||
msg: dict,
|
||||
) -> None:
|
||||
"""Tell Insteon a new ALDB record was added."""
|
||||
|
||||
device = devices[msg[DEVICE_ADDRESS]]
|
||||
if not device:
|
||||
if not (device := devices[msg[DEVICE_ADDRESS]]):
|
||||
notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND)
|
||||
return
|
||||
|
||||
|
|
|
@ -35,8 +35,7 @@ async def async_device_name(dev_registry, address):
|
|||
identifiers={(DOMAIN, str(address))}, connections=set()
|
||||
)
|
||||
if not ha_device:
|
||||
device = devices[address]
|
||||
if device:
|
||||
if device := devices[address]:
|
||||
return f"{device.description} ({device.model})"
|
||||
return ""
|
||||
return compute_device_name(ha_device)
|
||||
|
@ -61,8 +60,7 @@ async def websocket_get_device(
|
|||
) -> None:
|
||||
"""Get an Insteon device."""
|
||||
dev_registry = await hass.helpers.device_registry.async_get_registry()
|
||||
ha_device = dev_registry.async_get(msg[DEVICE_ID])
|
||||
if not ha_device:
|
||||
if not (ha_device := dev_registry.async_get(msg[DEVICE_ID])):
|
||||
notify_device_not_found(connection, msg, HA_DEVICE_NOT_FOUND)
|
||||
return
|
||||
device = get_insteon_device_from_ha_device(ha_device)
|
||||
|
|
|
@ -295,8 +295,7 @@ async def websocket_get_properties(
|
|||
msg: dict,
|
||||
) -> None:
|
||||
"""Add the default All-Link Database records for an Insteon device."""
|
||||
device = devices[msg[DEVICE_ADDRESS]]
|
||||
if not device:
|
||||
if not (device := devices[msg[DEVICE_ADDRESS]]):
|
||||
notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND)
|
||||
return
|
||||
|
||||
|
@ -321,8 +320,7 @@ async def websocket_change_properties_record(
|
|||
msg: dict,
|
||||
) -> None:
|
||||
"""Add the default All-Link Database records for an Insteon device."""
|
||||
device = devices[msg[DEVICE_ADDRESS]]
|
||||
if not device:
|
||||
if not (device := devices[msg[DEVICE_ADDRESS]]):
|
||||
notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND)
|
||||
return
|
||||
|
||||
|
@ -344,8 +342,7 @@ async def websocket_write_properties(
|
|||
msg: dict,
|
||||
) -> None:
|
||||
"""Add the default All-Link Database records for an Insteon device."""
|
||||
device = devices[msg[DEVICE_ADDRESS]]
|
||||
if not device:
|
||||
if not (device := devices[msg[DEVICE_ADDRESS]]):
|
||||
notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND)
|
||||
return
|
||||
|
||||
|
@ -376,8 +373,7 @@ async def websocket_load_properties(
|
|||
msg: dict,
|
||||
) -> None:
|
||||
"""Add the default All-Link Database records for an Insteon device."""
|
||||
device = devices[msg[DEVICE_ADDRESS]]
|
||||
if not device:
|
||||
if not (device := devices[msg[DEVICE_ADDRESS]]):
|
||||
notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND)
|
||||
return
|
||||
|
||||
|
@ -408,8 +404,7 @@ async def websocket_reset_properties(
|
|||
msg: dict,
|
||||
) -> None:
|
||||
"""Add the default All-Link Database records for an Insteon device."""
|
||||
device = devices[msg[DEVICE_ADDRESS]]
|
||||
if not device:
|
||||
if not (device := devices[msg[DEVICE_ADDRESS]]):
|
||||
notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND)
|
||||
return
|
||||
|
||||
|
|
|
@ -57,8 +57,7 @@ def set_default_port(schema: dict) -> dict:
|
|||
"""Set the default port based on the Hub version."""
|
||||
# If the ip_port is found do nothing
|
||||
# If it is not found the set the default
|
||||
ip_port = schema.get(CONF_IP_PORT)
|
||||
if not ip_port:
|
||||
if not schema.get(CONF_IP_PORT):
|
||||
hub_version = schema.get(CONF_HUB_VERSION)
|
||||
# Found hub_version but not ip_port
|
||||
schema[CONF_IP_PORT] = PORT_HUB_V1 if hub_version == 1 else PORT_HUB_V2
|
||||
|
|
|
@ -45,9 +45,7 @@ class OpenUvBinarySensor(OpenUvEntity, BinarySensorEntity):
|
|||
@callback
|
||||
def update_from_latest_data(self) -> None:
|
||||
"""Update the state."""
|
||||
data = self.openuv.data[DATA_PROTECTION_WINDOW]
|
||||
|
||||
if not data:
|
||||
if not (data := self.openuv.data[DATA_PROTECTION_WINDOW]):
|
||||
self._attr_available = False
|
||||
return
|
||||
|
||||
|
|
|
@ -134,9 +134,7 @@ class OpenUvSensor(OpenUvEntity, SensorEntity):
|
|||
@callback
|
||||
def update_from_latest_data(self) -> None:
|
||||
"""Update the state."""
|
||||
data = self.openuv.data[DATA_UV].get("result")
|
||||
|
||||
if not data:
|
||||
if not (data := self.openuv.data[DATA_UV].get("result")):
|
||||
self._attr_available = False
|
||||
return
|
||||
|
||||
|
|
|
@ -21,8 +21,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||
async def async_setup(hass, config):
|
||||
"""Configure Gammu state machine."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
sms_config = config.get(DOMAIN, {})
|
||||
if not sms_config:
|
||||
if not (sms_config := config.get(DOMAIN, {})):
|
||||
return True
|
||||
|
||||
hass.async_create_task(
|
||||
|
|
|
@ -51,8 +51,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the SQL sensor platform."""
|
||||
db_url = config.get(CONF_DB_URL)
|
||||
if not db_url:
|
||||
if not (db_url := config.get(CONF_DB_URL)):
|
||||
db_url = DEFAULT_URL.format(hass_config_path=hass.config.path(DEFAULT_DB_FILE))
|
||||
|
||||
sess = None
|
||||
|
|
|
@ -143,8 +143,7 @@ class LgWebOSMediaPlayerEntity(MediaPlayerEntity):
|
|||
|
||||
async def async_signal_handler(self, data):
|
||||
"""Handle domain-specific signal by calling appropriate method."""
|
||||
entity_ids = data[ATTR_ENTITY_ID]
|
||||
if entity_ids == ENTITY_MATCH_NONE:
|
||||
if (entity_ids := data[ATTR_ENTITY_ID]) == ENTITY_MATCH_NONE:
|
||||
return
|
||||
|
||||
if entity_ids == ENTITY_MATCH_ALL or self.entity_id in entity_ids:
|
||||
|
@ -368,8 +367,7 @@ class LgWebOSMediaPlayerEntity(MediaPlayerEntity):
|
|||
@cmd
|
||||
async def async_select_source(self, source):
|
||||
"""Select input source."""
|
||||
source_dict = self._source_list.get(source)
|
||||
if source_dict is None:
|
||||
if (source_dict := self._source_list.get(source)) is None:
|
||||
_LOGGER.warning("Source %s not found for %s", source, self.name)
|
||||
return
|
||||
if source_dict.get("title"):
|
||||
|
|
|
@ -86,8 +86,7 @@ class WiLightFan(WiLightDevice, FanEntity):
|
|||
):
|
||||
return 0
|
||||
|
||||
wl_speed = self._status.get("speed")
|
||||
if wl_speed is None:
|
||||
if (wl_speed := self._status.get("speed")) is None:
|
||||
return None
|
||||
return ordered_list_item_to_percentage(ORDERED_NAMED_FAN_SPEEDS, wl_speed)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue