Use assignment expressions 12 (#57937)
parent
7353ea5416
commit
4513ee4ea5
|
@ -86,8 +86,7 @@ class AdaxDevice(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._adax_data_handler.set_room_target_temperature(
|
||||
self._device_id, temperature, True
|
||||
|
|
|
@ -73,8 +73,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||
|
||||
async def async_setup(hass, config):
|
||||
"""Set up the AsusWrt integration."""
|
||||
conf = config.get(DOMAIN)
|
||||
if conf is None:
|
||||
if (conf := config.get(DOMAIN)) is None:
|
||||
return True
|
||||
|
||||
# save the options from config yaml
|
||||
|
|
|
@ -255,8 +255,7 @@ class DomainBlueprints:
|
|||
|
||||
def load_from_cache():
|
||||
"""Load blueprint from cache."""
|
||||
blueprint = self._blueprints[blueprint_path]
|
||||
if blueprint is None:
|
||||
if (blueprint := self._blueprints[blueprint_path]) is None:
|
||||
raise FailedToLoad(
|
||||
self.domain,
|
||||
blueprint_path,
|
||||
|
|
|
@ -73,8 +73,7 @@ class EnOceanLight(EnOceanEntity, LightEntity):
|
|||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the light source on or sets a specific dimmer value."""
|
||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||
if brightness is not None:
|
||||
if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is not None:
|
||||
self._brightness = brightness
|
||||
|
||||
bval = math.floor(self._brightness / 256.0 * 100.0)
|
||||
|
|
|
@ -52,8 +52,7 @@ async def async_attach_trigger(hass, config, action, automation_info):
|
|||
if not source_match(from_state, source) and not source_match(to_state, source):
|
||||
return
|
||||
|
||||
zone_state = hass.states.get(zone_entity_id)
|
||||
if zone_state is None:
|
||||
if (zone_state := hass.states.get(zone_entity_id)) is None:
|
||||
_LOGGER.warning(
|
||||
"Unable to execute automation %s: Zone %s not found",
|
||||
automation_info["name"],
|
||||
|
|
|
@ -150,8 +150,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||
|
||||
async def async_get_engine(hass, config, discovery_info=None):
|
||||
"""Set up Google Cloud TTS component."""
|
||||
key_file = config.get(CONF_KEY_FILE)
|
||||
if key_file:
|
||||
if key_file := config.get(CONF_KEY_FILE):
|
||||
key_file = hass.config.path(key_file)
|
||||
if not os.path.isfile(key_file):
|
||||
_LOGGER.error("File %s doesn't exist", key_file)
|
||||
|
|
|
@ -106,8 +106,7 @@ class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
|
|||
@property
|
||||
def temperature_unit(self) -> str:
|
||||
"""Return the unit of measurement."""
|
||||
uom = self._node.aux_properties.get(PROP_UOM)
|
||||
if not uom:
|
||||
if not (uom := self._node.aux_properties.get(PROP_UOM)):
|
||||
return self.hass.config.units.temperature_unit
|
||||
if uom.value == UOM_ISY_CELSIUS:
|
||||
return TEMP_CELSIUS
|
||||
|
@ -117,16 +116,14 @@ class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
|
|||
@property
|
||||
def current_humidity(self) -> int | None:
|
||||
"""Return the current humidity."""
|
||||
humidity = self._node.aux_properties.get(PROP_HUMIDITY)
|
||||
if not humidity:
|
||||
if not (humidity := self._node.aux_properties.get(PROP_HUMIDITY)):
|
||||
return None
|
||||
return int(humidity.value)
|
||||
|
||||
@property
|
||||
def hvac_mode(self) -> str | None:
|
||||
"""Return hvac operation ie. heat, cool mode."""
|
||||
hvac_mode = self._node.aux_properties.get(CMD_CLIMATE_MODE)
|
||||
if not hvac_mode:
|
||||
if not (hvac_mode := self._node.aux_properties.get(CMD_CLIMATE_MODE)):
|
||||
return None
|
||||
|
||||
# Which state values used depends on the mode property's UOM:
|
||||
|
|
|
@ -57,8 +57,7 @@ class ISYSensorEntity(ISYNodeEntity, SensorEntity):
|
|||
return UOM_FRIENDLY_NAME.get(uom[0], uom[0])
|
||||
|
||||
# Special cases for ISY UOM index units:
|
||||
isy_states = UOM_TO_STATES.get(uom)
|
||||
if isy_states:
|
||||
if isy_states := UOM_TO_STATES.get(uom):
|
||||
return isy_states
|
||||
|
||||
if uom in (UOM_ON_OFF, UOM_INDEX):
|
||||
|
|
|
@ -280,8 +280,7 @@ class OctoPrintAPI:
|
|||
|
||||
def update(self, sensor_type, end_point, group, tool=None):
|
||||
"""Return the value for sensor_type from the provided endpoint."""
|
||||
response = self.get(end_point)
|
||||
if response is not None:
|
||||
if (response := self.get(end_point)) is not None:
|
||||
return get_value_from_json(response, sensor_type, group, tool)
|
||||
|
||||
return response
|
||||
|
|
|
@ -85,9 +85,8 @@ WEBHOOK_SCHEMA = vol.Schema(
|
|||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Configure based on config entry."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
use_webhook = entry.data[CONF_USE_WEBHOOK]
|
||||
|
||||
if use_webhook:
|
||||
if entry.data[CONF_USE_WEBHOOK]:
|
||||
async_setup_webhook(hass, entry)
|
||||
else:
|
||||
await async_setup_coordinator(hass, entry)
|
||||
|
|
|
@ -131,8 +131,7 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
"""Begin manual configuration."""
|
||||
if user_input is not None and errors is None:
|
||||
user_input.pop(CONF_URL, None)
|
||||
host = user_input.get(CONF_HOST)
|
||||
if host:
|
||||
if host := user_input.get(CONF_HOST):
|
||||
port = user_input[CONF_PORT]
|
||||
prefix = "https" if user_input.get(CONF_SSL) else "http"
|
||||
user_input[CONF_URL] = f"{prefix}://{host}:{port}"
|
||||
|
|
|
@ -259,8 +259,7 @@ class PlexServer:
|
|||
"""Process a session payload received from a websocket callback."""
|
||||
session_payload = payload["PlaySessionStateNotification"][0]
|
||||
|
||||
state = session_payload["state"]
|
||||
if state == "buffering":
|
||||
if (state := session_payload["state"]) == "buffering":
|
||||
return
|
||||
|
||||
session_key = int(session_payload["sessionKey"])
|
||||
|
|
|
@ -148,8 +148,7 @@ class PrometheusMetrics:
|
|||
|
||||
def handle_event(self, event):
|
||||
"""Listen for new messages on the bus, and add them to Prometheus."""
|
||||
state = event.data.get("new_state")
|
||||
if state is None:
|
||||
if (state := event.data.get("new_state")) is None:
|
||||
return
|
||||
|
||||
entity_id = state.entity_id
|
||||
|
@ -318,8 +317,7 @@ class PrometheusMetrics:
|
|||
metric.labels(**self._labels(state)).set(value)
|
||||
|
||||
def _handle_climate_temp(self, state, attr, metric_name, metric_description):
|
||||
temp = state.attributes.get(attr)
|
||||
if temp:
|
||||
if temp := state.attributes.get(attr):
|
||||
if self._climate_units == TEMP_FAHRENHEIT:
|
||||
temp = fahrenheit_to_celsius(temp)
|
||||
metric = self._metric(
|
||||
|
@ -355,8 +353,7 @@ class PrometheusMetrics:
|
|||
"Current temperature in degrees Celsius",
|
||||
)
|
||||
|
||||
current_action = state.attributes.get(ATTR_HVAC_ACTION)
|
||||
if current_action:
|
||||
if current_action := state.attributes.get(ATTR_HVAC_ACTION):
|
||||
metric = self._metric(
|
||||
"climate_action",
|
||||
self.prometheus_cli.Gauge,
|
||||
|
|
|
@ -30,9 +30,7 @@ async def _async_reproduce_state(
|
|||
reproduce_options: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
"""Reproduce a single state."""
|
||||
cur_state = hass.states.get(state.entity_id)
|
||||
|
||||
if cur_state is None:
|
||||
if (cur_state := hass.states.get(state.entity_id)) is None:
|
||||
_LOGGER.warning("Unable to find entity %s", state.entity_id)
|
||||
return
|
||||
|
||||
|
|
|
@ -79,8 +79,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
"""Set up the Shelly component."""
|
||||
hass.data[DOMAIN] = {DATA_CONFIG_ENTRY: {}}
|
||||
|
||||
conf = config.get(DOMAIN)
|
||||
if conf is not None:
|
||||
if (conf := config.get(DOMAIN)) is not None:
|
||||
hass.data[DOMAIN][CONF_COAP_PORT] = conf[CONF_COAP_PORT]
|
||||
|
||||
return True
|
||||
|
@ -233,9 +232,8 @@ class BlockDeviceWrapper(update_coordinator.DataUpdateCoordinator):
|
|||
) -> None:
|
||||
"""Initialize the Shelly device wrapper."""
|
||||
self.device_id: str | None = None
|
||||
sleep_period = entry.data["sleep_period"]
|
||||
|
||||
if sleep_period:
|
||||
if sleep_period := entry.data["sleep_period"]:
|
||||
update_interval = SLEEP_PERIOD_MULTIPLIER * sleep_period
|
||||
else:
|
||||
update_interval = (
|
||||
|
|
|
@ -82,15 +82,13 @@ async def async_setup_entry(hass, config_entry):
|
|||
async def add_item_service(call):
|
||||
"""Add an item with `name`."""
|
||||
data = hass.data[DOMAIN]
|
||||
name = call.data.get(ATTR_NAME)
|
||||
if name is not None:
|
||||
if (name := call.data.get(ATTR_NAME)) is not None:
|
||||
await data.async_add(name)
|
||||
|
||||
async def complete_item_service(call):
|
||||
"""Mark the item provided via `name` as completed."""
|
||||
data = hass.data[DOMAIN]
|
||||
name = call.data.get(ATTR_NAME)
|
||||
if name is None:
|
||||
if (name := call.data.get(ATTR_NAME)) is None:
|
||||
return
|
||||
try:
|
||||
item = [item for item in data.items if item["name"] == name][0]
|
||||
|
@ -102,8 +100,7 @@ async def async_setup_entry(hass, config_entry):
|
|||
async def incomplete_item_service(call):
|
||||
"""Mark the item provided via `name` as incomplete."""
|
||||
data = hass.data[DOMAIN]
|
||||
name = call.data.get(ATTR_NAME)
|
||||
if name is None:
|
||||
if (name := call.data.get(ATTR_NAME)) is None:
|
||||
return
|
||||
try:
|
||||
item = [item for item in data.items if item["name"] == name][0]
|
||||
|
|
|
@ -61,8 +61,7 @@ def _parse_legacy_options(
|
|||
)
|
||||
|
||||
# Parsing of sensors configuration
|
||||
config_sensors = entry.data.get(CONF_SENSORS)
|
||||
if not config_sensors:
|
||||
if not (config_sensors := entry.data.get(CONF_SENSORS)):
|
||||
return []
|
||||
|
||||
# Support import of legacy config that should have been removed from 0.99, but was still functional
|
||||
|
|
|
@ -207,8 +207,7 @@ class UtilityMeterSensor(RestoreEntity, SensorEntity):
|
|||
@callback
|
||||
def async_tariff_change(self, event):
|
||||
"""Handle tariff changes."""
|
||||
new_state = event.data.get("new_state")
|
||||
if new_state is None:
|
||||
if (new_state := event.data.get("new_state")) is None:
|
||||
return
|
||||
|
||||
self._change_status(new_state.state)
|
||||
|
|
|
@ -102,8 +102,7 @@ def _list_payload(item, children=None):
|
|||
|
||||
def _raw_item_payload(entity, item, parent_item=None, title=None, info=None):
|
||||
if "type" in item:
|
||||
thumbnail = item.get("albumart")
|
||||
if thumbnail:
|
||||
if thumbnail := item.get("albumart"):
|
||||
item_hash = str(hash(thumbnail))
|
||||
entity.thumbnail_cache.setdefault(item_hash, thumbnail)
|
||||
thumbnail = entity.get_browse_image_url(MEDIA_TYPE_MUSIC, item_hash)
|
||||
|
@ -156,8 +155,7 @@ async def browse_node(entity, media_library, media_content_type, media_content_i
|
|||
for item in first_list["items"]
|
||||
]
|
||||
info = navigation.get("info")
|
||||
title = first_list.get("title")
|
||||
if not title:
|
||||
if not (title := first_list.get("title")):
|
||||
if info:
|
||||
title = f"{info.get('album')} ({info.get('artist')})"
|
||||
else:
|
||||
|
|
|
@ -53,9 +53,7 @@ async def _async_reproduce_state(
|
|||
reproduce_options: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
"""Reproduce a single state."""
|
||||
cur_state = hass.states.get(state.entity_id)
|
||||
|
||||
if cur_state is None:
|
||||
if (cur_state := hass.states.get(state.entity_id)) is None:
|
||||
_LOGGER.warning("Unable to find entity %s", state.entity_id)
|
||||
return
|
||||
|
||||
|
|
|
@ -34,16 +34,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
"""Set up the Zabbix sensor platform."""
|
||||
sensors = []
|
||||
|
||||
zapi = hass.data[zabbix.DOMAIN]
|
||||
if not zapi:
|
||||
if not (zapi := hass.data[zabbix.DOMAIN]):
|
||||
_LOGGER.error("Zabbix integration hasn't been loaded? zapi is None")
|
||||
return False
|
||||
|
||||
_LOGGER.info("Connected to Zabbix API Version %s", zapi.api_version())
|
||||
|
||||
trigger_conf = config.get(_CONF_TRIGGERS)
|
||||
# The following code seems overly complex. Need to think about this...
|
||||
if trigger_conf:
|
||||
if trigger_conf := config.get(_CONF_TRIGGERS):
|
||||
hostids = trigger_conf.get(_CONF_HOSTIDS)
|
||||
individual = trigger_conf.get(_CONF_INDIVIDUAL)
|
||||
name = trigger_conf.get(CONF_NAME)
|
||||
|
|
Loading…
Reference in New Issue