mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Use assignment expressions 23 (#58180)
This commit is contained in:
parent
281adfe3c9
commit
70469e0979
@ -220,9 +220,7 @@ class ApnsNotificationService(BaseNotificationService):
|
||||
)
|
||||
|
||||
device_state = kwargs.get(ATTR_TARGET)
|
||||
message_data = kwargs.get(ATTR_DATA)
|
||||
|
||||
if message_data is None:
|
||||
if (message_data := kwargs.get(ATTR_DATA)) is None:
|
||||
message_data = {}
|
||||
|
||||
if isinstance(message, str):
|
||||
|
@ -217,8 +217,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
||||
}
|
||||
)
|
||||
|
||||
conf_mode = self.config_entry.data[CONF_MODE]
|
||||
if conf_mode == MODE_AP:
|
||||
if self.config_entry.data[CONF_MODE] == MODE_AP:
|
||||
data_schema = data_schema.extend(
|
||||
{
|
||||
vol.Optional(
|
||||
|
@ -79,8 +79,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
_LOGGER.info("Skipping account %s for bank %s", account.iban, fints_name)
|
||||
continue
|
||||
|
||||
account_name = account_config.get(account.iban)
|
||||
if not account_name:
|
||||
if not (account_name := account_config.get(account.iban)):
|
||||
account_name = f"{fints_name} - {account.iban}"
|
||||
accounts.append(FinTsAccount(client, account, account_name))
|
||||
_LOGGER.debug("Creating account %s for bank %s", account.iban, fints_name)
|
||||
|
@ -92,8 +92,7 @@ class AccessoryAidStorage:
|
||||
|
||||
def get_or_allocate_aid_for_entity_id(self, entity_id: str):
|
||||
"""Generate a stable aid for an entity id."""
|
||||
entity = self._entity_registry.async_get(entity_id)
|
||||
if not entity:
|
||||
if not (entity := self._entity_registry.async_get(entity_id)):
|
||||
return self.get_or_allocate_aid(None, entity_id)
|
||||
|
||||
sys_unique_id = get_system_unique_id(entity)
|
||||
|
@ -207,8 +207,7 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
|
||||
|
||||
async def async_set_temperature(self, **kwargs) -> None:
|
||||
"""Set new target temperature."""
|
||||
temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||
if temperature is None:
|
||||
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||
return
|
||||
|
||||
if self.min_temp <= temperature <= self.max_temp:
|
||||
|
@ -208,9 +208,8 @@ async def _async_activate_eco_mode_with_duration(
|
||||
) -> None:
|
||||
"""Service to activate eco mode with duration."""
|
||||
duration = service.data[ATTR_DURATION]
|
||||
hapid = service.data.get(ATTR_ACCESSPOINT_ID)
|
||||
|
||||
if hapid:
|
||||
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
||||
home = _get_home(hass, hapid)
|
||||
if home:
|
||||
await home.activate_absence_with_duration(duration)
|
||||
@ -224,9 +223,8 @@ async def _async_activate_eco_mode_with_period(
|
||||
) -> None:
|
||||
"""Service to activate eco mode with period."""
|
||||
endtime = service.data[ATTR_ENDTIME]
|
||||
hapid = service.data.get(ATTR_ACCESSPOINT_ID)
|
||||
|
||||
if hapid:
|
||||
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
||||
home = _get_home(hass, hapid)
|
||||
if home:
|
||||
await home.activate_absence_with_period(endtime)
|
||||
@ -239,9 +237,8 @@ async def _async_activate_vacation(hass: HomeAssistant, service: ServiceCall) ->
|
||||
"""Service to activate vacation."""
|
||||
endtime = service.data[ATTR_ENDTIME]
|
||||
temperature = service.data[ATTR_TEMPERATURE]
|
||||
hapid = service.data.get(ATTR_ACCESSPOINT_ID)
|
||||
|
||||
if hapid:
|
||||
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
||||
home = _get_home(hass, hapid)
|
||||
if home:
|
||||
await home.activate_vacation(endtime, temperature)
|
||||
@ -252,9 +249,7 @@ async def _async_activate_vacation(hass: HomeAssistant, service: ServiceCall) ->
|
||||
|
||||
async def _async_deactivate_eco_mode(hass: HomeAssistant, service: ServiceCall) -> None:
|
||||
"""Service to deactivate eco mode."""
|
||||
hapid = service.data.get(ATTR_ACCESSPOINT_ID)
|
||||
|
||||
if hapid:
|
||||
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
||||
home = _get_home(hass, hapid)
|
||||
if home:
|
||||
await home.deactivate_absence()
|
||||
@ -265,9 +260,7 @@ async def _async_deactivate_eco_mode(hass: HomeAssistant, service: ServiceCall)
|
||||
|
||||
async def _async_deactivate_vacation(hass: HomeAssistant, service: ServiceCall) -> None:
|
||||
"""Service to deactivate vacation."""
|
||||
hapid = service.data.get(ATTR_ACCESSPOINT_ID)
|
||||
|
||||
if hapid:
|
||||
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
||||
home = _get_home(hass, hapid)
|
||||
if home:
|
||||
await home.deactivate_vacation()
|
||||
@ -337,8 +330,7 @@ async def _async_reset_energy_counter(hass: HomeAssistant, service: ServiceCall)
|
||||
|
||||
def _get_home(hass: HomeAssistant, hapid: str) -> AsyncHome | None:
|
||||
"""Return a HmIP home."""
|
||||
hap = hass.data[HMIPC_DOMAIN].get(hapid)
|
||||
if hap:
|
||||
if hap := hass.data[HMIPC_DOMAIN].get(hapid):
|
||||
return hap.home
|
||||
|
||||
_LOGGER.info("No matching access point found for access point id %s", hapid)
|
||||
|
@ -123,8 +123,7 @@ class SignalUpdateCallback:
|
||||
if not device_entry:
|
||||
return
|
||||
for event in events:
|
||||
event_type = EVENT_NAME_MAP.get(event)
|
||||
if not event_type:
|
||||
if not (event_type := EVENT_NAME_MAP.get(event)):
|
||||
continue
|
||||
message = {
|
||||
"device_id": device_entry.id,
|
||||
|
@ -38,8 +38,7 @@ async def async_get_nest_device_id(hass: HomeAssistant, device_id: str) -> str |
|
||||
device_registry: DeviceRegistry = (
|
||||
await hass.helpers.device_registry.async_get_registry()
|
||||
)
|
||||
device = device_registry.async_get(device_id)
|
||||
if device:
|
||||
if device := device_registry.async_get(device_id):
|
||||
for (domain, unique_id) in device.identifiers:
|
||||
if domain == DOMAIN:
|
||||
return unique_id
|
||||
@ -54,16 +53,15 @@ async def async_get_device_trigger_types(
|
||||
# "shouldn't happen" cases
|
||||
subscriber = hass.data[DOMAIN][DATA_SUBSCRIBER]
|
||||
device_manager = await subscriber.async_get_device_manager()
|
||||
nest_device = device_manager.devices.get(nest_device_id)
|
||||
if not nest_device:
|
||||
if not (nest_device := device_manager.devices.get(nest_device_id)):
|
||||
raise InvalidDeviceAutomationConfig(f"Nest device not found {nest_device_id}")
|
||||
|
||||
# Determine the set of event types based on the supported device traits
|
||||
trigger_types = []
|
||||
for trait in nest_device.traits:
|
||||
trigger_type = DEVICE_TRAIT_TRIGGER_MAP.get(trait)
|
||||
if trigger_type:
|
||||
trigger_types.append(trigger_type)
|
||||
trigger_types = [
|
||||
trigger_type
|
||||
for trait in nest_device.traits
|
||||
if (trigger_type := DEVICE_TRAIT_TRIGGER_MAP.get(trait))
|
||||
]
|
||||
return trigger_types
|
||||
|
||||
|
||||
|
@ -86,8 +86,7 @@ class NetgearScannerEntity(NetgearDeviceEntity, ScannerEntity):
|
||||
|
||||
def get_hostname(self):
|
||||
"""Return the hostname of the given device or None if we don't know."""
|
||||
hostname = self._device["name"]
|
||||
if hostname == "--":
|
||||
if (hostname := self._device["name"]) == "--":
|
||||
return None
|
||||
|
||||
return hostname
|
||||
|
@ -159,8 +159,7 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
raise data_entry_flow.AbortFlow(RESULT_NOT_SUPPORTED)
|
||||
return False
|
||||
dev_info = info.get("device", {})
|
||||
device_type = dev_info.get("type")
|
||||
if device_type != "Samsung SmartTV":
|
||||
if (device_type := dev_info.get("type")) != "Samsung SmartTV":
|
||||
raise data_entry_flow.AbortFlow(RESULT_NOT_SUPPORTED)
|
||||
self._model = dev_info.get("modelName")
|
||||
name = dev_info.get("name")
|
||||
|
@ -154,8 +154,7 @@ def process_before_send(
|
||||
]
|
||||
|
||||
# Add additional tags based on what caused the event.
|
||||
platform = entity_platform.current_platform.get()
|
||||
if platform is not None:
|
||||
if (platform := entity_platform.current_platform.get()) is not None:
|
||||
# This event happened in a platform
|
||||
additional_tags["custom_component"] = "no"
|
||||
additional_tags["integration"] = platform.platform_name
|
||||
|
@ -249,8 +249,7 @@ class APISpaceApiView(HomeAssistantView):
|
||||
@staticmethod
|
||||
def get_sensor_data(hass, spaceapi, sensor):
|
||||
"""Get data from a sensor."""
|
||||
sensor_state = hass.states.get(sensor)
|
||||
if not sensor_state:
|
||||
if not (sensor_state := hass.states.get(sensor)):
|
||||
return None
|
||||
sensor_data = {ATTR_NAME: sensor_state.name, ATTR_VALUE: sensor_state.state}
|
||||
if ATTR_SENSOR_LOCATION in sensor_state.attributes:
|
||||
@ -279,9 +278,8 @@ class APISpaceApiView(HomeAssistantView):
|
||||
pass
|
||||
|
||||
state_entity = spaceapi["state"][ATTR_ENTITY_ID]
|
||||
space_state = hass.states.get(state_entity)
|
||||
|
||||
if space_state is not None:
|
||||
if (space_state := hass.states.get(state_entity)) is not None:
|
||||
state = {
|
||||
ATTR_OPEN: space_state.state != "off",
|
||||
ATTR_LASTCHANGE: dt_util.as_timestamp(space_state.last_updated),
|
||||
|
@ -67,9 +67,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({vol.Optional(CONF_HOST): cv.string})
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the ThinkingCleaner platform."""
|
||||
|
||||
host = config.get(CONF_HOST)
|
||||
if host:
|
||||
if host := config.get(CONF_HOST):
|
||||
devices = [ThinkingCleaner(host, "unknown")]
|
||||
else:
|
||||
discovery = Discovery()
|
||||
|
@ -42,8 +42,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({vol.Optional(CONF_HOST): cv.string})
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the ThinkingCleaner platform."""
|
||||
host = config.get(CONF_HOST)
|
||||
if host:
|
||||
if host := config.get(CONF_HOST):
|
||||
devices = [ThinkingCleaner(host, "unknown")]
|
||||
else:
|
||||
discovery = Discovery()
|
||||
|
@ -132,8 +132,7 @@ async def async_list_traces(hass, wanted_domain, wanted_key):
|
||||
|
||||
def async_store_trace(hass, trace, stored_traces):
|
||||
"""Store a trace if its key is valid."""
|
||||
key = trace.key
|
||||
if key:
|
||||
if key := trace.key:
|
||||
traces = hass.data[DATA_TRACE]
|
||||
if key not in traces:
|
||||
traces[key] = LimitedSizeDict(size_limit=stored_traces)
|
||||
|
@ -239,8 +239,7 @@ class TuyaCoverEntity(TuyaEntity, CoverEntity):
|
||||
):
|
||||
return None
|
||||
|
||||
position = self.device.status.get(dpcode)
|
||||
if position is None:
|
||||
if (position := self.device.status.get(dpcode)) is None:
|
||||
return None
|
||||
|
||||
return round(
|
||||
@ -256,8 +255,7 @@ class TuyaCoverEntity(TuyaEntity, CoverEntity):
|
||||
if self._tilt_dpcode is None or self._tilt_type is None:
|
||||
return None
|
||||
|
||||
angle = self.device.status.get(self._tilt_dpcode)
|
||||
if angle is None:
|
||||
if (angle := self.device.status.get(self._tilt_dpcode)) is None:
|
||||
return None
|
||||
|
||||
return round(self._tilt_type.remap_value_to(angle, 0, 100))
|
||||
|
Loading…
x
Reference in New Issue
Block a user