diff --git a/homeassistant/components/alexa/entities.py b/homeassistant/components/alexa/entities.py
index 8c139d66369de8109a4dbd56e40123684e24ba57..6a0b1830b7ec44a24d1fd129ef3c6a8b43227276 100644
--- a/homeassistant/components/alexa/entities.py
+++ b/homeassistant/components/alexa/entities.py
@@ -474,25 +474,30 @@ class ClimateCapabilities(AlexaEntity):
         # If we support two modes, one being off, we allow turning on too.
         supported_features = self.entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
         if (
-            self.entity.domain == climate.DOMAIN
-            and climate.HVACMode.OFF
-            in (self.entity.attributes.get(climate.ATTR_HVAC_MODES) or [])
-            or self.entity.domain == climate.DOMAIN
-            and (
-                supported_features
-                & (
-                    climate.ClimateEntityFeature.TURN_ON
-                    | climate.ClimateEntityFeature.TURN_OFF
+            (
+                self.entity.domain == climate.DOMAIN
+                and climate.HVACMode.OFF
+                in (self.entity.attributes.get(climate.ATTR_HVAC_MODES) or [])
+            )
+            or (
+                self.entity.domain == climate.DOMAIN
+                and (
+                    supported_features
+                    & (
+                        climate.ClimateEntityFeature.TURN_ON
+                        | climate.ClimateEntityFeature.TURN_OFF
+                    )
                 )
             )
-            or self.entity.domain == water_heater.DOMAIN
-            and (supported_features & water_heater.WaterHeaterEntityFeature.ON_OFF)
+            or (
+                self.entity.domain == water_heater.DOMAIN
+                and (supported_features & water_heater.WaterHeaterEntityFeature.ON_OFF)
+            )
         ):
             yield AlexaPowerController(self.entity)
 
-        if (
-            self.entity.domain == climate.DOMAIN
-            or self.entity.domain == water_heater.DOMAIN
+        if self.entity.domain == climate.DOMAIN or (
+            self.entity.domain == water_heater.DOMAIN
             and (
                 supported_features
                 & water_heater.WaterHeaterEntityFeature.OPERATION_MODE
diff --git a/homeassistant/components/alexa/state_report.py b/homeassistant/components/alexa/state_report.py
index 3eb761dacded0adb01d801b1155fd0d290b57ed7..03b6a22007c6aa9765c68fa21a617f97d11fdbe3 100644
--- a/homeassistant/components/alexa/state_report.py
+++ b/homeassistant/components/alexa/state_report.py
@@ -317,9 +317,8 @@ async def async_enable_proactive_mode(
 
         if should_doorbell:
             old_state = data["old_state"]
-            if (
-                new_state.domain == event.DOMAIN
-                or new_state.state == STATE_ON
+            if new_state.domain == event.DOMAIN or (
+                new_state.state == STATE_ON
                 and (old_state is None or old_state.state != STATE_ON)
             ):
                 await async_send_doorbell_event_message(
diff --git a/homeassistant/components/bond/entity.py b/homeassistant/components/bond/entity.py
index 81f96b1772c76808dac893c7f0c2f6637553a582..2ae1df5fd684ce0d9eec581c56257fed0781205a 100644
--- a/homeassistant/components/bond/entity.py
+++ b/homeassistant/components/bond/entity.py
@@ -115,11 +115,8 @@ class BondEntity(Entity):
     def _async_update_if_bpup_not_alive(self, now: datetime) -> None:
         """Fetch via the API if BPUP is not alive."""
         self._async_schedule_bpup_alive_or_poll()
-        if (
-            self.hass.is_stopping
-            or self._bpup_subs.alive
-            and self._initialized
-            and self.available
+        if self.hass.is_stopping or (
+            self._bpup_subs.alive and self._initialized and self.available
         ):
             return
         if self._update_lock.locked():
diff --git a/homeassistant/components/bthome/logbook.py b/homeassistant/components/bthome/logbook.py
index 32e90118deaea2e84caa6f4ae2aa2a7a79f2812b..1c41d5553da0fef0d4a5c29ed132f6de56c409bc 100644
--- a/homeassistant/components/bthome/logbook.py
+++ b/homeassistant/components/bthome/logbook.py
@@ -26,7 +26,7 @@ def async_describe_events(
         """Describe bthome logbook event."""
         data = event.data
         device = dev_reg.async_get(data["device_id"])
-        name = device and device.name or f"BTHome {data['address']}"
+        name = (device and device.name) or f"BTHome {data['address']}"
         if properties := data["event_properties"]:
             message = f"{data['event_class']} {data['event_type']}: {properties}"
         else:
diff --git a/homeassistant/components/caldav/coordinator.py b/homeassistant/components/caldav/coordinator.py
index eb09e3f5452226be952da8f119334408b4d21e5a..c6bbd15bdff708ba225b7ad58d005fc180699450 100644
--- a/homeassistant/components/caldav/coordinator.py
+++ b/homeassistant/components/caldav/coordinator.py
@@ -186,12 +186,12 @@ class CalDavUpdateCoordinator(DataUpdateCoordinator[CalendarEvent | None]):
 
         pattern = re.compile(search)
         return (
-            hasattr(vevent, "summary")
-            and pattern.match(vevent.summary.value)
-            or hasattr(vevent, "location")
-            and pattern.match(vevent.location.value)
-            or hasattr(vevent, "description")
-            and pattern.match(vevent.description.value)
+            (hasattr(vevent, "summary") and pattern.match(vevent.summary.value))
+            or (hasattr(vevent, "location") and pattern.match(vevent.location.value))
+            or (
+                hasattr(vevent, "description")
+                and pattern.match(vevent.description.value)
+            )
         )
 
     @staticmethod
diff --git a/homeassistant/components/coinbase/__init__.py b/homeassistant/components/coinbase/__init__.py
index f5fd8fa1dc3ab8f2b85ae748af0687f1f85ba2d7..6aa33a7c14dc6970a5142235589dd2c70a5c38ad 100644
--- a/homeassistant/components/coinbase/__init__.py
+++ b/homeassistant/components/coinbase/__init__.py
@@ -101,7 +101,8 @@ async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> Non
         if (
             "xe" in entity.unique_id
             and currency not in config_entry.options.get(CONF_EXCHANGE_RATES, [])
-            or "wallet" in entity.unique_id
+        ) or (
+            "wallet" in entity.unique_id
             and currency not in config_entry.options.get(CONF_CURRENCIES, [])
         ):
             registry.async_remove(entity.entity_id)
diff --git a/homeassistant/components/config/entity_registry.py b/homeassistant/components/config/entity_registry.py
index aed049439753b3879fd86bcd3e2bc7f6d117bef0..b987f249a336326a8c3ed534c658cb76364ac177 100644
--- a/homeassistant/components/config/entity_registry.py
+++ b/homeassistant/components/config/entity_registry.py
@@ -279,9 +279,8 @@ def websocket_update_entity(
     result: dict[str, Any] = {"entity_entry": entity_entry.extended_dict}
     if "disabled_by" in changes and changes["disabled_by"] is None:
         # Enabling an entity requires a config entry reload, or HA restart
-        if (
-            not (config_entry_id := entity_entry.config_entry_id)
-            or (config_entry := hass.config_entries.async_get_entry(config_entry_id))
+        if not (config_entry_id := entity_entry.config_entry_id) or (
+            (config_entry := hass.config_entries.async_get_entry(config_entry_id))
             and not config_entry.supports_unload
         ):
             result["require_restart"] = True
diff --git a/homeassistant/components/energy/sensor.py b/homeassistant/components/energy/sensor.py
index 147d8f3e26a36384c1229784526860eb65358d6a..199d18d6b0732250484e73f7484e1be8937b9c62 100644
--- a/homeassistant/components/energy/sensor.py
+++ b/homeassistant/components/energy/sensor.py
@@ -362,12 +362,11 @@ class EnergyCostSensor(SensorEntity):
             return
 
         if (
-            (
-                state_class != SensorStateClass.TOTAL_INCREASING
-                and energy_state.attributes.get(ATTR_LAST_RESET)
-                != self._last_energy_sensor_state.attributes.get(ATTR_LAST_RESET)
-            )
-            or state_class == SensorStateClass.TOTAL_INCREASING
+            state_class != SensorStateClass.TOTAL_INCREASING
+            and energy_state.attributes.get(ATTR_LAST_RESET)
+            != self._last_energy_sensor_state.attributes.get(ATTR_LAST_RESET)
+        ) or (
+            state_class == SensorStateClass.TOTAL_INCREASING
             and reset_detected(
                 self.hass,
                 cast(str, self._config[self._adapter.stat_energy_key]),
diff --git a/homeassistant/components/geo_location/trigger.py b/homeassistant/components/geo_location/trigger.py
index 96244e08d1b8380d73d9938df86e45ea01b3cd04..5f0d6e92ee188ea439acdfd2fed31f16a460beeb 100644
--- a/homeassistant/components/geo_location/trigger.py
+++ b/homeassistant/components/geo_location/trigger.py
@@ -83,13 +83,8 @@ async def async_attach_trigger(
         )
         to_match = condition.zone(hass, zone_state, to_state) if to_state else False
 
-        if (
-            trigger_event == EVENT_ENTER
-            and not from_match
-            and to_match
-            or trigger_event == EVENT_LEAVE
-            and from_match
-            and not to_match
+        if (trigger_event == EVENT_ENTER and not from_match and to_match) or (
+            trigger_event == EVENT_LEAVE and from_match and not to_match
         ):
             hass.async_run_hass_job(
                 job,
diff --git a/homeassistant/components/glances/sensor.py b/homeassistant/components/glances/sensor.py
index 59eba69d60a6e6510b6335bed1821f167d78428d..0741926296ee8260f393e9eccffc2ec679b3e861 100644
--- a/homeassistant/components/glances/sensor.py
+++ b/homeassistant/components/glances/sensor.py
@@ -375,6 +375,8 @@ class GlancesSensor(CoordinatorEntity[GlancesDataUpdateCoordinator], SensorEntit
         self._data_valid = self._attr_native_value is not None and (
             not self._numeric_state_expected
             or isinstance(self._attr_native_value, (int, float))
-            or isinstance(self._attr_native_value, str)
-            and self._attr_native_value.isnumeric()
+            or (
+                isinstance(self._attr_native_value, str)
+                and self._attr_native_value.isnumeric()
+            )
         )
diff --git a/homeassistant/components/google_mail/api.py b/homeassistant/components/google_mail/api.py
index 485d640a04dbf3aaa5a8cb5303bf7d6b9776cfd7..3e455f645ad02e8d4343c6747e72d7563d6bab05 100644
--- a/homeassistant/components/google_mail/api.py
+++ b/homeassistant/components/google_mail/api.py
@@ -49,10 +49,8 @@ class AsyncConfigEntryAuth:
                         "OAuth session is not valid, reauth required"
                     ) from ex
                 raise ConfigEntryNotReady from ex
-            if (
-                isinstance(ex, RefreshError)
-                or hasattr(ex, "status")
-                and ex.status == 400
+            if isinstance(ex, RefreshError) or (
+                hasattr(ex, "status") and ex.status == 400
             ):
                 self.oauth_session.config_entry.async_start_reauth(
                     self.oauth_session.hass
diff --git a/homeassistant/components/group/entity.py b/homeassistant/components/group/entity.py
index 03a8be4bed596005ad34900e14942b11ce5c114e..40db70a2eb35a461056a0c6ac4aa281d50b0c108 100644
--- a/homeassistant/components/group/entity.py
+++ b/homeassistant/components/group/entity.py
@@ -440,10 +440,8 @@ class Group(Entity):
         if not self._on_off:
             return
 
-        if (
-            tr_state is None
-            or self._assumed_state
-            and not tr_state.attributes.get(ATTR_ASSUMED_STATE)
+        if tr_state is None or (
+            self._assumed_state and not tr_state.attributes.get(ATTR_ASSUMED_STATE)
         ):
             self._assumed_state = self.mode(self._assumed.values())
 
diff --git a/homeassistant/components/history/__init__.py b/homeassistant/components/history/__init__.py
index 7241e1fac9ad793a864320e4cd7af1d681be413d..ba4614bbc35ce23166c5c3f48a90d31c2e758eb3 100644
--- a/homeassistant/components/history/__init__.py
+++ b/homeassistant/components/history/__init__.py
@@ -111,10 +111,12 @@ class HistoryPeriodView(HomeAssistantView):
             # end_time. If it's false, we know there are no states in the
             # database up until end_time.
             (end_time and not has_states_before(hass, end_time))
-            or not include_start_time_state
-            and entity_ids
-            and not entities_may_have_state_changes_after(
-                hass, entity_ids, start_time, no_attributes
+            or (
+                not include_start_time_state
+                and entity_ids
+                and not entities_may_have_state_changes_after(
+                    hass, entity_ids, start_time, no_attributes
+                )
             )
         ):
             return self.json([])
diff --git a/homeassistant/components/history/websocket_api.py b/homeassistant/components/history/websocket_api.py
index 35f8ed5f1acdca22235b7b1683e516a2578cf700..e6c9145321333cfb687e9b99b675c46daa95d9fe 100644
--- a/homeassistant/components/history/websocket_api.py
+++ b/homeassistant/components/history/websocket_api.py
@@ -146,10 +146,12 @@ async def ws_get_history_during_period(
         # end_time. If it's false, we know there are no states in the
         # database up until end_time.
         (end_time and not has_states_before(hass, end_time))
-        or not include_start_time_state
-        and entity_ids
-        and not entities_may_have_state_changes_after(
-            hass, entity_ids, start_time, no_attributes
+        or (
+            not include_start_time_state
+            and entity_ids
+            and not entities_may_have_state_changes_after(
+                hass, entity_ids, start_time, no_attributes
+            )
         )
     ):
         connection.send_result(msg["id"], {})
diff --git a/homeassistant/components/homekit/type_covers.py b/homeassistant/components/homekit/type_covers.py
index 6752633f3d268efb106a600ddc7f5f7a4b49733b..651033682cf31e6b4d0957fc08df03f4b071144a 100644
--- a/homeassistant/components/homekit/type_covers.py
+++ b/homeassistant/components/homekit/type_covers.py
@@ -409,11 +409,8 @@ class WindowCoveringBasic(OpeningDeviceBase, HomeAccessory):
         """Move cover to value if call came from HomeKit."""
         _LOGGER.debug("%s: Set position to %d", self.entity_id, value)
 
-        if (
-            self._supports_stop
-            and value > 70
-            or not self._supports_stop
-            and value >= 50
+        if (self._supports_stop and value > 70) or (
+            not self._supports_stop and value >= 50
         ):
             service, position = (SERVICE_OPEN_COVER, 100)
         elif value < 30 or not self._supports_stop:
diff --git a/homeassistant/components/homekit/util.py b/homeassistant/components/homekit/util.py
index d339aa6aded34a1ce9c95180df76a43ef4aa8432..cd6596546177dae344e4c1ca22d12b3a09e71605 100644
--- a/homeassistant/components/homekit/util.py
+++ b/homeassistant/components/homekit/util.py
@@ -643,7 +643,8 @@ def state_needs_accessory_mode(state: State) -> bool:
         state.domain == MEDIA_PLAYER_DOMAIN
         and state.attributes.get(ATTR_DEVICE_CLASS)
         in (MediaPlayerDeviceClass.TV, MediaPlayerDeviceClass.RECEIVER)
-        or state.domain == REMOTE_DOMAIN
+    ) or (
+        state.domain == REMOTE_DOMAIN
         and state.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
         & RemoteEntityFeature.ACTIVITY
     )
diff --git a/homeassistant/components/lidarr/sensor.py b/homeassistant/components/lidarr/sensor.py
index b02361e65ca12cda4be411cb0f3ce7c6ff99c131..805fcce53adce2f62f37a0c541b7208981c8e919 100644
--- a/homeassistant/components/lidarr/sensor.py
+++ b/homeassistant/components/lidarr/sensor.py
@@ -160,10 +160,8 @@ class LidarrSensor(LidarrEntity[T], SensorEntity):
 
 def queue_str(item: LidarrQueueItem) -> str:
     """Return string description of queue item."""
-    if (
-        item.sizeleft > 0
-        and item.timeleft == "00:00:00"
-        or not hasattr(item, "trackedDownloadState")
+    if (item.sizeleft > 0 and item.timeleft == "00:00:00") or not hasattr(
+        item, "trackedDownloadState"
     ):
         return "stopped"
     return item.trackedDownloadState
diff --git a/homeassistant/components/melcloud/config_flow.py b/homeassistant/components/melcloud/config_flow.py
index b604ee5016e860941b0fe853351ee78e6eacee2c..d2c9d67f29a1b2ec0da281fbcfdd3db528469da5 100644
--- a/homeassistant/components/melcloud/config_flow.py
+++ b/homeassistant/components/melcloud/config_flow.py
@@ -126,9 +126,7 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
                     HTTPStatus.UNAUTHORIZED,
                     HTTPStatus.FORBIDDEN,
                 )
-                or isinstance(err, AttributeError)
-                and err.name == "get"
-            ):
+            ) or (isinstance(err, AttributeError) and err.name == "get"):
                 errors["base"] = "invalid_auth"
             else:
                 errors["base"] = "cannot_connect"
@@ -165,9 +163,7 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
                         HTTPStatus.UNAUTHORIZED,
                         HTTPStatus.FORBIDDEN,
                     )
-                    or isinstance(err, AttributeError)
-                    and err.name == "get"
-                ):
+                ) or (isinstance(err, AttributeError) and err.name == "get"):
                     errors["base"] = "invalid_auth"
                 else:
                     errors["base"] = "cannot_connect"
diff --git a/homeassistant/components/mqtt/config_flow.py b/homeassistant/components/mqtt/config_flow.py
index f07777742eef3f069923addea8bff4b9dde48622..a4d400dfea23d53a8bd11bea44c3c0d1b9cdd17a 100644
--- a/homeassistant/components/mqtt/config_flow.py
+++ b/homeassistant/components/mqtt/config_flow.py
@@ -768,11 +768,8 @@ async def async_get_broker_settings(
         validated_user_input.update(user_input)
         client_certificate_id: str | None = user_input.get(CONF_CLIENT_CERT)
         client_key_id: str | None = user_input.get(CONF_CLIENT_KEY)
-        if (
-            client_certificate_id
-            and not client_key_id
-            or not client_certificate_id
-            and client_key_id
+        if (client_certificate_id and not client_key_id) or (
+            not client_certificate_id and client_key_id
         ):
             errors["base"] = "invalid_inclusion"
             return False
@@ -782,14 +779,20 @@ async def async_get_broker_settings(
 
         # Return to form for file upload CA cert or client cert and key
         if (
-            not client_certificate
-            and user_input.get(SET_CLIENT_CERT)
-            and not client_certificate_id
-            or not certificate
-            and user_input.get(SET_CA_CERT, "off") == "custom"
-            and not certificate_id
-            or user_input.get(CONF_TRANSPORT) == TRANSPORT_WEBSOCKETS
-            and CONF_WS_PATH not in user_input
+            (
+                not client_certificate
+                and user_input.get(SET_CLIENT_CERT)
+                and not client_certificate_id
+            )
+            or (
+                not certificate
+                and user_input.get(SET_CA_CERT, "off") == "custom"
+                and not certificate_id
+            )
+            or (
+                user_input.get(CONF_TRANSPORT) == TRANSPORT_WEBSOCKETS
+                and CONF_WS_PATH not in user_input
+            )
         ):
             return False
 
diff --git a/homeassistant/components/myuplink/helpers.py b/homeassistant/components/myuplink/helpers.py
index bd875d8a8720351bfeec8bee0b66de464ded4fe7..5751d574e0452aa672281b9d5455b0e7d8d8306e 100644
--- a/homeassistant/components/myuplink/helpers.py
+++ b/homeassistant/components/myuplink/helpers.py
@@ -26,10 +26,8 @@ def find_matching_platform(
     if len(device_point.enum_values) > 0 and device_point.writable:
         return Platform.SELECT
 
-    if (
-        description
-        and description.native_unit_of_measurement == "DM"
-        or (device_point.raw["maxValue"] and device_point.raw["minValue"])
+    if (description and description.native_unit_of_measurement == "DM") or (
+        device_point.raw["maxValue"] and device_point.raw["minValue"]
     ):
         if device_point.writable:
             return Platform.NUMBER
diff --git a/homeassistant/components/netatmo/__init__.py b/homeassistant/components/netatmo/__init__.py
index 6f14c9c76bb21c1375c29181de4becb539e6209d..9c92724c5436b8c10ed1e523a45886da35afa04e 100644
--- a/homeassistant/components/netatmo/__init__.py
+++ b/homeassistant/components/netatmo/__init__.py
@@ -257,7 +257,6 @@ async def async_remove_config_entry_device(
     return not any(
         identifier
         for identifier in device_entry.identifiers
-        if identifier[0] == DOMAIN
-        and identifier[1] in modules
+        if (identifier[0] == DOMAIN and identifier[1] in modules)
         or identifier[1] in rooms
     )
diff --git a/homeassistant/components/octoprint/coordinator.py b/homeassistant/components/octoprint/coordinator.py
index ff00b6c34208f4a6c7e07d10a45e04d4b4aa6278..c6d7373a002a7c2d40c6234ebea4318598f36e1b 100644
--- a/homeassistant/components/octoprint/coordinator.py
+++ b/homeassistant/components/octoprint/coordinator.py
@@ -80,7 +80,7 @@ class OctoprintDataUpdateCoordinator(DataUpdateCoordinator):
         """Device info."""
         unique_id = cast(str, self.config_entry.unique_id)
         configuration_url = URL.build(
-            scheme=self.config_entry.data[CONF_SSL] and "https" or "http",
+            scheme=(self.config_entry.data[CONF_SSL] and "https") or "http",
             host=self.config_entry.data[CONF_HOST],
             port=self.config_entry.data[CONF_PORT],
             path=self.config_entry.data[CONF_PATH],
diff --git a/homeassistant/components/overkiz/sensor.py b/homeassistant/components/overkiz/sensor.py
index 84d25b01d245ea59d2a5f037a29d5d04777cb6ea..81a9ab41d2d98215b674e1c021f73bf2d8f8a640 100644
--- a/homeassistant/components/overkiz/sensor.py
+++ b/homeassistant/components/overkiz/sensor.py
@@ -534,8 +534,7 @@ class OverkizStateSensor(OverkizDescriptiveEntity, SensorEntity):
             # This is probably incorrect and should be fixed in a follow up PR.
             # To ensure measurement sensors do not get an `unknown` state on
             # a falsy value (e.g. 0 or 0.0) we also check the state_class.
-            or self.state_class != SensorStateClass.MEASUREMENT
-            and not state.value
+            or (self.state_class != SensorStateClass.MEASUREMENT and not state.value)
         ):
             return None
 
diff --git a/homeassistant/components/overkiz/water_heater/domestic_hot_water_production.py b/homeassistant/components/overkiz/water_heater/domestic_hot_water_production.py
index abd3f40adc2f32c01dc92678991a38d2eecfec8b..f5a9e3d4a7e776b39ea9f5d741a54985514c9ed8 100644
--- a/homeassistant/components/overkiz/water_heater/domestic_hot_water_production.py
+++ b/homeassistant/components/overkiz/water_heater/domestic_hot_water_production.py
@@ -64,10 +64,8 @@ class DomesticHotWaterProduction(OverkizEntity, WaterHeaterEntity):
         for param, mode in OVERKIZ_TO_OPERATION_MODE.items():
             # Filter only for mode allowed by this device
             # or allow all if no mode definition found
-            if (
-                not state_mode_definition
-                or state_mode_definition.values
-                and param in state_mode_definition.values
+            if not state_mode_definition or (
+                state_mode_definition.values and param in state_mode_definition.values
             ):
                 self.operation_mode_to_overkiz[mode] = param
                 self._attr_operation_list.append(param)
diff --git a/homeassistant/components/python_script/__init__.py b/homeassistant/components/python_script/__init__.py
index f9e6a994406354344e487be557081e0d7128a8c9..dbd1a5dce4b37f82d5ade95e554467cf32f28cf2 100644
--- a/homeassistant/components/python_script/__init__.py
+++ b/homeassistant/components/python_script/__init__.py
@@ -239,20 +239,13 @@ def execute(
         if name.startswith("async_"):
             raise ScriptError("Not allowed to access async methods")
         if (
-            obj is hass
-            and name not in ALLOWED_HASS
-            or obj is hass.bus
-            and name not in ALLOWED_EVENTBUS
-            or obj is hass.states
-            and name not in ALLOWED_STATEMACHINE
-            or obj is hass.services
-            and name not in ALLOWED_SERVICEREGISTRY
-            or obj is dt_util
-            and name not in ALLOWED_DT_UTIL
-            or obj is datetime
-            and name not in ALLOWED_DATETIME
-            or isinstance(obj, TimeWrapper)
-            and name not in ALLOWED_TIME
+            (obj is hass and name not in ALLOWED_HASS)
+            or (obj is hass.bus and name not in ALLOWED_EVENTBUS)
+            or (obj is hass.states and name not in ALLOWED_STATEMACHINE)
+            or (obj is hass.services and name not in ALLOWED_SERVICEREGISTRY)
+            or (obj is dt_util and name not in ALLOWED_DT_UTIL)
+            or (obj is datetime and name not in ALLOWED_DATETIME)
+            or (isinstance(obj, TimeWrapper) and name not in ALLOWED_TIME)
         ):
             raise ScriptError(f"Not allowed to access {obj.__class__.__name__}.{name}")
 
diff --git a/homeassistant/components/rfxtrx/switch.py b/homeassistant/components/rfxtrx/switch.py
index 1464cccb5c4cd6bd8c3c7cc299eab9a6cc0049b3..cd17e71f4f0d797b410cd73cb1a648c640c62318 100644
--- a/homeassistant/components/rfxtrx/switch.py
+++ b/homeassistant/components/rfxtrx/switch.py
@@ -35,8 +35,7 @@ def supported(event: rfxtrxmod.RFXtrxEvent) -> bool:
         isinstance(event.device, rfxtrxmod.LightingDevice)
         and not event.device.known_to_be_dimmable
         and not event.device.known_to_be_rollershutter
-        or isinstance(event.device, rfxtrxmod.RfyDevice)
-    )
+    ) or isinstance(event.device, rfxtrxmod.RfyDevice)
 
 
 async def async_setup_entry(
diff --git a/homeassistant/components/rmvtransport/sensor.py b/homeassistant/components/rmvtransport/sensor.py
index 8fd437e7e1db2b0643a651f20b79c5b6e4644ef3..ac6c66bb6d271cd5152a73c9dce245514f628176 100644
--- a/homeassistant/components/rmvtransport/sensor.py
+++ b/homeassistant/components/rmvtransport/sensor.py
@@ -271,11 +271,9 @@ class RMVDepartureData:
                 if not dest_found:
                     continue
 
-            if (
-                self._lines
-                and journey["number"] not in self._lines
-                or journey["minutes"] < self._time_offset
-            ):
+            if (self._lines and journey["number"] not in self._lines) or journey[
+                "minutes"
+            ] < self._time_offset:
                 continue
 
             for attr in ("direction", "departure_time", "product", "minutes"):
diff --git a/homeassistant/components/shelly/switch.py b/homeassistant/components/shelly/switch.py
index 134704cb0ffce244248b402b0371426e079e92ba..8a33dae09383dcd89a1284e8bb815da3c5d11b6c 100644
--- a/homeassistant/components/shelly/switch.py
+++ b/homeassistant/components/shelly/switch.py
@@ -120,9 +120,8 @@ def async_setup_block_entry(
     relay_blocks = []
     assert coordinator.device.blocks
     for block in coordinator.device.blocks:
-        if (
-            block.type != "relay"
-            or block.channel is not None
+        if block.type != "relay" or (
+            block.channel is not None
             and is_block_channel_type_light(
                 coordinator.device.settings, int(block.channel)
             )
diff --git a/homeassistant/components/siren/__init__.py b/homeassistant/components/siren/__init__.py
index 9ce6898fd9356073a2e37a8fb99f1e230512a318..02b49f5732e29ded807829105fef0c0d44a402b6 100644
--- a/homeassistant/components/siren/__init__.py
+++ b/homeassistant/components/siren/__init__.py
@@ -68,10 +68,8 @@ def process_turn_on_params(
             isinstance(siren.available_tones, dict)
             and tone in siren.available_tones.values()
         )
-        if (
-            not siren.available_tones
-            or tone not in siren.available_tones
-            and not is_tone_dict_value
+        if not siren.available_tones or (
+            tone not in siren.available_tones and not is_tone_dict_value
         ):
             raise ValueError(
                 f"Invalid tone specified for entity {siren.entity_id}: {tone}, "
diff --git a/homeassistant/components/snmp/device_tracker.py b/homeassistant/components/snmp/device_tracker.py
index 3c4a0a0725c6c37b5d3f9d77d6fd0fe268345a64..4c2b2b25ad8da7449bc8f4bc938d7035bf45c122 100644
--- a/homeassistant/components/snmp/device_tracker.py
+++ b/homeassistant/components/snmp/device_tracker.py
@@ -172,7 +172,7 @@ class SnmpScanner(DeviceScanner):
                 _LOGGER.error(
                     "SNMP error: %s at %s",
                     errstatus.prettyPrint(),
-                    errindex and res[int(errindex) - 1][0] or "?",
+                    (errindex and res[int(errindex) - 1][0]) or "?",
                 )
                 return None
 
diff --git a/homeassistant/components/snmp/switch.py b/homeassistant/components/snmp/switch.py
index 92e27daed6c3fb33c6503982b92e9f4fd5e1e3c6..2f9f8b0bfb74bfe0548fb5f66c2487a6ae021824 100644
--- a/homeassistant/components/snmp/switch.py
+++ b/homeassistant/components/snmp/switch.py
@@ -264,7 +264,7 @@ class SnmpSwitch(SwitchEntity):
             _LOGGER.error(
                 "SNMP error: %s at %s",
                 errstatus.prettyPrint(),
-                errindex and restable[-1][int(errindex) - 1] or "?",
+                (errindex and restable[-1][int(errindex) - 1]) or "?",
             )
         else:
             for resrow in restable:
diff --git a/homeassistant/components/squeezebox/__init__.py b/homeassistant/components/squeezebox/__init__.py
index f466f3bcb62c06e38857a095d09664b72d18569e..f94ea118c6a4a878d6f00773a1dad13afe9971ff 100644
--- a/homeassistant/components/squeezebox/__init__.py
+++ b/homeassistant/components/squeezebox/__init__.py
@@ -105,9 +105,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: SqueezeboxConfigEntry) -
     lms.name = (
         (STATUS_QUERY_LIBRARYNAME in status and status[STATUS_QUERY_LIBRARYNAME])
         and status[STATUS_QUERY_LIBRARYNAME]
-        or host
-    )
-    version = STATUS_QUERY_VERSION in status and status[STATUS_QUERY_VERSION] or None
+    ) or host
+    version = (STATUS_QUERY_VERSION in status and status[STATUS_QUERY_VERSION]) or None
     # mac can be missing
     mac_connect = (
         {(CONNECTION_NETWORK_MAC, format_mac(status[STATUS_QUERY_MAC]))}
diff --git a/homeassistant/components/ssdp/__init__.py b/homeassistant/components/ssdp/__init__.py
index 637974853f6350e1f1e7789ed69b607d13558416..c5fb349ddbb6aeb4ee47d9e81c0e1d49f16997ef 100644
--- a/homeassistant/components/ssdp/__init__.py
+++ b/homeassistant/components/ssdp/__init__.py
@@ -273,7 +273,7 @@ async def async_build_source_set(hass: HomeAssistant) -> set[IPv4Address | IPv6A
         for source_ip in await network.async_get_enabled_source_ips(hass)
         if not source_ip.is_loopback
         and not source_ip.is_global
-        and (source_ip.version == 6 and source_ip.scope_id or source_ip.version == 4)
+        and ((source_ip.version == 6 and source_ip.scope_id) or source_ip.version == 4)
     }
 
 
diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py
index 80c175ccfe4857fafc1f3f35ae39c7ce99d3fc61..0213fd17864a65d9189fa8efda65e5a062031ce6 100644
--- a/homeassistant/components/tts/__init__.py
+++ b/homeassistant/components/tts/__init__.py
@@ -1052,10 +1052,8 @@ class TextToSpeechUrlView(HomeAssistantView):
             data = await request.json()
         except ValueError:
             return self.json_message("Invalid JSON specified", HTTPStatus.BAD_REQUEST)
-        if (
-            not data.get("engine_id")
-            and not data.get(ATTR_PLATFORM)
-            or not data.get(ATTR_MESSAGE)
+        if (not data.get("engine_id") and not data.get(ATTR_PLATFORM)) or not data.get(
+            ATTR_MESSAGE
         ):
             return self.json_message(
                 "Must specify platform and message", HTTPStatus.BAD_REQUEST
diff --git a/homeassistant/components/tuya/vacuum.py b/homeassistant/components/tuya/vacuum.py
index 738492102a148121674d8f182158505ecf56453d..bab9ac309ecfdf1f70bcae5ce5a0e6e7774b7f93 100644
--- a/homeassistant/components/tuya/vacuum.py
+++ b/homeassistant/components/tuya/vacuum.py
@@ -89,9 +89,8 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity):
         if self.find_dpcode(DPCode.PAUSE, prefer_function=True):
             self._attr_supported_features |= VacuumEntityFeature.PAUSE
 
-        if (
-            self.find_dpcode(DPCode.SWITCH_CHARGE, prefer_function=True)
-            or (
+        if self.find_dpcode(DPCode.SWITCH_CHARGE, prefer_function=True) or (
+            (
                 enum_type := self.find_dpcode(
                     DPCode.MODE, dptype=DPType.ENUM, prefer_function=True
                 )
diff --git a/homeassistant/components/unifi/services.py b/homeassistant/components/unifi/services.py
index ce726a0f5d025dd35f210e59b6a1b32888f69b6a..fc63c092d5624f251b31161e87a8e6be05f299b6 100644
--- a/homeassistant/components/unifi/services.py
+++ b/homeassistant/components/unifi/services.py
@@ -69,8 +69,7 @@ async def async_reconnect_client(hass: HomeAssistant, data: Mapping[str, Any]) -
 
     for config_entry in hass.config_entries.async_entries(UNIFI_DOMAIN):
         if config_entry.state is not ConfigEntryState.LOADED or (
-            (hub := config_entry.runtime_data)
-            and not hub.available
+            ((hub := config_entry.runtime_data) and not hub.available)
             or (client := hub.api.clients.get(mac)) is None
             or client.is_wired
         ):
@@ -87,10 +86,8 @@ async def async_remove_clients(hass: HomeAssistant, data: Mapping[str, Any]) ->
     - Neither IP, hostname nor name is configured.
     """
     for config_entry in hass.config_entries.async_entries(UNIFI_DOMAIN):
-        if (
-            config_entry.state is not ConfigEntryState.LOADED
-            or (hub := config_entry.runtime_data)
-            and not hub.available
+        if config_entry.state is not ConfigEntryState.LOADED or (
+            (hub := config_entry.runtime_data) and not hub.available
         ):
             continue
 
diff --git a/homeassistant/components/whirlpool/sensor.py b/homeassistant/components/whirlpool/sensor.py
index b84518cedf109d8618324c77d0b8d62b23233c1b..9180164c272dc8d625092cb75d71fb567d6580d5 100644
--- a/homeassistant/components/whirlpool/sensor.py
+++ b/homeassistant/components/whirlpool/sensor.py
@@ -291,9 +291,8 @@ class WasherDryerTimeClass(RestoreSensor):
                 seconds=int(self._wd.get_attribute("Cavity_TimeStatusEstTimeRemaining"))
             )
 
-            if (
-                self._attr_native_value is None
-                or isinstance(self._attr_native_value, datetime)
+            if self._attr_native_value is None or (
+                isinstance(self._attr_native_value, datetime)
                 and abs(new_timestamp - self._attr_native_value) > timedelta(seconds=60)
             ):
                 self._attr_native_value = new_timestamp
diff --git a/homeassistant/components/zone/trigger.py b/homeassistant/components/zone/trigger.py
index aa4aefe6d95c2b23d2f36bf4caa3ffb79e6138ab..af4999e5438dbf287a5ae33b28bfbfe66ad0f711 100644
--- a/homeassistant/components/zone/trigger.py
+++ b/homeassistant/components/zone/trigger.py
@@ -85,11 +85,8 @@ async def async_attach_trigger(
         from_s = zone_event.data["old_state"]
         to_s = zone_event.data["new_state"]
 
-        if (
-            from_s
-            and not location.has_location(from_s)
-            or to_s
-            and not location.has_location(to_s)
+        if (from_s and not location.has_location(from_s)) or (
+            to_s and not location.has_location(to_s)
         ):
             return
 
@@ -107,13 +104,8 @@ async def async_attach_trigger(
         from_match = condition.zone(hass, zone_state, from_s) if from_s else False
         to_match = condition.zone(hass, zone_state, to_s) if to_s else False
 
-        if (
-            event == EVENT_ENTER
-            and not from_match
-            and to_match
-            or event == EVENT_LEAVE
-            and from_match
-            and not to_match
+        if (event == EVENT_ENTER and not from_match and to_match) or (
+            event == EVENT_LEAVE and from_match and not to_match
         ):
             description = f"{entity} {_EVENT_DESCRIPTION[event]} {zone_state.attributes[ATTR_FRIENDLY_NAME]}"
             hass.async_run_hass_job(
diff --git a/homeassistant/components/zwave_js/light.py b/homeassistant/components/zwave_js/light.py
index e6cfc6c8b29e2df57fa5aa62313436423de9543c..639d2fbcd7a1a3814a26d814411f57dc9c1b63cb 100644
--- a/homeassistant/components/zwave_js/light.py
+++ b/homeassistant/components/zwave_js/light.py
@@ -458,7 +458,7 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
         if warm_white and cool_white:
             self._supports_color_temp = True
         # only one white channel (warm white or cool white) = rgbw support
-        elif red and green and blue and warm_white or cool_white:
+        elif (red and green and blue and warm_white) or cool_white:
             self._supports_rgbw = True
 
     @callback
diff --git a/homeassistant/helpers/condition.py b/homeassistant/helpers/condition.py
index 5952e28a1eb9b54f8fa9912f6d747db45305c9ce..695af80bc1c563446c1a31089f447ce68fe15a83 100644
--- a/homeassistant/helpers/condition.py
+++ b/homeassistant/helpers/condition.py
@@ -884,10 +884,8 @@ def time(
 
         condition_trace_update_result(weekday=weekday, now_weekday=now_weekday)
         if (
-            isinstance(weekday, str)
-            and weekday != now_weekday
-            or now_weekday not in weekday
-        ):
+            isinstance(weekday, str) and weekday != now_weekday
+        ) or now_weekday not in weekday:
             return False
 
     return True
diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py
index 72a4ef3c05065c9e7639bf99f67a75e8f9e680a4..b363bc21e8616dd323fedd93179e8623eb44793f 100644
--- a/homeassistant/helpers/event.py
+++ b/homeassistant/helpers/event.py
@@ -951,8 +951,7 @@ def async_track_template(
         if (
             not isinstance(last_result, TemplateError)
             and result_as_boolean(last_result)
-            or not result_as_boolean(result)
-        ):
+        ) or not result_as_boolean(result):
             return
 
         hass.async_run_hass_job(
diff --git a/homeassistant/helpers/script.py b/homeassistant/helpers/script.py
index f3f798e1d6b5f518e5446420e62ea7a267e59f9f..1fd0e08988c6b8854888629b24cfbe604a07e7d9 100644
--- a/homeassistant/helpers/script.py
+++ b/homeassistant/helpers/script.py
@@ -756,10 +756,8 @@ class _ScriptRun:
                 )
 
         running_script = (
-            params[CONF_DOMAIN] == "automation"
-            and params[CONF_SERVICE] == "trigger"
-            or params[CONF_DOMAIN] in ("python_script", "script")
-        )
+            params[CONF_DOMAIN] == "automation" and params[CONF_SERVICE] == "trigger"
+        ) or params[CONF_DOMAIN] in ("python_script", "script")
         trace_set_result(params=params, running_script=running_script)
         response_data = await self._async_run_long_action(
             self._hass.async_create_task_internal(
diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py
index e8c169e92d8ecbfa05f5c695effb4f6c4e412e1d..4625c3000ba4bd678a1b0a77764dc372e69c9484 100644
--- a/homeassistant/helpers/template.py
+++ b/homeassistant/helpers/template.py
@@ -601,7 +601,7 @@ class Template:
         or filter depending on hass or the state machine.
         """
         if self.is_static:
-            if not parse_result or self.hass and self.hass.config.legacy_templates:
+            if not parse_result or (self.hass and self.hass.config.legacy_templates):
                 return self.template
             return self._parse_result(self.template)
         assert self.hass is not None, "hass variable not set on template"
@@ -630,7 +630,7 @@ class Template:
         self._renders += 1
 
         if self.is_static:
-            if not parse_result or self.hass and self.hass.config.legacy_templates:
+            if not parse_result or (self.hass and self.hass.config.legacy_templates):
                 return self.template
             return self._parse_result(self.template)
 
@@ -651,7 +651,7 @@ class Template:
 
         render_result = render_result.strip()
 
-        if not parse_result or self.hass and self.hass.config.legacy_templates:
+        if not parse_result or (self.hass and self.hass.config.legacy_templates):
             return render_result
 
         return self._parse_result(render_result)
@@ -826,7 +826,7 @@ class Template:
                 )
             return value if error_value is _SENTINEL else error_value
 
-        if not parse_result or self.hass and self.hass.config.legacy_templates:
+        if not parse_result or (self.hass and self.hass.config.legacy_templates):
             return render_result
 
         return self._parse_result(render_result)
@@ -1873,7 +1873,8 @@ def is_state(hass: HomeAssistant, entity_id: str, state: str | list[str]) -> boo
     """Test if a state is a specific value."""
     state_obj = _get_state(hass, entity_id)
     return state_obj is not None and (
-        state_obj.state == state or isinstance(state, list) and state_obj.state in state
+        state_obj.state == state
+        or (isinstance(state, list) and state_obj.state in state)
     )
 
 
diff --git a/homeassistant/helpers/update_coordinator.py b/homeassistant/helpers/update_coordinator.py
index 8acd43970f9f0a065b9a4c0d1437518a6c2a1c2f..62dcb2622e792c7de33bcdfda600a56654bd0cc1 100644
--- a/homeassistant/helpers/update_coordinator.py
+++ b/homeassistant/helpers/update_coordinator.py
@@ -359,7 +359,7 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
         self._async_unsub_refresh()
         self._debounced_refresh.async_cancel()
 
-        if self._shutdown_requested or scheduled and self.hass.is_stopping:
+        if self._shutdown_requested or (scheduled and self.hass.is_stopping):
             return
 
         if log_timing := self.logger.isEnabledFor(logging.DEBUG):
diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py
index d66845583d1030e86b5d5fcd112def04f1b3cf35..d06d078ae8b894e7e731b1c202cc18ef142fc581 100644
--- a/pylint/plugins/hass_enforce_type_hints.py
+++ b/pylint/plugins/hass_enforce_type_hints.py
@@ -55,10 +55,14 @@ class TypeHintMatch:
         """Confirm if function should be checked."""
         return (
             self.function_name == node.name
-            or self.has_async_counterpart
-            and node.name == f"async_{self.function_name}"
-            or self.function_name.endswith("*")
-            and node.name.startswith(self.function_name[:-1])
+            or (
+                self.has_async_counterpart
+                and node.name == f"async_{self.function_name}"
+            )
+            or (
+                self.function_name.endswith("*")
+                and node.name.startswith(self.function_name[:-1])
+            )
         )
 
 
@@ -2998,8 +3002,8 @@ def _is_valid_type(
         isinstance(node, nodes.Subscript)
         and isinstance(node.value, nodes.Name)
         and node.value.name in _KNOWN_GENERIC_TYPES
-        or isinstance(node, nodes.Name)
-        and node.name.endswith(_KNOWN_GENERIC_TYPES_TUPLE)
+    ) or (
+        isinstance(node, nodes.Name) and node.name.endswith(_KNOWN_GENERIC_TYPES_TUPLE)
     ):
         return True
 
diff --git a/pylint/plugins/hass_imports.py b/pylint/plugins/hass_imports.py
index 194f99ae700a76f0eb7b817d804012699a41e698..2fe70fad10dda88fa6b62c3709ac6a0ea2bcb9de 100644
--- a/pylint/plugins/hass_imports.py
+++ b/pylint/plugins/hass_imports.py
@@ -268,9 +268,8 @@ class HassImportsFormatChecker(BaseChecker):
         self, current_package: str, node: nodes.ImportFrom
     ) -> None:
         """Check for improper 'from ._ import _' invocations."""
-        if (
-            node.level <= 1
-            or not current_package.startswith("homeassistant.components.")
+        if node.level <= 1 or (
+            not current_package.startswith("homeassistant.components.")
             and not current_package.startswith("tests.components.")
         ):
             return
diff --git a/pyproject.toml b/pyproject.toml
index 8cd777c3c67461f9baa138082bd872202c59edea..0623d681df7bd2e089f22aac8cb882f1bcedecbd 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -763,6 +763,7 @@ select = [
     "RUF018", # Avoid assignment expressions in assert statements
     "RUF019", # Unnecessary key check before dictionary access
     "RUF020", # {never_like} | T is equivalent to T
+    "RUF021", # Parenthesize a and b expressions when chaining and and or together, to make the precedence clear
     "RUF022", # Sort __all__
     "RUF024", # Do not pass mutable objects as values to dict.fromkeys
     "RUF026", # default_factory is a positional-only argument to defaultdict
diff --git a/script/translations/deduplicate.py b/script/translations/deduplicate.py
index f92f90115cefc7f9ab1fd1c0e0d4cd6da6112035..ac608a1aa0e4440ee35097f60988f0083c956cd6 100644
--- a/script/translations/deduplicate.py
+++ b/script/translations/deduplicate.py
@@ -70,8 +70,10 @@ def run():
         # If we want to only add references to own integrations
         # but not include entity integrations
         if (
-            args.limit_reference
-            and (key_integration != key_to_reference_integration and not is_common)
+            (
+                args.limit_reference
+                and (key_integration != key_to_reference_integration and not is_common)
+            )
             # Do not create self-references in entity integrations
             or key_integration in Platform.__members__.values()
         ):
diff --git a/tests/components/google_assistant/test_helpers.py b/tests/components/google_assistant/test_helpers.py
index 0e6876cc9019928247eee91bdce5d3ece7685d99..a5451e5332d50f9c49a332b583d98c3834ffbbba 100644
--- a/tests/components/google_assistant/test_helpers.py
+++ b/tests/components/google_assistant/test_helpers.py
@@ -316,7 +316,7 @@ async def test_sync_notifications(agents) -> None:
         config, "async_sync_notification", return_value=HTTPStatus.NO_CONTENT
     ) as mock:
         await config.async_sync_notification_all("1234", {})
-        assert not agents or bool(mock.mock_calls) and agents
+        assert not agents or (bool(mock.mock_calls) and agents)
 
 
 @pytest.mark.parametrize(
diff --git a/tests/components/imap/test_init.py b/tests/components/imap/test_init.py
index d4281b9e5134003fa7fa3ce7c1619532832e461f..b86855bd78f3656ba87d24a26b517c23afe26ba7 100644
--- a/tests/components/imap/test_init.py
+++ b/tests/components/imap/test_init.py
@@ -171,11 +171,8 @@ async def test_receiving_message_successfully(
     assert data["subject"] == "Test subject"
     assert data["uid"] == "1"
     assert "Test body" in data["text"]
-    assert (
-        valid_date
-        and isinstance(data["date"], datetime)
-        or not valid_date
-        and data["date"] is None
+    assert (valid_date and isinstance(data["date"], datetime)) or (
+        not valid_date and data["date"] is None
     )
 
 
@@ -581,11 +578,8 @@ async def test_reset_last_message(
     assert data["subject"] == "Test subject"
     assert data["text"]
     assert data["initial"]
-    assert (
-        valid_date
-        and isinstance(data["date"], datetime)
-        or not valid_date
-        and data["date"] is None
+    assert (valid_date and isinstance(data["date"], datetime)) or (
+        not valid_date and data["date"] is None
     )
 
     # Simulate an update where no messages are found (needed for pushed coordinator)
diff --git a/tests/components/matrix/test_commands.py b/tests/components/matrix/test_commands.py
index dabee74fdc3265c47f7fd4dbb862c864b5bf6a1f..ea0805b920ac9a41e367579eb244071364bb54e5 100644
--- a/tests/components/matrix/test_commands.py
+++ b/tests/components/matrix/test_commands.py
@@ -42,9 +42,8 @@ class CommandTestParameters:
         Commands that are named with 'Subset' are expected not to be read from Room A.
         """
 
-        if (
-            self.expected_event_data_extra is None
-            or "Subset" in self.expected_event_data_extra["command"]
+        if self.expected_event_data_extra is None or (
+            "Subset" in self.expected_event_data_extra["command"]
             and self.room_id not in SUBSET_ROOMS
         ):
             return None
diff --git a/tests/components/onewire/__init__.py b/tests/components/onewire/__init__.py
index ac7e917d10a6a47c2742a79a6249edfda2f9bc9b..9c025fe33af24ca1cb5c0ea04cbe4f9097add19c 100644
--- a/tests/components/onewire/__init__.py
+++ b/tests/components/onewire/__init__.py
@@ -25,10 +25,8 @@ def setup_owproxy_mock_devices(owproxy: MagicMock, device_ids: list[str]) -> Non
         if (side_effect := dir_side_effect.get(path)) is None:
             raise NotImplementedError(f"Unexpected _dir call: {path}")
         result = side_effect.pop(0)
-        if (
-            isinstance(result, Exception)
-            or isinstance(result, type)
-            and issubclass(result, Exception)
+        if isinstance(result, Exception) or (
+            isinstance(result, type) and issubclass(result, Exception)
         ):
             raise result
         return result
@@ -39,10 +37,8 @@ def setup_owproxy_mock_devices(owproxy: MagicMock, device_ids: list[str]) -> Non
         if len(side_effect) == 0:
             raise ProtocolError(f"Missing injected value for: {path}")
         result = side_effect.pop(0)
-        if (
-            isinstance(result, Exception)
-            or isinstance(result, type)
-            and issubclass(result, Exception)
+        if isinstance(result, Exception) or (
+            isinstance(result, type) and issubclass(result, Exception)
         ):
             raise result
         return result