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