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