diff --git a/homeassistant/components/arcam_fmj/media_player.py b/homeassistant/components/arcam_fmj/media_player.py index b63279d9c26..553524dbcdf 100644 --- a/homeassistant/components/arcam_fmj/media_player.py +++ b/homeassistant/components/arcam_fmj/media_player.py @@ -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: diff --git a/homeassistant/components/cast/home_assistant_cast.py b/homeassistant/components/cast/home_assistant_cast.py index fb2d790d03d..6127e466099 100644 --- a/homeassistant/components/cast/home_assistant_cast.py +++ b/homeassistant/components/cast/home_assistant_cast.py @@ -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) diff --git a/homeassistant/components/ihc/__init__.py b/homeassistant/components/ihc/__init__.py index c0fe8944c66..3a75a841fde 100644 --- a/homeassistant/components/ihc/__init__.py +++ b/homeassistant/components/ihc/__init__.py @@ -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) diff --git a/homeassistant/components/insteon/api/device.py b/homeassistant/components/insteon/api/device.py index 6815ec43031..1071451876b 100644 --- a/homeassistant/components/insteon/api/device.py +++ b/homeassistant/components/insteon/api/device.py @@ -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) diff --git a/homeassistant/components/insteon/insteon_entity.py b/homeassistant/components/insteon/insteon_entity.py index aa2d4367225..719b58a3d9f 100644 --- a/homeassistant/components/insteon/insteon_entity.py +++ b/homeassistant/components/insteon/insteon_entity.py @@ -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}" diff --git a/homeassistant/components/kiwi/lock.py b/homeassistant/components/kiwi/lock.py index 8a0eeed83f0..650d6d34de8 100644 --- a/homeassistant/components/kiwi/lock.py +++ b/homeassistant/components/kiwi/lock.py @@ -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 diff --git a/homeassistant/components/mold_indicator/sensor.py b/homeassistant/components/mold_indicator/sensor.py index c57903ce5b7..c178d5e2360 100644 --- a/homeassistant/components/mold_indicator/sensor.py +++ b/homeassistant/components/mold_indicator/sensor.py @@ -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, diff --git a/homeassistant/components/rfxtrx/__init__.py b/homeassistant/components/rfxtrx/__init__.py index 9a5b7ecf57a..88bddc6afbe 100644 --- a/homeassistant/components/rfxtrx/__init__.py +++ b/homeassistant/components/rfxtrx/__init__.py @@ -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) diff --git a/homeassistant/components/rfxtrx/binary_sensor.py b/homeassistant/components/rfxtrx/binary_sensor.py index 914303f1468..cc11e94c526 100644 --- a/homeassistant/components/rfxtrx/binary_sensor.py +++ b/homeassistant/components/rfxtrx/binary_sensor.py @@ -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): diff --git a/homeassistant/components/rfxtrx/cover.py b/homeassistant/components/rfxtrx/cover.py index 26a938141a2..0244e3aa8a0 100644 --- a/homeassistant/components/rfxtrx/cover.py +++ b/homeassistant/components/rfxtrx/cover.py @@ -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): diff --git a/homeassistant/components/rfxtrx/light.py b/homeassistant/components/rfxtrx/light.py index ea197b5ebc4..c67213ed6f8 100644 --- a/homeassistant/components/rfxtrx/light.py +++ b/homeassistant/components/rfxtrx/light.py @@ -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): diff --git a/homeassistant/components/rfxtrx/sensor.py b/homeassistant/components/rfxtrx/sensor.py index afd1d6a12ce..8ce9843076d 100644 --- a/homeassistant/components/rfxtrx/sensor.py +++ b/homeassistant/components/rfxtrx/sensor.py @@ -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): diff --git a/homeassistant/components/rfxtrx/switch.py b/homeassistant/components/rfxtrx/switch.py index 2a09d027345..21e9e06b802 100644 --- a/homeassistant/components/rfxtrx/switch.py +++ b/homeassistant/components/rfxtrx/switch.py @@ -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): diff --git a/homeassistant/components/worxlandroid/sensor.py b/homeassistant/components/worxlandroid/sensor.py index b34481d0990..464892e9126 100644 --- a/homeassistant/components/worxlandroid/sensor.py +++ b/homeassistant/components/worxlandroid/sensor.py @@ -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"]