diff --git a/homeassistant/components/here_travel_time/sensor.py b/homeassistant/components/here_travel_time/sensor.py index e4fbc0b2a89..4b8f765d08a 100644 --- a/homeassistant/components/here_travel_time/sensor.py +++ b/homeassistant/components/here_travel_time/sensor.py @@ -258,9 +258,8 @@ class HERETravelTimeSensor(SensorEntity): @property def state(self) -> str | None: """Return the state of the sensor.""" - if self._here_data.traffic_mode: - if self._here_data.traffic_time is not None: - return str(round(self._here_data.traffic_time / 60)) + if self._here_data.traffic_mode and self._here_data.traffic_time is not None: + return str(round(self._here_data.traffic_time / 60)) if self._here_data.base_time is not None: return str(round(self._here_data.base_time / 60)) diff --git a/homeassistant/components/hitron_coda/device_tracker.py b/homeassistant/components/hitron_coda/device_tracker.py index 4634c6e378a..cbd6b7eeff8 100644 --- a/homeassistant/components/hitron_coda/device_tracker.py +++ b/homeassistant/components/hitron_coda/device_tracker.py @@ -74,10 +74,9 @@ class HitronCODADeviceScanner(DeviceScanner): def get_device_name(self, device): """Return the name of the device with the given MAC address.""" - name = next( + return next( (result.name for result in self.last_results if result.mac == device), None ) - return name def _login(self): """Log in to the router. This is required for subsequent api calls.""" @@ -103,10 +102,9 @@ class HitronCODADeviceScanner(DeviceScanner): """Get ARP from router.""" _LOGGER.info("Fetching") - if self._userid is None: - if not self._login(): - _LOGGER.error("Could not obtain a user ID from the router") - return False + if self._userid is None and not self._login(): + _LOGGER.error("Could not obtain a user ID from the router") + return False last_results = [] # doing a request diff --git a/homeassistant/components/homekit_controller/device_trigger.py b/homeassistant/components/homekit_controller/device_trigger.py index 31bfcc18d52..59cc32c0b1b 100644 --- a/homeassistant/components/homekit_controller/device_trigger.py +++ b/homeassistant/components/homekit_controller/device_trigger.py @@ -99,9 +99,11 @@ def enumerate_stateless_switch(service): # A stateless switch that has a SERVICE_LABEL_INDEX is part of a group # And is handled separately - if service.has(CharacteristicsTypes.SERVICE_LABEL_INDEX): - if len(service.linked) > 0: - return [] + if ( + service.has(CharacteristicsTypes.SERVICE_LABEL_INDEX) + and len(service.linked) > 0 + ): + return [] char = service[CharacteristicsTypes.INPUT_EVENT] @@ -109,17 +111,15 @@ def enumerate_stateless_switch(service): # manufacturer might not - clamp options to what they say. all_values = clamp_enum_to_char(InputEventValues, char) - results = [] - for event_type in all_values: - results.append( - { - "characteristic": char.iid, - "value": event_type, - "type": "button1", - "subtype": HK_TO_HA_INPUT_EVENT_VALUES[event_type], - } - ) - return results + return [ + { + "characteristic": char.iid, + "value": event_type, + "type": "button1", + "subtype": HK_TO_HA_INPUT_EVENT_VALUES[event_type], + } + for event_type in all_values + ] def enumerate_stateless_switch_group(service): @@ -234,20 +234,16 @@ async def async_get_triggers(hass: HomeAssistant, device_id: str) -> list[dict]: device = hass.data[TRIGGERS][device_id] - triggers = [] - - for trigger, subtype in device.async_get_triggers(): - triggers.append( - { - CONF_PLATFORM: "device", - CONF_DEVICE_ID: device_id, - CONF_DOMAIN: DOMAIN, - CONF_TYPE: trigger, - CONF_SUBTYPE: subtype, - } - ) - - return triggers + return [ + { + CONF_PLATFORM: "device", + CONF_DEVICE_ID: device_id, + CONF_DOMAIN: DOMAIN, + CONF_TYPE: trigger, + CONF_SUBTYPE: subtype, + } + for trigger, subtype in device.async_get_triggers() + ] async def async_attach_trigger( diff --git a/homeassistant/components/homekit_controller/media_player.py b/homeassistant/components/homekit_controller/media_player.py index 6dfa8720ee5..71bde5f0af9 100644 --- a/homeassistant/components/homekit_controller/media_player.py +++ b/homeassistant/components/homekit_controller/media_player.py @@ -93,9 +93,11 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity): if TargetMediaStateValues.STOP in self.supported_media_states: features |= SUPPORT_STOP - if self.service.has(CharacteristicsTypes.REMOTE_KEY): - if RemoteKeyValues.PLAY_PAUSE in self.supported_remote_keys: - features |= SUPPORT_PAUSE | SUPPORT_PLAY + if ( + self.service.has(CharacteristicsTypes.REMOTE_KEY) + and RemoteKeyValues.PLAY_PAUSE in self.supported_remote_keys + ): + features |= SUPPORT_PAUSE | SUPPORT_PLAY return features diff --git a/homeassistant/components/hue/light.py b/homeassistant/components/hue/light.py index 8adde810fbe..3d193734005 100644 --- a/homeassistant/components/hue/light.py +++ b/homeassistant/components/hue/light.py @@ -229,7 +229,7 @@ async def async_safe_fetch(bridge, fetch_method): except aiohue.Unauthorized as err: await bridge.handle_unauthorized_error() raise UpdateFailed("Unauthorized") from err - except (aiohue.AiohueException,) as err: + except aiohue.AiohueException as err: raise UpdateFailed(f"Hue error: {err}") from err @@ -297,12 +297,11 @@ class HueLight(CoordinatorEntity, LightEntity): "bulb in the Philips Hue App." ) _LOGGER.warning(err, self.name) - if self.gamut: - if not color.check_valid_gamut(self.gamut): - err = "Color gamut of %s: %s, not valid, setting gamut to None." - _LOGGER.warning(err, self.name, str(self.gamut)) - self.gamut_typ = GAMUT_TYPE_UNAVAILABLE - self.gamut = None + if self.gamut and not color.check_valid_gamut(self.gamut): + err = "Color gamut of %s: %s, not valid, setting gamut to None." + _LOGGER.warning(err, self.name, str(self.gamut)) + self.gamut_typ = GAMUT_TYPE_UNAVAILABLE + self.gamut = None @property def unique_id(self): diff --git a/homeassistant/components/hyperion/light.py b/homeassistant/components/hyperion/light.py index 36c3d836bf3..248a45ec753 100644 --- a/homeassistant/components/hyperion/light.py +++ b/homeassistant/components/hyperion/light.py @@ -241,8 +241,9 @@ class HyperionBaseLight(LightEntity): if ATTR_BRIGHTNESS in kwargs: brightness = kwargs[ATTR_BRIGHTNESS] for item in self._client.adjustment or []: - if const.KEY_ID in item: - if not await self._client.async_send_set_adjustment( + if ( + const.KEY_ID in item + and not await self._client.async_send_set_adjustment( **{ const.KEY_ADJUSTMENT: { const.KEY_BRIGHTNESS: int( @@ -251,8 +252,9 @@ class HyperionBaseLight(LightEntity): const.KEY_ID: item[const.KEY_ID], } } - ): - return + ) + ): + return # == Set an external source if ( diff --git a/homeassistant/components/image_processing/__init__.py b/homeassistant/components/image_processing/__init__.py index 1320629aeb4..58a6582e33c 100644 --- a/homeassistant/components/image_processing/__init__.py +++ b/homeassistant/components/image_processing/__init__.py @@ -208,9 +208,12 @@ class ImageProcessingFaceEntity(ImageProcessingEntity): """ # Send events for face in faces: - if ATTR_CONFIDENCE in face and self.confidence: - if face[ATTR_CONFIDENCE] < self.confidence: - continue + if ( + ATTR_CONFIDENCE in face + and self.confidence + and face[ATTR_CONFIDENCE] < self.confidence + ): + continue face.update({ATTR_ENTITY_ID: self.entity_id}) self.hass.async_add_job(self.hass.bus.async_fire, EVENT_DETECT_FACE, face) diff --git a/homeassistant/components/imap_email_content/sensor.py b/homeassistant/components/imap_email_content/sensor.py index 22c395a7c8f..cdd47d68d76 100644 --- a/homeassistant/components/imap_email_content/sensor.py +++ b/homeassistant/components/imap_email_content/sensor.py @@ -220,9 +220,11 @@ class EmailContentSensor(SensorEntity): elif part.get_content_type() == "text/html": if message_html is None: message_html = part.get_payload() - elif part.get_content_type().startswith("text"): - if message_untyped_text is None: - message_untyped_text = part.get_payload() + elif ( + part.get_content_type().startswith("text") + and message_untyped_text is None + ): + message_untyped_text = part.get_payload() if message_text is not None: return message_text diff --git a/homeassistant/components/ios/notify.py b/homeassistant/components/ios/notify.py index f9c682bf527..853fb0d479a 100644 --- a/homeassistant/components/ios/notify.py +++ b/homeassistant/components/ios/notify.py @@ -69,10 +69,12 @@ class iOSNotificationService(BaseNotificationService): """Send a message to the Lambda APNS gateway.""" data = {ATTR_MESSAGE: message} - if kwargs.get(ATTR_TITLE) is not None: - # Remove default title from notifications. - if kwargs.get(ATTR_TITLE) != ATTR_TITLE_DEFAULT: - data[ATTR_TITLE] = kwargs.get(ATTR_TITLE) + # Remove default title from notifications. + if ( + kwargs.get(ATTR_TITLE) is not None + and kwargs.get(ATTR_TITLE) != ATTR_TITLE_DEFAULT + ): + data[ATTR_TITLE] = kwargs.get(ATTR_TITLE) targets = kwargs.get(ATTR_TARGET) diff --git a/homeassistant/components/isy994/binary_sensor.py b/homeassistant/components/isy994/binary_sensor.py index 3b0bb9fd144..57b134e0900 100644 --- a/homeassistant/components/isy994/binary_sensor.py +++ b/homeassistant/components/isy994/binary_sensor.py @@ -281,15 +281,17 @@ class ISYInsteonBinarySensorEntity(ISYBinarySensorEntity): """ self._negative_node = child - if self._negative_node.status != ISY_VALUE_UNKNOWN: - # If the negative node has a value, it means the negative node is - # in use for this device. Next we need to check to see if the - # negative and positive nodes disagree on the state (both ON or - # both OFF). - if self._negative_node.status == self._node.status: - # The states disagree, therefore we cannot determine the state - # of the sensor until we receive our first ON event. - self._computed_state = None + # If the negative node has a value, it means the negative node is + # in use for this device. Next we need to check to see if the + # negative and positive nodes disagree on the state (both ON or + # both OFF). + if ( + self._negative_node.status != ISY_VALUE_UNKNOWN + and self._negative_node.status == self._node.status + ): + # The states disagree, therefore we cannot determine the state + # of the sensor until we receive our first ON event. + self._computed_state = None def _negative_node_control_handler(self, event: object) -> None: """Handle an "On" control event from the "negative" node.""" diff --git a/homeassistant/components/joaoapps_join/__init__.py b/homeassistant/components/joaoapps_join/__init__.py index a65a7ffd7fe..1331afbfe97 100644 --- a/homeassistant/components/joaoapps_join/__init__.py +++ b/homeassistant/components/joaoapps_join/__init__.py @@ -121,10 +121,9 @@ def setup(hass, config): device_names = device.get(CONF_DEVICE_NAMES) name = device.get(CONF_NAME) name = f"{name.lower().replace(' ', '_')}_" if name else "" - if api_key: - if not get_devices(api_key): - _LOGGER.error("Error connecting to Join, check API key") - return False + if api_key and not get_devices(api_key): + _LOGGER.error("Error connecting to Join, check API key") + return False if device_id is None and device_ids is None and device_names is None: _LOGGER.error( "No device was provided. Please specify device_id" diff --git a/homeassistant/components/joaoapps_join/notify.py b/homeassistant/components/joaoapps_join/notify.py index 7ba089e5dab..06cad45bdde 100644 --- a/homeassistant/components/joaoapps_join/notify.py +++ b/homeassistant/components/joaoapps_join/notify.py @@ -35,10 +35,9 @@ def get_service(hass, config, discovery_info=None): device_id = config.get(CONF_DEVICE_ID) device_ids = config.get(CONF_DEVICE_IDS) device_names = config.get(CONF_DEVICE_NAMES) - if api_key: - if not get_devices(api_key): - _LOGGER.error("Error connecting to Join. Check the API key") - return False + if api_key and not get_devices(api_key): + _LOGGER.error("Error connecting to Join. Check the API key") + return False if device_id is None and device_ids is None and device_names is None: _LOGGER.error( "No device was provided. Please specify device_id"