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