Use assignment expressions 13 (#57938)
This commit is contained in:
parent
c979e89b70
commit
1bcf39517a
20 changed files with 31 additions and 66 deletions
|
@ -95,9 +95,7 @@ class AvionLight(LightEntity):
|
|||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the specified or all lights on."""
|
||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||
|
||||
if brightness is not None:
|
||||
if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is not None:
|
||||
self._attr_brightness = brightness
|
||||
|
||||
self.set_state(self.brightness)
|
||||
|
|
|
@ -85,8 +85,7 @@ async def async_setup(hass, config):
|
|||
"""Set up AWS component."""
|
||||
hass.data[DATA_HASS_CONFIG] = config
|
||||
|
||||
conf = config.get(DOMAIN)
|
||||
if conf is None:
|
||||
if (conf := config.get(DOMAIN)) is None:
|
||||
# create a default conf using default profile
|
||||
conf = CONFIG_SCHEMA({ATTR_CREDENTIALS: DEFAULT_CREDENTIAL})
|
||||
|
||||
|
@ -159,9 +158,7 @@ async def _validate_aws_credentials(hass, credential):
|
|||
del aws_config[CONF_NAME]
|
||||
del aws_config[CONF_VALIDATE]
|
||||
|
||||
profile = aws_config.get(CONF_PROFILE_NAME)
|
||||
|
||||
if profile is not None:
|
||||
if (profile := aws_config.get(CONF_PROFILE_NAME)) is not None:
|
||||
session = aiobotocore.AioSession(profile=profile)
|
||||
del aws_config[CONF_PROFILE_NAME]
|
||||
if CONF_ACCESS_KEY_ID in aws_config:
|
||||
|
|
|
@ -82,8 +82,7 @@ async def async_get_service(hass, config, discovery_info=None):
|
|||
del aws_config[CONF_CREDENTIAL_NAME]
|
||||
|
||||
if session is None:
|
||||
profile = aws_config.get(CONF_PROFILE_NAME)
|
||||
if profile is not None:
|
||||
if (profile := aws_config.get(CONF_PROFILE_NAME)) is not None:
|
||||
session = aiobotocore.AioSession(profile=profile)
|
||||
del aws_config[CONF_PROFILE_NAME]
|
||||
else:
|
||||
|
|
|
@ -621,8 +621,7 @@ class ForkedDaapdMaster(MediaPlayerEntity):
|
|||
@property
|
||||
def media_image_url(self):
|
||||
"""Image url of current playing media."""
|
||||
url = self._track_info.get("artwork_url")
|
||||
if url:
|
||||
if url := self._track_info.get("artwork_url"):
|
||||
url = self._api.full_url(url)
|
||||
return url
|
||||
|
||||
|
@ -769,11 +768,10 @@ class ForkedDaapdUpdater:
|
|||
async def async_init(self):
|
||||
"""Perform async portion of class initialization."""
|
||||
server_config = await self._api.get_request("config")
|
||||
websocket_port = server_config.get("websocket_port")
|
||||
if websocket_port:
|
||||
if websocket_port := server_config.get("websocket_port"):
|
||||
self.websocket_handler = asyncio.create_task(
|
||||
self._api.start_websocket_handler(
|
||||
server_config["websocket_port"],
|
||||
websocket_port,
|
||||
WS_NOTIFY_EVENT_TYPES,
|
||||
self._update,
|
||||
WEBSOCKET_RECONNECT_TIME,
|
||||
|
|
|
@ -326,9 +326,7 @@ class HERETravelTimeSensor(SensorEntity):
|
|||
|
||||
async def _get_location_from_entity(self, entity_id: str) -> str | None:
|
||||
"""Get the location from the entity state or attributes."""
|
||||
entity = self.hass.states.get(entity_id)
|
||||
|
||||
if entity is None:
|
||||
if (entity := self.hass.states.get(entity_id)) is None:
|
||||
_LOGGER.error("Unable to find entity %s", entity_id)
|
||||
return None
|
||||
|
||||
|
@ -484,8 +482,7 @@ class HERETravelTimeData:
|
|||
if suppliers is not None:
|
||||
supplier_titles = []
|
||||
for supplier in suppliers:
|
||||
title = supplier.get("title")
|
||||
if title is not None:
|
||||
if (title := supplier.get("title")) is not None:
|
||||
supplier_titles.append(title)
|
||||
joined_supplier_titles = ",".join(supplier_titles)
|
||||
attribution = f"With the support of {joined_supplier_titles}. All information is provided without warranty of any kind."
|
||||
|
|
|
@ -28,8 +28,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Register the iZone component config."""
|
||||
conf = config.get(IZONE)
|
||||
if not conf:
|
||||
if not (conf := config.get(IZONE)):
|
||||
return True
|
||||
|
||||
hass.data[DATA_CONFIG] = conf
|
||||
|
|
|
@ -429,8 +429,7 @@ class ControllerDevice(ClimateEntity):
|
|||
if not self.supported_features & SUPPORT_TARGET_TEMPERATURE:
|
||||
self.async_schedule_update_ha_state(True)
|
||||
return
|
||||
temp = kwargs.get(ATTR_TEMPERATURE)
|
||||
if temp is not None:
|
||||
if (temp := kwargs.get(ATTR_TEMPERATURE)) is not None:
|
||||
await self.wrap_and_catch(self._controller.set_temp_setpoint(temp))
|
||||
|
||||
async def async_set_fan_mode(self, fan_mode: str) -> None:
|
||||
|
@ -627,8 +626,7 @@ class ZoneDevice(ClimateEntity):
|
|||
"""Set new target temperature."""
|
||||
if self._zone.mode != Zone.Mode.AUTO:
|
||||
return
|
||||
temp = kwargs.get(ATTR_TEMPERATURE)
|
||||
if temp is not None:
|
||||
if (temp := kwargs.get(ATTR_TEMPERATURE)) is not None:
|
||||
await self._controller.wrap_and_catch(self._zone.set_temp_setpoint(temp))
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
||||
|
|
|
@ -49,8 +49,7 @@ class DiscoveryService(pizone.Listener):
|
|||
|
||||
async def async_start_discovery_service(hass: HomeAssistant):
|
||||
"""Set up the pizone internal discovery."""
|
||||
disco = hass.data.get(DATA_DISCOVERY_SERVICE)
|
||||
if disco:
|
||||
if disco := hass.data.get(DATA_DISCOVERY_SERVICE):
|
||||
# Already started
|
||||
return disco
|
||||
|
||||
|
@ -75,8 +74,7 @@ async def async_start_discovery_service(hass: HomeAssistant):
|
|||
|
||||
async def async_stop_discovery_service(hass: HomeAssistant):
|
||||
"""Stop the discovery service."""
|
||||
disco = hass.data.get(DATA_DISCOVERY_SERVICE)
|
||||
if not disco:
|
||||
if not (disco := hass.data.get(DATA_DISCOVERY_SERVICE)):
|
||||
return
|
||||
|
||||
await disco.pi_disco.close()
|
||||
|
|
|
@ -72,9 +72,7 @@ class KaiterraApiData:
|
|||
|
||||
aqi, main_pollutant = None, None
|
||||
for sensor_name, sensor in device.items():
|
||||
points = sensor.get("points")
|
||||
|
||||
if not points:
|
||||
if not (points := sensor.get("points")):
|
||||
continue
|
||||
|
||||
point = points[0]
|
||||
|
|
|
@ -28,8 +28,7 @@ def setup(hass, config):
|
|||
|
||||
def logentries_event_listener(event):
|
||||
"""Listen for new messages on the bus and sends them to Logentries."""
|
||||
state = event.data.get("new_state")
|
||||
if state is None:
|
||||
if (state := event.data.get("new_state")) is None:
|
||||
return
|
||||
try:
|
||||
_state = state_helper.state_as_number(state)
|
||||
|
|
|
@ -420,9 +420,8 @@ async def handle_webhook(
|
|||
event_type = data[ATTR_EVENT_TYPE]
|
||||
device_registry = dr.async_get(hass)
|
||||
device_id = data[ATTR_DEVICE_ID]
|
||||
device = device_registry.async_get(device_id)
|
||||
|
||||
if not device:
|
||||
if not (device := device_registry.async_get(device_id)):
|
||||
return Response(
|
||||
text=f"Device not found: {device_id}",
|
||||
status=HTTPStatus.BAD_REQUEST,
|
||||
|
|
|
@ -193,12 +193,9 @@ async def async_setup(hass, config):
|
|||
for sms_id in service.data[ATTR_SMS_ID]:
|
||||
await modem_data.modem.delete_sms(sms_id)
|
||||
elif service.service == SERVICE_SET_OPTION:
|
||||
failover = service.data.get(ATTR_FAILOVER)
|
||||
if failover:
|
||||
if failover := service.data.get(ATTR_FAILOVER):
|
||||
await modem_data.modem.set_failover_mode(failover)
|
||||
|
||||
autoconnect = service.data.get(ATTR_AUTOCONNECT)
|
||||
if autoconnect:
|
||||
if autoconnect := service.data.get(ATTR_AUTOCONNECT):
|
||||
await modem_data.modem.set_autoconnect_mode(autoconnect)
|
||||
elif service.service == SERVICE_CONNECT_LTE:
|
||||
await modem_data.modem.connect_lte()
|
||||
|
|
|
@ -263,8 +263,7 @@ class OpenhomeDevice(MediaPlayerEntity):
|
|||
@property
|
||||
def media_artist(self):
|
||||
"""Artist of current playing media, music track only."""
|
||||
artists = self._track_information.get("artist")
|
||||
if artists:
|
||||
if artists := self._track_information.get("artist"):
|
||||
return artists[0]
|
||||
|
||||
@property
|
||||
|
|
|
@ -39,8 +39,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up Pilight Binary Sensor."""
|
||||
disarm = config.get(CONF_DISARM_AFTER_TRIGGER)
|
||||
if disarm:
|
||||
if config.get(CONF_DISARM_AFTER_TRIGGER):
|
||||
add_entities(
|
||||
[
|
||||
PilightTriggerSensor(
|
||||
|
|
|
@ -131,7 +131,6 @@ class ProliphixThermostat(ClimateEntity):
|
|||
|
||||
def set_temperature(self, **kwargs):
|
||||
"""Set new target temperature."""
|
||||
temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||
if temperature is None:
|
||||
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||
return
|
||||
self._pdp.setback = temperature
|
||||
|
|
|
@ -69,8 +69,7 @@ class RocketChatNotificationService(BaseNotificationService):
|
|||
data = kwargs.get(ATTR_DATA) or {}
|
||||
resp = self._server.chat_post_message(message, channel=self._room, **data)
|
||||
if resp.status_code == HTTP_OK:
|
||||
success = resp.json()["success"]
|
||||
if not success:
|
||||
if not resp.json()["success"]:
|
||||
_LOGGER.error("Unable to post Rocket.Chat message")
|
||||
else:
|
||||
_LOGGER.error(
|
||||
|
|
|
@ -367,8 +367,7 @@ class DeviceBroker:
|
|||
for evt in req.events:
|
||||
if evt.event_type != EVENT_TYPE_DEVICE:
|
||||
continue
|
||||
device = self.devices.get(evt.device_id)
|
||||
if not device:
|
||||
if not (device := self.devices.get(evt.device_id)):
|
||||
continue
|
||||
device.status.apply_attribute_update(
|
||||
evt.component_id,
|
||||
|
|
|
@ -184,8 +184,7 @@ class SmartThingsThermostat(SmartThingsEntity, ClimateEntity):
|
|||
async def async_set_temperature(self, **kwargs):
|
||||
"""Set new operation mode and target temperatures."""
|
||||
# Operation state
|
||||
operation_state = kwargs.get(ATTR_HVAC_MODE)
|
||||
if operation_state:
|
||||
if operation_state := kwargs.get(ATTR_HVAC_MODE):
|
||||
mode = STATE_TO_MODE[operation_state]
|
||||
await self._device.set_thermostat_mode(mode, set_status=True)
|
||||
await self.async_update()
|
||||
|
@ -235,8 +234,7 @@ class SmartThingsThermostat(SmartThingsEntity, ClimateEntity):
|
|||
supported_modes = self._device.status.supported_thermostat_modes
|
||||
if isinstance(supported_modes, Iterable):
|
||||
for mode in supported_modes:
|
||||
state = MODE_TO_STATE.get(mode)
|
||||
if state is not None:
|
||||
if (state := MODE_TO_STATE.get(mode)) is not None:
|
||||
modes.add(state)
|
||||
else:
|
||||
_LOGGER.debug(
|
||||
|
@ -363,8 +361,7 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateEntity):
|
|||
"""Set new target temperature."""
|
||||
tasks = []
|
||||
# operation mode
|
||||
operation_mode = kwargs.get(ATTR_HVAC_MODE)
|
||||
if operation_mode:
|
||||
if operation_mode := kwargs.get(ATTR_HVAC_MODE):
|
||||
if operation_mode == HVAC_MODE_OFF:
|
||||
tasks.append(self._device.switch_off(set_status=True))
|
||||
else:
|
||||
|
@ -398,8 +395,7 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateEntity):
|
|||
"""Update the calculated fields of the AC."""
|
||||
modes = {HVAC_MODE_OFF}
|
||||
for mode in self._device.status.supported_ac_modes:
|
||||
state = AC_MODE_TO_STATE.get(mode)
|
||||
if state is not None:
|
||||
if (state := AC_MODE_TO_STATE.get(mode)) is not None:
|
||||
modes.add(state)
|
||||
else:
|
||||
_LOGGER.debug(
|
||||
|
|
|
@ -67,7 +67,6 @@ class SmartThingsLock(SmartThingsEntity, LockEntity):
|
|||
state_attrs["lock_state"] = status.value
|
||||
if isinstance(status.data, dict):
|
||||
for st_attr, ha_attr in ST_LOCK_ATTR_MAP.items():
|
||||
data_val = status.data.get(st_attr)
|
||||
if data_val is not None:
|
||||
if (data_val := status.data.get(st_attr)) is not None:
|
||||
state_attrs[ha_attr] = data_val
|
||||
return state_attrs
|
||||
|
|
|
@ -188,8 +188,7 @@ def setup_smartapp(hass, app):
|
|||
for each SmartThings account that is configured in hass.
|
||||
"""
|
||||
manager = hass.data[DOMAIN][DATA_MANAGER]
|
||||
smartapp = manager.smartapps.get(app.app_id)
|
||||
if smartapp:
|
||||
if smartapp := manager.smartapps.get(app.app_id):
|
||||
# already setup
|
||||
return smartapp
|
||||
smartapp = manager.register(app.app_id, app.webhook_public_key)
|
||||
|
@ -206,8 +205,7 @@ async def setup_smartapp_endpoint(hass: HomeAssistant):
|
|||
SmartApps are an extension point within the SmartThings ecosystem and
|
||||
is used to receive push updates (i.e. device updates) from the cloud.
|
||||
"""
|
||||
data = hass.data.get(DOMAIN)
|
||||
if data:
|
||||
if hass.data.get(DOMAIN):
|
||||
# already setup
|
||||
return
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue