Use assignment expressions 37 (#58827)
This commit is contained in:
parent
8e03102892
commit
b6d9e517c2
14 changed files with 29 additions and 52 deletions
|
@ -255,8 +255,7 @@ class ArcamFmj(MediaPlayerEntity):
|
|||
@property
|
||||
def source(self):
|
||||
"""Return the current input source."""
|
||||
value = self._state.get_source()
|
||||
if value is None:
|
||||
if (value := self._state.get_source()) is None:
|
||||
return None
|
||||
return value.name
|
||||
|
||||
|
@ -268,32 +267,28 @@ class ArcamFmj(MediaPlayerEntity):
|
|||
@property
|
||||
def sound_mode(self):
|
||||
"""Name of the current sound mode."""
|
||||
value = self._state.get_decode_mode()
|
||||
if value is None:
|
||||
if (value := self._state.get_decode_mode()) is None:
|
||||
return None
|
||||
return value.name
|
||||
|
||||
@property
|
||||
def sound_mode_list(self):
|
||||
"""List of available sound modes."""
|
||||
values = self._state.get_decode_modes()
|
||||
if values is None:
|
||||
if (values := self._state.get_decode_modes()) is None:
|
||||
return None
|
||||
return [x.name for x in values]
|
||||
|
||||
@property
|
||||
def is_volume_muted(self):
|
||||
"""Boolean if volume is currently muted."""
|
||||
value = self._state.get_mute()
|
||||
if value is None:
|
||||
if (value := self._state.get_mute()) is None:
|
||||
return None
|
||||
return value
|
||||
|
||||
@property
|
||||
def volume_level(self):
|
||||
"""Volume level of device."""
|
||||
value = self._state.get_volume()
|
||||
if value is None:
|
||||
if (value := self._state.get_volume()) is None:
|
||||
return None
|
||||
return value / 99.0
|
||||
|
||||
|
@ -314,8 +309,7 @@ class ArcamFmj(MediaPlayerEntity):
|
|||
"""Content type of current playing media."""
|
||||
source = self._state.get_source()
|
||||
if source in (SourceCodes.DAB, SourceCodes.FM):
|
||||
preset = self._state.get_tuner_preset()
|
||||
if preset:
|
||||
if preset := self._state.get_tuner_preset():
|
||||
value = f"preset:{preset}"
|
||||
else:
|
||||
value = None
|
||||
|
@ -339,8 +333,7 @@ class ArcamFmj(MediaPlayerEntity):
|
|||
@property
|
||||
def media_artist(self):
|
||||
"""Artist of current playing media, music track only."""
|
||||
source = self._state.get_source()
|
||||
if source == SourceCodes.DAB:
|
||||
if self._state.get_source() == SourceCodes.DAB:
|
||||
value = self._state.get_dls_pdt()
|
||||
else:
|
||||
value = None
|
||||
|
@ -349,8 +342,7 @@ class ArcamFmj(MediaPlayerEntity):
|
|||
@property
|
||||
def media_title(self):
|
||||
"""Title of current playing media."""
|
||||
source = self._state.get_source()
|
||||
if source is None:
|
||||
if (source := self._state.get_source()) is None:
|
||||
return None
|
||||
|
||||
if channel := self.media_channel:
|
||||
|
|
|
@ -80,7 +80,5 @@ async def async_remove_user(
|
|||
"""Remove Home Assistant Cast user."""
|
||||
user_id: str | None = entry.data.get("user_id")
|
||||
|
||||
if user_id is not None:
|
||||
user = await hass.auth.async_get_user(user_id)
|
||||
if user:
|
||||
await hass.auth.async_remove_user(user)
|
||||
if user_id is not None and (user := await hass.auth.async_get_user(user_id)):
|
||||
await hass.auth.async_remove_user(user)
|
||||
|
|
|
@ -286,8 +286,7 @@ def get_manual_configuration(hass, config, conf, ihc_controller, controller_id):
|
|||
|
||||
def autosetup_ihc_products(hass: HomeAssistant, config, ihc_controller, controller_id):
|
||||
"""Auto setup of IHC products from the IHC project file."""
|
||||
project_xml = ihc_controller.get_project()
|
||||
if not project_xml:
|
||||
if not (project_xml := ihc_controller.get_project()):
|
||||
_LOGGER.error("Unable to read project from IHC controller")
|
||||
return False
|
||||
project = ElementTree.fromstring(project_xml)
|
||||
|
|
|
@ -63,8 +63,7 @@ async def websocket_get_device(
|
|||
if not (ha_device := dev_registry.async_get(msg[DEVICE_ID])):
|
||||
notify_device_not_found(connection, msg, HA_DEVICE_NOT_FOUND)
|
||||
return
|
||||
device = get_insteon_device_from_ha_device(ha_device)
|
||||
if not device:
|
||||
if not (device := get_insteon_device_from_ha_device(ha_device)):
|
||||
notify_device_not_found(connection, msg, INSTEON_DEVICE_NOT_FOUND)
|
||||
return
|
||||
ha_name = compute_device_name(ha_device)
|
||||
|
|
|
@ -68,8 +68,7 @@ class InsteonEntity(Entity):
|
|||
if (description := self._insteon_device.description) is None:
|
||||
description = "Unknown Device"
|
||||
# Get an extension label if there is one
|
||||
extension = self._get_label()
|
||||
if extension:
|
||||
if extension := self._get_label():
|
||||
extension = f" {extension}"
|
||||
return f"{description} {self._insteon_device.address}{extension}"
|
||||
|
||||
|
|
|
@ -39,8 +39,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
except KiwiException as exc:
|
||||
_LOGGER.error(exc)
|
||||
return
|
||||
available_locks = kiwi.get_locks()
|
||||
if not available_locks:
|
||||
if not (available_locks := kiwi.get_locks()):
|
||||
# No locks found; abort setup routine.
|
||||
_LOGGER.info("No KIWI locks found in your account")
|
||||
return
|
||||
|
|
|
@ -235,10 +235,7 @@ class MoldIndicator(SensorEntity):
|
|||
)
|
||||
return None
|
||||
|
||||
unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
hum = util.convert(state.state, float)
|
||||
|
||||
if hum is None:
|
||||
if (hum := util.convert(state.state, float)) is None:
|
||||
_LOGGER.error(
|
||||
"Unable to parse humidity sensor %s, state: %s",
|
||||
state.entity_id,
|
||||
|
@ -246,7 +243,7 @@ class MoldIndicator(SensorEntity):
|
|||
)
|
||||
return None
|
||||
|
||||
if unit != PERCENTAGE:
|
||||
if (unit := state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)) != PERCENTAGE:
|
||||
_LOGGER.error(
|
||||
"Humidity sensor %s has unsupported unit: %s %s",
|
||||
state.entity_id,
|
||||
|
|
|
@ -124,8 +124,7 @@ def _get_device_lookup(devices):
|
|||
"""Get a lookup structure for devices."""
|
||||
lookup = {}
|
||||
for event_code, event_config in devices.items():
|
||||
event = get_rfx_object(event_code)
|
||||
if event is None:
|
||||
if (event := get_rfx_object(event_code)) is None:
|
||||
continue
|
||||
device_id = get_device_id(
|
||||
event.device, data_bits=event_config.get(CONF_DATA_BITS)
|
||||
|
@ -313,10 +312,12 @@ def find_possible_pt2262_device(device_ids, device_id):
|
|||
def get_device_id(device, data_bits=None):
|
||||
"""Calculate a device id for device."""
|
||||
id_string = device.id_string
|
||||
if data_bits and device.packettype == DEVICE_PACKET_TYPE_LIGHTING4:
|
||||
masked_id = get_pt2262_deviceid(id_string, data_bits)
|
||||
if masked_id:
|
||||
id_string = masked_id.decode("ASCII")
|
||||
if (
|
||||
data_bits
|
||||
and device.packettype == DEVICE_PACKET_TYPE_LIGHTING4
|
||||
and (masked_id := get_pt2262_deviceid(id_string, data_bits))
|
||||
):
|
||||
id_string = masked_id.decode("ASCII")
|
||||
|
||||
return (f"{device.packettype:x}", f"{device.subtype:x}", id_string)
|
||||
|
||||
|
|
|
@ -114,8 +114,7 @@ async def async_setup_entry(
|
|||
return description
|
||||
|
||||
for packet_id, entity_info in discovery_info[CONF_DEVICES].items():
|
||||
event = get_rfx_object(packet_id)
|
||||
if event is None:
|
||||
if (event := get_rfx_object(packet_id)) is None:
|
||||
_LOGGER.error("Invalid device: %s", packet_id)
|
||||
continue
|
||||
if not supported(event):
|
||||
|
|
|
@ -49,8 +49,7 @@ async def async_setup_entry(
|
|||
|
||||
entities = []
|
||||
for packet_id, entity_info in discovery_info[CONF_DEVICES].items():
|
||||
event = get_rfx_object(packet_id)
|
||||
if event is None:
|
||||
if (event := get_rfx_object(packet_id)) is None:
|
||||
_LOGGER.error("Invalid device: %s", packet_id)
|
||||
continue
|
||||
if not supported(event):
|
||||
|
|
|
@ -50,8 +50,7 @@ async def async_setup_entry(
|
|||
# Add switch from config file
|
||||
entities = []
|
||||
for packet_id, entity_info in discovery_info[CONF_DEVICES].items():
|
||||
event = get_rfx_object(packet_id)
|
||||
if event is None:
|
||||
if (event := get_rfx_object(packet_id)) is None:
|
||||
_LOGGER.error("Invalid device: %s", packet_id)
|
||||
continue
|
||||
if not supported(event):
|
||||
|
|
|
@ -237,8 +237,7 @@ async def async_setup_entry(
|
|||
|
||||
entities = []
|
||||
for packet_id, entity_info in discovery_info[CONF_DEVICES].items():
|
||||
event = get_rfx_object(packet_id)
|
||||
if event is None:
|
||||
if (event := get_rfx_object(packet_id)) is None:
|
||||
_LOGGER.error("Invalid device: %s", packet_id)
|
||||
continue
|
||||
if not supported(event):
|
||||
|
|
|
@ -49,8 +49,7 @@ async def async_setup_entry(
|
|||
# Add switch from config file
|
||||
entities = []
|
||||
for packet_id, entity_info in discovery_info[CONF_DEVICES].items():
|
||||
event = get_rfx_object(packet_id)
|
||||
if event is None:
|
||||
if (event := get_rfx_object(packet_id)) is None:
|
||||
_LOGGER.error("Invalid device: %s", packet_id)
|
||||
continue
|
||||
if not supported(event):
|
||||
|
|
|
@ -134,9 +134,7 @@ class WorxLandroidSensor(SensorEntity):
|
|||
|
||||
def get_state(self, obj):
|
||||
"""Get the state of the mower."""
|
||||
state = self.get_error(obj)
|
||||
|
||||
if state is None:
|
||||
if (state := self.get_error(obj)) is None:
|
||||
if obj["batteryChargerState"] == "charging":
|
||||
return obj["batteryChargerState"]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue