mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use assignment expressions 39 (#58829)
This commit is contained in:
parent
72801867d6
commit
e0c0d00833
@ -86,9 +86,7 @@ class AmbiclimateFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
"""Received code for authentication."""
|
"""Received code for authentication."""
|
||||||
self._async_abort_entries_match()
|
self._async_abort_entries_match()
|
||||||
|
|
||||||
token_info = await self._get_token_info(code)
|
if await self._get_token_info(code) is None:
|
||||||
|
|
||||||
if token_info is None:
|
|
||||||
return self.async_abort(reason="access_token")
|
return self.async_abort(reason="access_token")
|
||||||
|
|
||||||
config = self.hass.data[DATA_AMBICLIMATE_IMPL].copy()
|
config = self.hass.data[DATA_AMBICLIMATE_IMPL].copy()
|
||||||
|
@ -74,8 +74,7 @@ class ArubaDeviceScanner(DeviceScanner):
|
|||||||
if not self.success_init:
|
if not self.success_init:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
data = self.get_aruba_data()
|
if not (data := self.get_aruba_data()):
|
||||||
if not data:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.last_results = data.values()
|
self.last_results = data.values()
|
||||||
|
@ -65,9 +65,7 @@ class CiscoDeviceScanner(DeviceScanner):
|
|||||||
|
|
||||||
Returns boolean if scanning successful.
|
Returns boolean if scanning successful.
|
||||||
"""
|
"""
|
||||||
string_result = self._get_arp_data()
|
if string_result := self._get_arp_data():
|
||||||
|
|
||||||
if string_result:
|
|
||||||
self.last_results = []
|
self.last_results = []
|
||||||
last_results = []
|
last_results = []
|
||||||
|
|
||||||
|
@ -89,8 +89,7 @@ class DlnaDmrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
await self._async_set_info_from_discovery(discovery)
|
await self._async_set_info_from_discovery(discovery)
|
||||||
return self._create_entry()
|
return self._create_entry()
|
||||||
|
|
||||||
discoveries = await self._async_get_discoveries()
|
if not (discoveries := await self._async_get_discoveries()):
|
||||||
if not discoveries:
|
|
||||||
# Nothing found, maybe the user knows an URL to try
|
# Nothing found, maybe the user knows an URL to try
|
||||||
return await self.async_step_manual()
|
return await self.async_step_manual()
|
||||||
|
|
||||||
|
@ -269,9 +269,7 @@ class ConfiguredDoorBird:
|
|||||||
if not self.webhook_is_registered(url):
|
if not self.webhook_is_registered(url):
|
||||||
self.device.change_favorite("http", f"Home Assistant ({event})", url)
|
self.device.change_favorite("http", f"Home Assistant ({event})", url)
|
||||||
|
|
||||||
fav_id = self.get_webhook_id(url)
|
if not self.get_webhook_id(url):
|
||||||
|
|
||||||
if not fav_id:
|
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
'Could not find favorite for URL "%s". ' 'Skipping sensor "%s"',
|
'Could not find favorite for URL "%s". ' 'Skipping sensor "%s"',
|
||||||
url,
|
url,
|
||||||
|
@ -260,8 +260,7 @@ class DSMREntity(SensorEntity):
|
|||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType:
|
||||||
"""Return the state of sensor, if available, translate if needed."""
|
"""Return the state of sensor, if available, translate if needed."""
|
||||||
value = self.get_dsmr_object_attr("value")
|
if (value := self.get_dsmr_object_attr("value")) is None:
|
||||||
if value is None:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if self.entity_description.key == obis_ref.ELECTRICITY_ACTIVE_TARIFF:
|
if self.entity_description.key == obis_ref.ELECTRICITY_ACTIVE_TARIFF:
|
||||||
|
@ -210,8 +210,7 @@ async def _async_activate_eco_mode_with_duration(
|
|||||||
duration = service.data[ATTR_DURATION]
|
duration = service.data[ATTR_DURATION]
|
||||||
|
|
||||||
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
||||||
home = _get_home(hass, hapid)
|
if home := _get_home(hass, hapid):
|
||||||
if home:
|
|
||||||
await home.activate_absence_with_duration(duration)
|
await home.activate_absence_with_duration(duration)
|
||||||
else:
|
else:
|
||||||
for hap in hass.data[HMIPC_DOMAIN].values():
|
for hap in hass.data[HMIPC_DOMAIN].values():
|
||||||
@ -225,8 +224,7 @@ async def _async_activate_eco_mode_with_period(
|
|||||||
endtime = service.data[ATTR_ENDTIME]
|
endtime = service.data[ATTR_ENDTIME]
|
||||||
|
|
||||||
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
||||||
home = _get_home(hass, hapid)
|
if home := _get_home(hass, hapid):
|
||||||
if home:
|
|
||||||
await home.activate_absence_with_period(endtime)
|
await home.activate_absence_with_period(endtime)
|
||||||
else:
|
else:
|
||||||
for hap in hass.data[HMIPC_DOMAIN].values():
|
for hap in hass.data[HMIPC_DOMAIN].values():
|
||||||
@ -239,8 +237,7 @@ async def _async_activate_vacation(hass: HomeAssistant, service: ServiceCall) ->
|
|||||||
temperature = service.data[ATTR_TEMPERATURE]
|
temperature = service.data[ATTR_TEMPERATURE]
|
||||||
|
|
||||||
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
||||||
home = _get_home(hass, hapid)
|
if home := _get_home(hass, hapid):
|
||||||
if home:
|
|
||||||
await home.activate_vacation(endtime, temperature)
|
await home.activate_vacation(endtime, temperature)
|
||||||
else:
|
else:
|
||||||
for hap in hass.data[HMIPC_DOMAIN].values():
|
for hap in hass.data[HMIPC_DOMAIN].values():
|
||||||
@ -250,8 +247,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."""
|
||||||
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
||||||
home = _get_home(hass, hapid)
|
if home := _get_home(hass, hapid):
|
||||||
if home:
|
|
||||||
await home.deactivate_absence()
|
await home.deactivate_absence()
|
||||||
else:
|
else:
|
||||||
for hap in hass.data[HMIPC_DOMAIN].values():
|
for hap in hass.data[HMIPC_DOMAIN].values():
|
||||||
@ -261,8 +257,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."""
|
||||||
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
|
||||||
home = _get_home(hass, hapid)
|
if home := _get_home(hass, hapid):
|
||||||
if home:
|
|
||||||
await home.deactivate_vacation()
|
await home.deactivate_vacation()
|
||||||
else:
|
else:
|
||||||
for hap in hass.data[HMIPC_DOMAIN].values():
|
for hap in hass.data[HMIPC_DOMAIN].values():
|
||||||
|
@ -133,8 +133,7 @@ def async_add_new_entities(
|
|||||||
tracked: set[str],
|
tracked: set[str],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Add new entities that are not already being tracked."""
|
"""Add new entities that are not already being tracked."""
|
||||||
hosts = _get_hosts(router)
|
if not (hosts := _get_hosts(router)):
|
||||||
if not hosts:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
track_wired_clients = router.config_entry.options.get(
|
track_wired_clients = router.config_entry.options.get(
|
||||||
@ -225,8 +224,7 @@ class HuaweiLteScannerEntity(HuaweiLteBaseEntity, ScannerEntity):
|
|||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Update state."""
|
"""Update state."""
|
||||||
hosts = _get_hosts(self.router)
|
if (hosts := _get_hosts(self.router)) is None:
|
||||||
if hosts is None:
|
|
||||||
self._available = False
|
self._available = False
|
||||||
return
|
return
|
||||||
self._available = True
|
self._available = True
|
||||||
|
@ -137,8 +137,7 @@ class KNXExposeSensor:
|
|||||||
async def _async_entity_changed(self, event: Event) -> None:
|
async def _async_entity_changed(self, event: Event) -> None:
|
||||||
"""Handle entity change."""
|
"""Handle entity change."""
|
||||||
new_state = event.data.get("new_state")
|
new_state = event.data.get("new_state")
|
||||||
new_value = self._get_expose_value(new_state)
|
if (new_value := self._get_expose_value(new_state)) is None:
|
||||||
if new_value is None:
|
|
||||||
return
|
return
|
||||||
old_state = event.data.get("old_state")
|
old_state = event.data.get("old_state")
|
||||||
# don't use default value for comparison on first state change (old_state is None)
|
# don't use default value for comparison on first state change (old_state is None)
|
||||||
|
@ -34,8 +34,7 @@ def setup(hass, config):
|
|||||||
hlmn = HassLaMetricManager(
|
hlmn = HassLaMetricManager(
|
||||||
client_id=conf[CONF_CLIENT_ID], client_secret=conf[CONF_CLIENT_SECRET]
|
client_id=conf[CONF_CLIENT_ID], client_secret=conf[CONF_CLIENT_SECRET]
|
||||||
)
|
)
|
||||||
devices = hlmn.manager.get_devices()
|
if not (devices := hlmn.manager.get_devices()):
|
||||||
if not devices:
|
|
||||||
_LOGGER.error("No LaMetric devices found")
|
_LOGGER.error("No LaMetric devices found")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -38,8 +38,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
|
|
||||||
dev = []
|
dev = []
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
node_id = linode.get_node_id(node)
|
if (node_id := linode.get_node_id(node)) is None:
|
||||||
if node_id is None:
|
|
||||||
_LOGGER.error("Node %s is not available", node)
|
_LOGGER.error("Node %s is not available", node)
|
||||||
return
|
return
|
||||||
dev.append(LinodeBinarySensor(linode, node_id))
|
dev.append(LinodeBinarySensor(linode, node_id))
|
||||||
|
@ -35,8 +35,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
|
|
||||||
dev = []
|
dev = []
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
node_id = linode.get_node_id(node)
|
if (node_id := linode.get_node_id(node)) is None:
|
||||||
if node_id is None:
|
|
||||||
_LOGGER.error("Node %s is not available", node)
|
_LOGGER.error("Node %s is not available", node)
|
||||||
return
|
return
|
||||||
dev.append(LinodeSwitch(linode, node_id))
|
dev.append(LinodeSwitch(linode, node_id))
|
||||||
|
@ -45,9 +45,7 @@ async def async_call_action_from_config(
|
|||||||
"Unable to resolve webhook ID from the device ID"
|
"Unable to resolve webhook ID from the device ID"
|
||||||
)
|
)
|
||||||
|
|
||||||
service_name = get_notify_service(hass, webhook_id)
|
if (service_name := get_notify_service(hass, webhook_id)) is None:
|
||||||
|
|
||||||
if service_name is None:
|
|
||||||
raise InvalidDeviceAutomationConfig(
|
raise InvalidDeviceAutomationConfig(
|
||||||
"Unable to find notify service for webhook ID"
|
"Unable to find notify service for webhook ID"
|
||||||
)
|
)
|
||||||
|
@ -490,9 +490,7 @@ class NetatmoSensor(NetatmoBase, SensorEntity):
|
|||||||
self._station_id = module_info.get("main_device", self._id)
|
self._station_id = module_info.get("main_device", self._id)
|
||||||
|
|
||||||
station = self._data.get_station(self._station_id)
|
station = self._data.get_station(self._station_id)
|
||||||
device = self._data.get_module(self._id)
|
if not (device := self._data.get_module(self._id)):
|
||||||
|
|
||||||
if not device:
|
|
||||||
# Assume it's a station if module can't be found
|
# Assume it's a station if module can't be found
|
||||||
device = station
|
device = station
|
||||||
|
|
||||||
|
@ -106,8 +106,7 @@ class RepetierSensor(SensorEntity):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the sensor."""
|
"""Update the sensor."""
|
||||||
data = self._get_data()
|
if (data := self._get_data()) is None:
|
||||||
if data is None:
|
|
||||||
return
|
return
|
||||||
state = data.pop("state")
|
state = data.pop("state")
|
||||||
_LOGGER.debug("Printer %s State %s", self.name, state)
|
_LOGGER.debug("Printer %s State %s", self.name, state)
|
||||||
@ -127,8 +126,7 @@ class RepetierTempSensor(RepetierSensor):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the sensor."""
|
"""Update the sensor."""
|
||||||
data = self._get_data()
|
if (data := self._get_data()) is None:
|
||||||
if data is None:
|
|
||||||
return
|
return
|
||||||
state = data.pop("state")
|
state = data.pop("state")
|
||||||
temp_set = data["temp_set"]
|
temp_set = data["temp_set"]
|
||||||
@ -155,8 +153,7 @@ class RepetierJobEndSensor(RepetierSensor):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the sensor."""
|
"""Update the sensor."""
|
||||||
data = self._get_data()
|
if (data := self._get_data()) is None:
|
||||||
if data is None:
|
|
||||||
return
|
return
|
||||||
job_name = data["job_name"]
|
job_name = data["job_name"]
|
||||||
start = data["start"]
|
start = data["start"]
|
||||||
@ -180,8 +177,7 @@ class RepetierJobStartSensor(RepetierSensor):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the sensor."""
|
"""Update the sensor."""
|
||||||
data = self._get_data()
|
if (data := self._get_data()) is None:
|
||||||
if data is None:
|
|
||||||
return
|
return
|
||||||
job_name = data["job_name"]
|
job_name = data["job_name"]
|
||||||
start = data["start"]
|
start = data["start"]
|
||||||
|
@ -62,7 +62,5 @@ class RippleSensor(SensorEntity):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest state of the sensor."""
|
"""Get the latest state of the sensor."""
|
||||||
|
if (balance := get_balance(self.address)) is not None:
|
||||||
balance = get_balance(self.address)
|
|
||||||
if balance is not None:
|
|
||||||
self._state = balance
|
self._state = balance
|
||||||
|
@ -68,9 +68,7 @@ class SkyHubDeviceScanner(DeviceScanner):
|
|||||||
"""Ensure the information from the Sky Hub is up to date."""
|
"""Ensure the information from the Sky Hub is up to date."""
|
||||||
_LOGGER.debug("Scanning")
|
_LOGGER.debug("Scanning")
|
||||||
|
|
||||||
data = await self._hub.async_get_skyhub_data()
|
if not (data := await self._hub.async_get_skyhub_data()):
|
||||||
|
|
||||||
if not data:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self.last_results = data
|
self.last_results = data
|
||||||
|
@ -78,8 +78,7 @@ class ThomsonDeviceScanner(DeviceScanner):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
_LOGGER.info("Checking ARP")
|
_LOGGER.info("Checking ARP")
|
||||||
data = self.get_thomson_data()
|
if not (data := self.get_thomson_data()):
|
||||||
if not data:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Flag C stands for CONNECTED
|
# Flag C stands for CONNECTED
|
||||||
|
@ -217,8 +217,7 @@ class WatsonIOTThread(threading.Thread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
"""Process incoming events."""
|
"""Process incoming events."""
|
||||||
while not self.shutdown:
|
while not self.shutdown:
|
||||||
event = self.get_events_json()
|
if event := self.get_events_json():
|
||||||
if event:
|
|
||||||
self.write_to_watson(event)
|
self.write_to_watson(event)
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
|
|
||||||
|
@ -64,8 +64,7 @@ SUPPORTED_TARGET_TEMPERATURE_STEP = 1
|
|||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Set up entry."""
|
"""Set up entry."""
|
||||||
auth: Auth = hass.data[DOMAIN][config_entry.entry_id][AUTH_INSTANCE_KEY]
|
auth: Auth = hass.data[DOMAIN][config_entry.entry_id][AUTH_INSTANCE_KEY]
|
||||||
said_list = auth.get_said_list()
|
if not (said_list := auth.get_said_list()):
|
||||||
if not said_list:
|
|
||||||
_LOGGER.debug("No appliances found")
|
_LOGGER.debug("No appliances found")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -47,8 +47,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
interval = config.get(CONF_SCAN_INTERVAL, interval)
|
interval = config.get(CONF_SCAN_INTERVAL, interval)
|
||||||
|
|
||||||
for xuid in users:
|
for xuid in users:
|
||||||
gamercard = get_user_gamercard(api, xuid)
|
if (gamercard := get_user_gamercard(api, xuid)) is None:
|
||||||
if gamercard is None:
|
|
||||||
continue
|
continue
|
||||||
entities.append(XboxSensor(api, xuid, gamercard, interval))
|
entities.append(XboxSensor(api, xuid, gamercard, interval))
|
||||||
|
|
||||||
|
@ -335,8 +335,7 @@ class ZWaveMeterSensor(ZWaveNumericSensor):
|
|||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> Mapping[str, int | str] | None:
|
def extra_state_attributes(self) -> Mapping[str, int | str] | None:
|
||||||
"""Return extra state attributes."""
|
"""Return extra state attributes."""
|
||||||
meter_type = get_meter_type(self.info.primary_value)
|
if meter_type := get_meter_type(self.info.primary_value):
|
||||||
if meter_type:
|
|
||||||
return {
|
return {
|
||||||
ATTR_METER_TYPE: meter_type.value,
|
ATTR_METER_TYPE: meter_type.value,
|
||||||
ATTR_METER_TYPE_NAME: meter_type.name,
|
ATTR_METER_TYPE_NAME: meter_type.name,
|
||||||
|
@ -52,9 +52,7 @@ async def async_detect_location_info(
|
|||||||
session: aiohttp.ClientSession,
|
session: aiohttp.ClientSession,
|
||||||
) -> LocationInfo | None:
|
) -> LocationInfo | None:
|
||||||
"""Detect location information."""
|
"""Detect location information."""
|
||||||
data = await _get_whoami(session)
|
if (data := await _get_whoami(session)) is None:
|
||||||
|
|
||||||
if data is None:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data["use_metric"] = data["country_code"] not in ("US", "MM", "LR")
|
data["use_metric"] = data["country_code"] not in ("US", "MM", "LR")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user