Use assignment expressions 20 (#57969)
parent
398061706c
commit
487fa0a905
homeassistant/components
|
@ -131,8 +131,7 @@ class BuienradarCam(Camera):
|
|||
_LOGGER.debug("HTTP 304 - success")
|
||||
return True
|
||||
|
||||
last_modified = res.headers.get("Last-Modified")
|
||||
if last_modified:
|
||||
if last_modified := res.headers.get("Last-Modified"):
|
||||
self._last_modified = last_modified
|
||||
|
||||
self._last_image = await res.read()
|
||||
|
|
|
@ -786,8 +786,7 @@ class BrSensor(SensorEntity):
|
|||
|
||||
if sensor_type == SYMBOL or sensor_type.startswith(CONDITION):
|
||||
# update weather symbol & status text
|
||||
condition = data.get(CONDITION)
|
||||
if condition:
|
||||
if condition := data.get(CONDITION):
|
||||
if sensor_type == SYMBOL:
|
||||
new_state = condition.get(EXACTNL)
|
||||
if sensor_type == CONDITION:
|
||||
|
|
|
@ -133,12 +133,13 @@ class BrWeather(WeatherEntity):
|
|||
@property
|
||||
def condition(self):
|
||||
"""Return the current condition."""
|
||||
if self._data and self._data.condition:
|
||||
ccode = self._data.condition.get(CONDCODE)
|
||||
if ccode:
|
||||
conditions = self.hass.data[DOMAIN].get(DATA_CONDITION)
|
||||
if conditions:
|
||||
return conditions.get(ccode)
|
||||
if (
|
||||
self._data
|
||||
and self._data.condition
|
||||
and (ccode := self._data.condition.get(CONDCODE))
|
||||
and (conditions := self.hass.data[DOMAIN].get(DATA_CONDITION))
|
||||
):
|
||||
return conditions.get(ccode)
|
||||
|
||||
@property
|
||||
def temperature(self):
|
||||
|
|
|
@ -48,8 +48,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
debugpy.listen((conf[CONF_HOST], conf[CONF_PORT]))
|
||||
|
||||
wait = conf[CONF_WAIT]
|
||||
if wait:
|
||||
if conf[CONF_WAIT]:
|
||||
_LOGGER.warning(
|
||||
"Waiting for remote debug connection on %s:%s",
|
||||
conf[CONF_HOST],
|
||||
|
|
|
@ -598,8 +598,7 @@ class MQTT:
|
|||
"""
|
||||
self = hass.data[DATA_MQTT]
|
||||
|
||||
conf = hass.data.get(DATA_MQTT_CONFIG)
|
||||
if conf is None:
|
||||
if (conf := hass.data.get(DATA_MQTT_CONFIG)) is None:
|
||||
conf = CONFIG_SCHEMA({DOMAIN: dict(entry.data)})[DOMAIN]
|
||||
|
||||
self.conf = _merge_config(entry, conf)
|
||||
|
@ -622,8 +621,7 @@ class MQTT:
|
|||
else:
|
||||
proto = mqtt.MQTTv311
|
||||
|
||||
client_id = self.conf.get(CONF_CLIENT_ID)
|
||||
if client_id is None:
|
||||
if (client_id := self.conf.get(CONF_CLIENT_ID)) is None:
|
||||
# PAHO MQTT relies on the MQTT server to generate random client IDs.
|
||||
# However, that feature is not mandatory so we generate our own.
|
||||
client_id = mqtt.base62(uuid.uuid4().int, padding=22)
|
||||
|
@ -637,9 +635,7 @@ class MQTT:
|
|||
if username is not None:
|
||||
self._mqttc.username_pw_set(username, password)
|
||||
|
||||
certificate = self.conf.get(CONF_CERTIFICATE)
|
||||
|
||||
if certificate == "auto":
|
||||
if (certificate := self.conf.get(CONF_CERTIFICATE)) == "auto":
|
||||
certificate = certifi.where()
|
||||
|
||||
client_key = self.conf.get(CONF_CLIENT_KEY)
|
||||
|
@ -1002,8 +998,7 @@ async def websocket_remove_device(hass, connection, msg):
|
|||
device_id = msg["device_id"]
|
||||
dev_registry = await hass.helpers.device_registry.async_get_registry()
|
||||
|
||||
device = dev_registry.async_get(device_id)
|
||||
if not device:
|
||||
if not (device := dev_registry.async_get(device_id)):
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "Device not found"
|
||||
)
|
||||
|
|
|
@ -205,8 +205,7 @@ class MqttAlarm(MqttEntity, alarm.AlarmControlPanelEntity):
|
|||
@property
|
||||
def code_format(self):
|
||||
"""Return one or more digits/characters."""
|
||||
code = self._config.get(CONF_CODE)
|
||||
if code is None:
|
||||
if (code := self._config.get(CONF_CODE)) is None:
|
||||
return None
|
||||
if code == REMOTE_CODE or (isinstance(code, str) and re.search("^\\d+$", code)):
|
||||
return alarm.FORMAT_NUMBER
|
||||
|
|
|
@ -142,8 +142,7 @@ async def async_start( # noqa: C901
|
|||
payload[key] = f"{value[:-1]}{base}"
|
||||
if payload.get(CONF_AVAILABILITY):
|
||||
for availability_conf in payload[CONF_AVAILABILITY]:
|
||||
topic = availability_conf.get(CONF_TOPIC)
|
||||
if topic:
|
||||
if topic := availability_conf.get(CONF_TOPIC):
|
||||
if topic[0] == TOPIC_BASE:
|
||||
availability_conf[CONF_TOPIC] = f"{base}{topic[1:]}"
|
||||
if topic[-1] == TOPIC_BASE:
|
||||
|
|
|
@ -826,8 +826,7 @@ class MqttLight(MqttEntity, LightEntity, RestoreEntity):
|
|||
|
||||
def render_rgbx(color, template, color_mode):
|
||||
"""Render RGBx payload."""
|
||||
tpl = self._command_templates[template]
|
||||
if tpl:
|
||||
if tpl := self._command_templates[template]:
|
||||
keys = ["red", "green", "blue"]
|
||||
if color_mode == COLOR_MODE_RGBW:
|
||||
keys.append("white")
|
||||
|
|
|
@ -31,8 +31,7 @@ async def async_setup_entry(hass, config_entry):
|
|||
hass.config_entries.async_setup_platforms(config_entry, PLATFORMS)
|
||||
|
||||
def _element_changed(element, changeset):
|
||||
change = changeset.get("last_change")
|
||||
if change is None:
|
||||
if (change := changeset.get("last_change")) is None:
|
||||
return
|
||||
if change.get("command") is None:
|
||||
return
|
||||
|
|
|
@ -62,8 +62,7 @@ async def _validate_input(data):
|
|||
|
||||
|
||||
def _make_url_from_data(data):
|
||||
host = data.get(CONF_HOST)
|
||||
if host:
|
||||
if host := data.get(CONF_HOST):
|
||||
return host
|
||||
|
||||
protocol = PROTOCOL_MAP[data[CONF_PROTOCOL]]
|
||||
|
|
|
@ -67,8 +67,7 @@ class UpbLight(UpbAttachedEntity, LightEntity):
|
|||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn on the light."""
|
||||
flash = kwargs.get(ATTR_FLASH)
|
||||
if flash:
|
||||
if flash := kwargs.get(ATTR_FLASH):
|
||||
await self.async_light_blink(0.5 if flash == "short" else 1.5)
|
||||
else:
|
||||
rate = kwargs.get(ATTR_TRANSITION, -1)
|
||||
|
|
|
@ -139,8 +139,7 @@ class ElectricalMeasurementChannel(ZigbeeChannel):
|
|||
@property
|
||||
def measurement_type(self) -> str | None:
|
||||
"""Return Measurement type."""
|
||||
meas_type = self.cluster.get("measurement_type")
|
||||
if meas_type is None:
|
||||
if (meas_type := self.cluster.get("measurement_type")) is None:
|
||||
return None
|
||||
|
||||
meas_type = self.MeasurementType(meas_type)
|
||||
|
|
|
@ -138,8 +138,7 @@ class Metering(ZigbeeChannel):
|
|||
@property
|
||||
def status(self) -> int | None:
|
||||
"""Return metering device status."""
|
||||
status = self.cluster.get("status")
|
||||
if status is None:
|
||||
if (status := self.cluster.get("status")) is None:
|
||||
return None
|
||||
if self.cluster.get("metering_device_type") == 0:
|
||||
# Electric metering device type
|
||||
|
|
|
@ -206,8 +206,7 @@ class ProbeEndpoint:
|
|||
def initialize(self, hass: HomeAssistant) -> None:
|
||||
"""Update device overrides config."""
|
||||
zha_config = hass.data[zha_const.DATA_ZHA].get(zha_const.DATA_ZHA_CONFIG, {})
|
||||
overrides = zha_config.get(zha_const.CONF_DEVICE_CONFIG)
|
||||
if overrides:
|
||||
if overrides := zha_config.get(zha_const.CONF_DEVICE_CONFIG):
|
||||
self._device_configs.update(overrides)
|
||||
|
||||
|
||||
|
@ -237,8 +236,7 @@ class GroupProbe:
|
|||
def _reprobe_group(self, group_id: int) -> None:
|
||||
"""Reprobe a group for entities after its members change."""
|
||||
zha_gateway = self._hass.data[zha_const.DATA_ZHA][zha_const.DATA_ZHA_GATEWAY]
|
||||
zha_group = zha_gateway.groups.get(group_id)
|
||||
if zha_group is None:
|
||||
if (zha_group := zha_gateway.groups.get(group_id)) is None:
|
||||
return
|
||||
self.discover_group_entities(zha_group)
|
||||
|
||||
|
|
|
@ -494,8 +494,7 @@ class ZHAGateway:
|
|||
self, zigpy_device: zha_typing.ZigpyDeviceType, restored: bool = False
|
||||
):
|
||||
"""Get or create a ZHA device."""
|
||||
zha_device = self._devices.get(zigpy_device.ieee)
|
||||
if zha_device is None:
|
||||
if (zha_device := self._devices.get(zigpy_device.ieee)) is None:
|
||||
zha_device = ZHADevice.new(self._hass, zigpy_device, self, restored)
|
||||
self._devices[zigpy_device.ieee] = zha_device
|
||||
device_registry_device = self.ha_device_registry.async_get_or_create(
|
||||
|
@ -649,8 +648,7 @@ class ZHAGateway:
|
|||
|
||||
async def async_remove_zigpy_group(self, group_id: int) -> None:
|
||||
"""Remove a Zigbee group from Zigpy."""
|
||||
group = self.groups.get(group_id)
|
||||
if not group:
|
||||
if not (group := self.groups.get(group_id)):
|
||||
_LOGGER.debug("Group: %s:0x%04x could not be found", group.name, group_id)
|
||||
return
|
||||
if group.members:
|
||||
|
|
|
@ -167,8 +167,7 @@ async def async_get_zha_device(hass, device_id):
|
|||
def find_state_attributes(states: list[State], key: str) -> Iterator[Any]:
|
||||
"""Find attributes with matching key from states."""
|
||||
for state in states:
|
||||
value = state.attributes.get(key)
|
||||
if value is not None:
|
||||
if (value := state.attributes.get(key)) is not None:
|
||||
yield value
|
||||
|
||||
|
||||
|
|
|
@ -131,9 +131,7 @@ class ZhaStorage:
|
|||
@bind_hass
|
||||
async def async_get_registry(hass: HomeAssistant) -> ZhaStorage:
|
||||
"""Return zha device storage instance."""
|
||||
task = hass.data.get(DATA_REGISTRY)
|
||||
|
||||
if task is None:
|
||||
if (task := hass.data.get(DATA_REGISTRY)) is None:
|
||||
|
||||
async def _load_reg() -> ZhaStorage:
|
||||
registry = ZhaStorage(hass)
|
||||
|
|
|
@ -481,8 +481,7 @@ class Light(BaseLight, ZhaEntity):
|
|||
attributes, from_cache=False
|
||||
)
|
||||
|
||||
color_mode = results.get("color_mode")
|
||||
if color_mode is not None:
|
||||
if (color_mode := results.get("color_mode")) is not None:
|
||||
if color_mode == LightColorMode.COLOR_TEMP:
|
||||
color_temp = results.get("color_temperature")
|
||||
if color_temp is not None and color_mode:
|
||||
|
|
Loading…
Reference in New Issue