Use assignment expressions 26 (#58187)
This commit is contained in:
parent
be201e3ebe
commit
184e0d7fdf
15 changed files with 29 additions and 57 deletions
|
@ -134,8 +134,7 @@ class AlexaConfig(alexa_config.AbstractConfig):
|
|||
return entity_expose
|
||||
|
||||
entity_registry = er.async_get(self.hass)
|
||||
registry_entry = entity_registry.async_get(entity_id)
|
||||
if registry_entry:
|
||||
if registry_entry := entity_registry.async_get(entity_id):
|
||||
auxiliary_entity = registry_entry.entity_category in (
|
||||
ENTITY_CATEGORY_CONFIG,
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
|
|
|
@ -132,8 +132,7 @@ class CloudGoogleConfig(AbstractConfig):
|
|||
return entity_expose
|
||||
|
||||
entity_registry = er.async_get(self.hass)
|
||||
registry_entry = entity_registry.async_get(entity_id)
|
||||
if registry_entry:
|
||||
if registry_entry := entity_registry.async_get(entity_id):
|
||||
auxiliary_entity = registry_entry.entity_category in (
|
||||
ENTITY_CATEGORY_CONFIG,
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
|
|
|
@ -352,8 +352,7 @@ class DlnaDmrOptionsFlowHandler(config_entries.OptionsFlow):
|
|||
|
||||
def _add_with_suggestion(key: str, validator: Callable) -> None:
|
||||
"""Add a field to with a suggested, not default, value."""
|
||||
suggested_value = options.get(key)
|
||||
if suggested_value is None:
|
||||
if (suggested_value := options.get(key)) is None:
|
||||
fields[vol.Optional(key)] = validator
|
||||
else:
|
||||
fields[
|
||||
|
|
|
@ -123,8 +123,7 @@ class EQ3BTSmartThermostat(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._thermostat.target_temperature = temperature
|
||||
|
||||
|
|
|
@ -377,11 +377,12 @@ class FitbitSensor(SensorEntity):
|
|||
@property
|
||||
def icon(self) -> str | None:
|
||||
"""Icon to use in the frontend, if any."""
|
||||
if self.entity_description.key == "devices/battery" and self.extra is not None:
|
||||
extra_battery = self.extra.get("battery")
|
||||
if extra_battery is not None:
|
||||
battery_level = BATTERY_LEVELS.get(extra_battery)
|
||||
if battery_level is not None:
|
||||
if (
|
||||
self.entity_description.key == "devices/battery"
|
||||
and self.extra is not None
|
||||
and (extra_battery := self.extra.get("battery")) is not None
|
||||
and (battery_level := BATTERY_LEVELS.get(extra_battery)) is not None
|
||||
):
|
||||
return icon_for_battery_level(battery_level=battery_level)
|
||||
return self.entity_description.icon
|
||||
|
||||
|
|
|
@ -364,8 +364,7 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
|||
|
||||
async def async_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._target_temp = temperature
|
||||
await self._async_control_heating(force=True)
|
||||
|
|
|
@ -282,8 +282,7 @@ class HoneywellUSThermostat(ClimateEntity):
|
|||
|
||||
def _set_temperature(self, **kwargs) -> None:
|
||||
"""Set new target temperature."""
|
||||
temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||
if temperature is None:
|
||||
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||
return
|
||||
try:
|
||||
# Get current mode
|
||||
|
@ -310,11 +309,9 @@ class HoneywellUSThermostat(ClimateEntity):
|
|||
|
||||
try:
|
||||
if HVAC_MODE_HEAT_COOL in self._hvac_mode_map:
|
||||
temperature = kwargs.get(ATTR_TARGET_TEMP_HIGH)
|
||||
if temperature:
|
||||
if temperature := kwargs.get(ATTR_TARGET_TEMP_HIGH):
|
||||
self._device.setpoint_cool = temperature
|
||||
temperature = kwargs.get(ATTR_TARGET_TEMP_LOW)
|
||||
if temperature:
|
||||
if temperature := kwargs.get(ATTR_TARGET_TEMP_LOW):
|
||||
self._device.setpoint_heat = temperature
|
||||
except somecomfort.SomeComfortError as err:
|
||||
_LOGGER.error("Invalid temperature %s: %s", temperature, err)
|
||||
|
|
|
@ -186,9 +186,8 @@ def get_service(hass, config, discovery_info=None):
|
|||
hass.http.register_view(HTML5PushCallbackView(registrations))
|
||||
|
||||
gcm_api_key = config.get(ATTR_GCM_API_KEY)
|
||||
gcm_sender_id = config.get(ATTR_GCM_SENDER_ID)
|
||||
|
||||
if gcm_sender_id is not None:
|
||||
if config.get(ATTR_GCM_SENDER_ID) is not None:
|
||||
add_manifest_json_key(ATTR_GCM_SENDER_ID, config.get(ATTR_GCM_SENDER_ID))
|
||||
|
||||
return HTML5NotificationService(
|
||||
|
@ -332,9 +331,7 @@ class HTML5PushCallbackView(HomeAssistantView):
|
|||
# https://auth0.com/docs/quickstart/backend/python
|
||||
def check_authorization_header(self, request):
|
||||
"""Check the authorization header."""
|
||||
|
||||
auth = request.headers.get(AUTHORIZATION)
|
||||
if not auth:
|
||||
if not (auth := request.headers.get(AUTHORIZATION)):
|
||||
return self.json_message(
|
||||
"Authorization header is expected", status_code=HTTPStatus.UNAUTHORIZED
|
||||
)
|
||||
|
@ -463,9 +460,7 @@ class HTML5NotificationService(BaseNotificationService):
|
|||
ATTR_TITLE: kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT),
|
||||
}
|
||||
|
||||
data = kwargs.get(ATTR_DATA)
|
||||
|
||||
if data:
|
||||
if data := kwargs.get(ATTR_DATA):
|
||||
# Pick out fields that should go into the notification directly vs
|
||||
# into the notification data dictionary.
|
||||
|
||||
|
@ -496,9 +491,8 @@ class HTML5NotificationService(BaseNotificationService):
|
|||
if priority not in ["normal", "high"]:
|
||||
priority = DEFAULT_PRIORITY
|
||||
payload["timestamp"] = timestamp * 1000 # Javascript ms since epoch
|
||||
targets = kwargs.get(ATTR_TARGET)
|
||||
|
||||
if not targets:
|
||||
if not (targets := kwargs.get(ATTR_TARGET)):
|
||||
targets = self.registrations.keys()
|
||||
|
||||
for target in list(targets):
|
||||
|
|
|
@ -218,8 +218,7 @@ class KNXClimate(KnxEntity, ClimateEntity):
|
|||
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set new target temperature."""
|
||||
temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||
if temperature is None:
|
||||
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||
return
|
||||
await self._device.set_target_temperature(temperature)
|
||||
self.async_write_ha_state()
|
||||
|
|
|
@ -60,8 +60,7 @@ class MobileAppEntity(TrackerEntity, RestoreEntity):
|
|||
"""Return device specific attributes."""
|
||||
attrs = {}
|
||||
for key in ATTR_KEYS:
|
||||
value = self._data.get(key)
|
||||
if value is not None:
|
||||
if (value := self._data.get(key)) is not None:
|
||||
attrs[key] = value
|
||||
|
||||
return attrs
|
||||
|
@ -74,9 +73,7 @@ class MobileAppEntity(TrackerEntity, RestoreEntity):
|
|||
@property
|
||||
def latitude(self):
|
||||
"""Return latitude value of the device."""
|
||||
gps = self._data.get(ATTR_GPS)
|
||||
|
||||
if gps is None:
|
||||
if (gps := self._data.get(ATTR_GPS)) is None:
|
||||
return None
|
||||
|
||||
return gps[0]
|
||||
|
@ -84,9 +81,7 @@ class MobileAppEntity(TrackerEntity, RestoreEntity):
|
|||
@property
|
||||
def longitude(self):
|
||||
"""Return longitude value of the device."""
|
||||
gps = self._data.get(ATTR_GPS)
|
||||
|
||||
if gps is None:
|
||||
if (gps := self._data.get(ATTR_GPS)) is None:
|
||||
return None
|
||||
|
||||
return gps[1]
|
||||
|
|
|
@ -114,9 +114,7 @@ class MobileAppNotificationService(BaseNotificationService):
|
|||
):
|
||||
data[ATTR_TITLE] = kwargs.get(ATTR_TITLE)
|
||||
|
||||
targets = kwargs.get(ATTR_TARGET)
|
||||
|
||||
if not targets:
|
||||
if not (targets := kwargs.get(ATTR_TARGET)):
|
||||
targets = push_registrations(self.hass).values()
|
||||
|
||||
if kwargs.get(ATTR_DATA) is not None:
|
||||
|
|
|
@ -264,9 +264,7 @@ async def webhook_fire_event(hass, config_entry, data):
|
|||
@validate_schema({vol.Required(ATTR_CAMERA_ENTITY_ID): cv.string})
|
||||
async def webhook_stream_camera(hass, config_entry, data):
|
||||
"""Handle a request to HLS-stream a camera."""
|
||||
camera = hass.states.get(data[ATTR_CAMERA_ENTITY_ID])
|
||||
|
||||
if camera is None:
|
||||
if (camera := hass.states.get(data[ATTR_CAMERA_ENTITY_ID])) is None:
|
||||
return webhook_response(
|
||||
{"success": False},
|
||||
registration=config_entry.data,
|
||||
|
|
|
@ -43,8 +43,7 @@ def setup(hass, config):
|
|||
|
||||
requires_auth = feedconfig.get("requires_api_password")
|
||||
|
||||
title = feedconfig.get("title")
|
||||
if title is not None:
|
||||
if (title := feedconfig.get("title")) is not None:
|
||||
title.hass = hass
|
||||
|
||||
items = feedconfig.get("items")
|
||||
|
|
|
@ -112,8 +112,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
|
||||
async def async_assume_state(service):
|
||||
"""Set state according to external service call.."""
|
||||
entity_ids = service.data.get(ATTR_ENTITY_ID)
|
||||
if entity_ids:
|
||||
if entity_ids := service.data.get(ATTR_ENTITY_ID):
|
||||
target_climate = [
|
||||
device for device in devices if device.entity_id in entity_ids
|
||||
]
|
||||
|
@ -299,8 +298,7 @@ class SensiboClimate(ClimateEntity):
|
|||
|
||||
async def async_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
|
||||
temperature = int(temperature)
|
||||
if temperature not in self._temperatures_list:
|
||||
|
|
|
@ -216,9 +216,7 @@ class UniversalMediaPlayer(MediaPlayerEntity):
|
|||
|
||||
def _entity_lkp(self, entity_id, state_attr=None):
|
||||
"""Look up an entity state."""
|
||||
state_obj = self.hass.states.get(entity_id)
|
||||
|
||||
if state_obj is None:
|
||||
if (state_obj := self.hass.states.get(entity_id)) is None:
|
||||
return
|
||||
|
||||
if state_attr:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue