Use assignment expressions [A-I] (#66880)
This commit is contained in:
parent
6e49b0e122
commit
4f20a8023b
18 changed files with 20 additions and 43 deletions
|
@ -146,8 +146,7 @@ class LocalAdaxDevice(ClimateEntity):
|
||||||
|
|
||||||
async def async_set_temperature(self, **kwargs):
|
async def async_set_temperature(self, **kwargs):
|
||||||
"""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
|
||||||
await self._adax_data_handler.set_target_temperature(temperature)
|
await self._adax_data_handler.set_target_temperature(temperature)
|
||||||
|
|
||||||
|
|
|
@ -125,8 +125,7 @@ def _migrate_aftv_entity(hass, aftv, entry_unique_id):
|
||||||
# entity already exist, nothing to do
|
# entity already exist, nothing to do
|
||||||
return
|
return
|
||||||
|
|
||||||
old_unique_id = aftv.device_properties.get(PROP_SERIALNO)
|
if not (old_unique_id := aftv.device_properties.get(PROP_SERIALNO)):
|
||||||
if not old_unique_id:
|
|
||||||
# serial no not found, exit
|
# serial no not found, exit
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,7 @@ class AuroraEntity(Entity):
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str | None:
|
def unique_id(self) -> str | None:
|
||||||
"""Return the unique id for this device."""
|
"""Return the unique id for this device."""
|
||||||
serial = self._data.get(ATTR_SERIAL_NUMBER)
|
if (serial := self._data.get(ATTR_SERIAL_NUMBER)) is None:
|
||||||
if serial is None:
|
|
||||||
return None
|
return None
|
||||||
return f"{serial}_{self.entity_description.key}"
|
return f"{serial}_{self.entity_description.key}"
|
||||||
|
|
||||||
|
|
|
@ -99,8 +99,7 @@ class BalboaSpaClimate(BalboaEntity, ClimateEntity):
|
||||||
@property
|
@property
|
||||||
def hvac_action(self) -> str:
|
def hvac_action(self) -> str:
|
||||||
"""Return the current operation mode."""
|
"""Return the current operation mode."""
|
||||||
state = self._client.get_heatstate()
|
if self._client.get_heatstate() >= self._client.ON:
|
||||||
if state >= self._client.ON:
|
|
||||||
return CURRENT_HVAC_HEAT
|
return CURRENT_HVAC_HEAT
|
||||||
return CURRENT_HVAC_IDLE
|
return CURRENT_HVAC_IDLE
|
||||||
|
|
||||||
|
|
|
@ -78,9 +78,8 @@ async def async_setup_platform(
|
||||||
"""
|
"""
|
||||||
mac_addr = config[CONF_MAC]
|
mac_addr = config[CONF_MAC]
|
||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
switches = config.get(CONF_SWITCHES)
|
|
||||||
|
|
||||||
if switches:
|
if switches := config.get(CONF_SWITCHES):
|
||||||
platform_data = hass.data[DOMAIN].platforms.setdefault(Platform.SWITCH, {})
|
platform_data = hass.data[DOMAIN].platforms.setdefault(Platform.SWITCH, {})
|
||||||
platform_data.setdefault(mac_addr, []).extend(switches)
|
platform_data.setdefault(mac_addr, []).extend(switches)
|
||||||
|
|
||||||
|
|
|
@ -450,9 +450,7 @@ class EDL21Entity(SensorEntity):
|
||||||
@property
|
@property
|
||||||
def native_unit_of_measurement(self):
|
def native_unit_of_measurement(self):
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
unit = self._telegram.get("unit")
|
if (unit := self._telegram.get("unit")) is None:
|
||||||
|
|
||||||
if unit is None:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return SENSOR_UNIT_MAPPING[unit]
|
return SENSOR_UNIT_MAPPING[unit]
|
||||||
|
|
|
@ -90,8 +90,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
|
|
||||||
async def _async_migrate_unique_ids(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
async def _async_migrate_unique_ids(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||||
"""Migrate entities when the mac address gets discovered."""
|
"""Migrate entities when the mac address gets discovered."""
|
||||||
unique_id = entry.unique_id
|
if not (unique_id := entry.unique_id):
|
||||||
if not unique_id:
|
|
||||||
return
|
return
|
||||||
entry_id = entry.entry_id
|
entry_id = entry.entry_id
|
||||||
|
|
||||||
|
|
|
@ -165,8 +165,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
except FLUX_LED_EXCEPTIONS:
|
except FLUX_LED_EXCEPTIONS:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
else:
|
else:
|
||||||
mac_address = device[ATTR_ID]
|
if (mac_address := device[ATTR_ID]) is not None:
|
||||||
if mac_address is not None:
|
|
||||||
await self.async_set_unique_id(
|
await self.async_set_unique_id(
|
||||||
dr.format_mac(mac_address), raise_on_progress=False
|
dr.format_mac(mac_address), raise_on_progress=False
|
||||||
)
|
)
|
||||||
|
|
|
@ -82,8 +82,7 @@ def async_build_cached_discovery(entry: ConfigEntry) -> FluxLEDDiscovery:
|
||||||
@callback
|
@callback
|
||||||
def async_name_from_discovery(device: FluxLEDDiscovery) -> str:
|
def async_name_from_discovery(device: FluxLEDDiscovery) -> str:
|
||||||
"""Convert a flux_led discovery to a human readable name."""
|
"""Convert a flux_led discovery to a human readable name."""
|
||||||
mac_address = device[ATTR_ID]
|
if (mac_address := device[ATTR_ID]) is None:
|
||||||
if mac_address is None:
|
|
||||||
return device[ATTR_IPADDR]
|
return device[ATTR_IPADDR]
|
||||||
short_mac = mac_address[-6:]
|
short_mac = mac_address[-6:]
|
||||||
if device[ATTR_MODEL_DESCRIPTION]:
|
if device[ATTR_MODEL_DESCRIPTION]:
|
||||||
|
|
|
@ -60,9 +60,7 @@ def deflection_entities_list(
|
||||||
_LOGGER.debug("The FRITZ!Box has no %s options", SWITCH_TYPE_DEFLECTION)
|
_LOGGER.debug("The FRITZ!Box has no %s options", SWITCH_TYPE_DEFLECTION)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
deflection_list = avm_wrapper.get_ontel_deflections()
|
if not (deflection_list := avm_wrapper.get_ontel_deflections()):
|
||||||
|
|
||||||
if not deflection_list:
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
items = xmltodict.parse(deflection_list["NewDeflectionList"])["List"]["Item"]
|
items = xmltodict.parse(deflection_list["NewDeflectionList"])["List"]["Item"]
|
||||||
|
|
|
@ -331,8 +331,7 @@ class GroupManager:
|
||||||
heos_const.EVENT_CONNECTED,
|
heos_const.EVENT_CONNECTED,
|
||||||
SIGNAL_HEOS_PLAYER_ADDED,
|
SIGNAL_HEOS_PLAYER_ADDED,
|
||||||
):
|
):
|
||||||
groups = await self.async_get_group_membership()
|
if groups := await self.async_get_group_membership():
|
||||||
if groups:
|
|
||||||
self._group_membership = groups
|
self._group_membership = groups
|
||||||
_LOGGER.debug("Groups updated due to change event")
|
_LOGGER.debug("Groups updated due to change event")
|
||||||
# Let players know to update
|
# Let players know to update
|
||||||
|
|
|
@ -36,8 +36,7 @@ async def async_setup_entry(
|
||||||
"""Set up Hive thermostat based on a config entry."""
|
"""Set up Hive thermostat based on a config entry."""
|
||||||
|
|
||||||
hive = hass.data[DOMAIN][entry.entry_id]
|
hive = hass.data[DOMAIN][entry.entry_id]
|
||||||
devices = hive.session.deviceList.get("alarm_control_panel")
|
if devices := hive.session.deviceList.get("alarm_control_panel"):
|
||||||
if devices:
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[HiveAlarmControlPanelEntity(hive, dev) for dev in devices], True
|
[HiveAlarmControlPanelEntity(hive, dev) for dev in devices], True
|
||||||
)
|
)
|
||||||
|
|
|
@ -424,8 +424,7 @@ def format_version(version):
|
||||||
"""Extract the version string in a format homekit can consume."""
|
"""Extract the version string in a format homekit can consume."""
|
||||||
split_ver = str(version).replace("-", ".")
|
split_ver = str(version).replace("-", ".")
|
||||||
num_only = NUMBERS_ONLY_RE.sub("", split_ver)
|
num_only = NUMBERS_ONLY_RE.sub("", split_ver)
|
||||||
match = VERSION_RE.search(num_only)
|
if match := VERSION_RE.search(num_only):
|
||||||
if match:
|
|
||||||
return match.group(0)
|
return match.group(0)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -122,8 +122,7 @@ def _async_get_diagnostics(
|
||||||
|
|
||||||
devices = data["devices"] = []
|
devices = data["devices"] = []
|
||||||
for device_id in connection.devices.values():
|
for device_id in connection.devices.values():
|
||||||
device = device_registry.async_get(device_id)
|
if not (device := device_registry.async_get(device_id)):
|
||||||
if not device:
|
|
||||||
continue
|
continue
|
||||||
devices.append(_async_get_diagnostics_for_device(hass, device))
|
devices.append(_async_get_diagnostics_for_device(hass, device))
|
||||||
|
|
||||||
|
|
|
@ -272,8 +272,7 @@ def setup_platform(
|
||||||
devices = []
|
devices = []
|
||||||
for conf in discovery_info[ATTR_DISCOVER_DEVICES]:
|
for conf in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||||
state = conf.get(ATTR_PARAM)
|
state = conf.get(ATTR_PARAM)
|
||||||
entity_desc = SENSOR_DESCRIPTIONS.get(state)
|
if (entity_desc := SENSOR_DESCRIPTIONS.get(state)) is None:
|
||||||
if entity_desc is None:
|
|
||||||
name = conf.get(ATTR_NAME)
|
name = conf.get(ATTR_NAME)
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Sensor (%s) entity description is missing. Sensor state (%s) needs to be maintained",
|
"Sensor (%s) entity description is missing. Sensor state (%s) needs to be maintained",
|
||||||
|
|
|
@ -41,8 +41,7 @@ async def async_validate_trigger_config(hass: "HomeAssistant", config: ConfigTyp
|
||||||
device_id = config[CONF_DEVICE_ID]
|
device_id = config[CONF_DEVICE_ID]
|
||||||
# lookup device in HASS DeviceRegistry
|
# lookup device in HASS DeviceRegistry
|
||||||
dev_reg: dr.DeviceRegistry = dr.async_get(hass)
|
dev_reg: dr.DeviceRegistry = dr.async_get(hass)
|
||||||
device_entry = dev_reg.async_get(device_id)
|
if (device_entry := dev_reg.async_get(device_id)) is None:
|
||||||
if device_entry is None:
|
|
||||||
raise InvalidDeviceAutomationConfig(f"Device ID {device_id} is not valid")
|
raise InvalidDeviceAutomationConfig(f"Device ID {device_id} is not valid")
|
||||||
|
|
||||||
for conf_entry_id in device_entry.config_entries:
|
for conf_entry_id in device_entry.config_entries:
|
||||||
|
@ -64,8 +63,7 @@ async def async_attach_trigger(
|
||||||
device_id = config[CONF_DEVICE_ID]
|
device_id = config[CONF_DEVICE_ID]
|
||||||
# lookup device in HASS DeviceRegistry
|
# lookup device in HASS DeviceRegistry
|
||||||
dev_reg: dr.DeviceRegistry = dr.async_get(hass)
|
dev_reg: dr.DeviceRegistry = dr.async_get(hass)
|
||||||
device_entry = dev_reg.async_get(device_id)
|
if (device_entry := dev_reg.async_get(device_id)) is None:
|
||||||
if device_entry is None:
|
|
||||||
raise InvalidDeviceAutomationConfig(f"Device ID {device_id} is not valid")
|
raise InvalidDeviceAutomationConfig(f"Device ID {device_id} is not valid")
|
||||||
|
|
||||||
for conf_entry_id in device_entry.config_entries:
|
for conf_entry_id in device_entry.config_entries:
|
||||||
|
@ -90,8 +88,7 @@ async def async_get_triggers(hass: "HomeAssistant", device_id: str):
|
||||||
return []
|
return []
|
||||||
# lookup device in HASS DeviceRegistry
|
# lookup device in HASS DeviceRegistry
|
||||||
dev_reg: dr.DeviceRegistry = dr.async_get(hass)
|
dev_reg: dr.DeviceRegistry = dr.async_get(hass)
|
||||||
device_entry = dev_reg.async_get(device_id)
|
if (device_entry := dev_reg.async_get(device_id)) is None:
|
||||||
if device_entry is None:
|
|
||||||
raise ValueError(f"Device ID {device_id} is not valid")
|
raise ValueError(f"Device ID {device_id} is not valid")
|
||||||
|
|
||||||
# Iterate all config entries for this device
|
# Iterate all config entries for this device
|
||||||
|
|
|
@ -39,8 +39,7 @@ async def check_migration(hass: core.HomeAssistant, entry: ConfigEntry) -> None:
|
||||||
data[CONF_API_KEY] = data.pop(CONF_USERNAME)
|
data[CONF_API_KEY] = data.pop(CONF_USERNAME)
|
||||||
hass.config_entries.async_update_entry(entry, data=data)
|
hass.config_entries.async_update_entry(entry, data=data)
|
||||||
|
|
||||||
conf_api_version = entry.data.get(CONF_API_VERSION, 1)
|
if (conf_api_version := entry.data.get(CONF_API_VERSION, 1)) == 1:
|
||||||
if conf_api_version == 1:
|
|
||||||
# a bridge might have upgraded firmware since last run so
|
# a bridge might have upgraded firmware since last run so
|
||||||
# we discover its capabilities at every startup
|
# we discover its capabilities at every startup
|
||||||
websession = aiohttp_client.async_get_clientsession(hass)
|
websession = aiohttp_client.async_get_clientsession(hass)
|
||||||
|
|
|
@ -71,9 +71,7 @@ CONFIG_SCHEMA = vol.Schema(
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the Aqualink component."""
|
"""Set up the Aqualink component."""
|
||||||
conf = config.get(DOMAIN)
|
if (conf := config.get(DOMAIN)) is not None:
|
||||||
|
|
||||||
if conf is not None:
|
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
hass.config_entries.flow.async_init(
|
hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
|
Loading…
Add table
Reference in a new issue