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