Skip to content

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Sep 29, 2025

Followup to #10581

Suggest rewriting conditional expressions

-if not isinstance(expr, nodes.Attribute) or expr.attrname != "__init__": ...
+if not (isinstance(expr, nodes.Attribute) and expr.attrname == "__init__"): ...

I've added the check in the CodeStyle extension. It might even make sense to disable it by default.

@cdce8p cdce8p added this to the 4.0.0 milestone Sep 29, 2025
@cdce8p cdce8p added Enhancement ✨ Improvement to a component Optional Checkers Related to a checked, disabled by default labels Sep 29, 2025
Comment on lines 78 to 102
"R6106": (
"Rewrite conditional expression to '%s'",
"improve-conditionals",
"Rewrite negated if expressions to improve readability.",
{
# "default_enabled": False,
},
),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be improved. Open to suggestions.
We could also change the checker name if someone has a good idea.

Besides that, should the checker be disabled by default even in the optional CodeStyle extension?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either that or it should be a pylint plugin. I regret including magic-number-comparison because then Ruff implemented it and Ruff does not take the default disable into account and it makes pylint look really opinionated and unreasonable.

Copy link

codecov bot commented Sep 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.98%. Comparing base (91d3e26) to head (0f72f23).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #10600      +/-   ##
==========================================
+ Coverage   95.96%   95.98%   +0.01%     
==========================================
  Files         176      176              
  Lines       19525    19584      +59     
==========================================
+ Hits        18738    18797      +59     
  Misses        787      787              
Files with missing lines Coverage Δ
pylint/extensions/code_style.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This comment has been minimized.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing the doc example with animal made me reconsider if the suggestion is always more readable. I guess when there's a double negation not x or not y, then yes, not (x and y) is better for not x or y >= 0 then not (x and y < 0) is slightly better, otherwise I don't know. The primer also point to an especially opinionated check that could be an external plugin. Let us hear from others.

Comment on lines 78 to 102
"R6106": (
"Rewrite conditional expression to '%s'",
"improve-conditionals",
"Rewrite negated if expressions to improve readability.",
{
# "default_enabled": False,
},
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either that or it should be a pylint plugin. I regret including magic-number-comparison because then Ruff implemented it and Ruff does not take the default disable into account and it makes pylint look really opinionated and unreasonable.

Comment on lines 1 to 4
def func(expr, node_cls):
# +1:[improve-conditionals]
if not isinstance(expr, node_cls) or expr.attrname != "__init__":
...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def func(expr, node_cls):
# +1:[improve-conditionals]
if not isinstance(expr, node_cls) or expr.attrname != "__init__":
...
def is_platypus(animal):
# The platypus is both the only mammal with a beak and without nipples.
# +1:[improve-conditionals]
return animal.is_mammal() and (not animal.has_nipples() or animal.has_beak)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your example wouldn't actually raise the message. Yes, it could be inverted but so far I've chosen not to emit it if we'd need to add not, only if it could be removed / moved before the BoolOp. I.e. it would only be emitted for

# bad
x and (not y or not z)

# good
x and not (y and z)

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok the checker is a lot less opinionated than I thought then : good.

I had to do some extensive phenology for this one, turn out uniquely identifying an animal by lack of a characteristic is not so easy.

Suggested change
def func(expr, node_cls):
# +1:[improve-conditionals]
if not isinstance(expr, node_cls) or expr.attrname != "__init__":
...
def is_penguin(animal):
# Penguins are the only flightless, kneeless sea birds
# +1:[improve-conditionals]
return animal.is_seabird() and (not animal.can_fly() or not animal.has_visible_knee())

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok the checker is a lot less opinionated than I thought then : good.

I went through all of the warning for Home Assistant. They looked quite good. There was just one common pattern I don't think the checker should emit a warning for.

# is x between 0 and 100
if x > 0 or x < 100:
    ...

Addressed that one in b08beb4

bool(name)
and name[0] == "_"
and (len(name) <= 4 or name[1] != "_" or name[-2:] != "__")
and not (len(name) > 4 and name[:2] == "__" and name[-2:] == "__")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition was done with great care about performance here, I'm not sure changing the order without benchmark is advisable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are they any different though? Let's consider some cases

Returning True

To return True with the "old" code, any one of the conditions had to evaluate to true and or short-circuits the conditional. With the "new" one it's just the inverse. Any one condition has to eval to false and and short-circuits as well. That's fine as all comparisons are inverted itself.

Returning False

With or all conditions had to be checked to make sure none actually returned true. Same with and. It will only return false if all conditions eval to true.

--
Am I missing something here? Tbh I had to think hard about it and even thought they aren't identical for a few minutes. In the end however, they should evaluate almost exactly the same.

--
I reverted the same change to the second check with name[:2] (instead of name[1]) in 7e4bb03.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at it too fast and thought that the prior check for first char is _ was removed, but it's not. We already checked the first character so name[:2] == "__" should stay name[1] == "_". And in this case it become equivalent.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+0.5 for deactivated by default in the code style checker. I invested so much time in the biology involved in the doc example that I now have sunk cost fallacy about it.

@cdce8p cdce8p force-pushed the check-improved-conditionals branch from 840dfbf to 7e4bb03 Compare October 1, 2025 19:23

This comment has been minimized.

Copy link
Member Author

@cdce8p cdce8p left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this check is ready now. Yes, it's a bit opinionated but that could even be a positive thing. In the end it'll be disabled by default in an optional checker.

At last I just want to highlight one of the cases I found in Home Assistant. There aren't a lot of them but sometimes it can be just art 🧑‍🎨

# current
if (
    not isinstance(data, dict)
    or "eventType" not in data
    or data["eventType"] != "changeReport"
    or "eventVersion" not in data
    or data["eventVersion"] != "1"
    or "context" not in data
    or not isinstance(data["context"], dict)
    or "deviceType" not in data["context"]
    or "deviceMac" not in data["context"]
):
    return
# with 'and' instead of 'or' it gets obvious that this might be a great place for match
if not (
    isinstance(data, dict)
    and "eventType" in data
    and data["eventType"] == "changeReport"
    and "eventVersion" in data
    and data["eventVersion"] == "1"
    and "context" in data
    and isinstance(data["context"], dict)
    and "deviceType" in data["context"]
    and "deviceMac" in data["context"]
):
    return
match data:
    case {
        "eventType": "changeReport",
        "eventVersion": "1",
        "context": {"deviceType": _, "deviceMac": _},
    }:
        pass
    case _:
        return

Comment on lines 1 to 4
def func(expr, node_cls):
# +1:[improve-conditionals]
if not isinstance(expr, node_cls) or expr.attrname != "__init__":
...
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok the checker is a lot less opinionated than I thought then : good.

I went through all of the warning for Home Assistant. They looked quite good. There was just one common pattern I don't think the checker should emit a warning for.

# is x between 0 and 100
if x > 0 or x < 100:
    ...

Addressed that one in b08beb4

bool(name)
and name[0] == "_"
and (len(name) <= 4 or name[1] != "_" or name[-2:] != "__")
and not (len(name) > 4 and name[:2] == "__" and name[-2:] == "__")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are they any different though? Let's consider some cases

Returning True

To return True with the "old" code, any one of the conditions had to evaluate to true and or short-circuits the conditional. With the "new" one it's just the inverse. Any one condition has to eval to false and and short-circuits as well. That's fine as all comparisons are inverted itself.

Returning False

With or all conditions had to be checked to make sure none actually returned true. Same with and. It will only return false if all conditions eval to true.

--
Am I missing something here? Tbh I had to think hard about it and even thought they aren't identical for a few minutes. In the end however, they should evaluate almost exactly the same.

--
I reverted the same change to the second check with name[:2] (instead of name[1]) in 7e4bb03.

This comment has been minimized.

@@ -0,0 +1,3 @@
Add :ref:`improve-conditionals` check to the Code Style extension.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Add :ref:`improve-conditionals` check to the Code Style extension.
Add :ref:`improve-conditionals` check to the Code Style extension to suggest `not(x and y)` instead of `not x or not y` in order to facilitate the detection of match case refactors. The code style extension must be enabled and `improve-conditionals` itself needs to be explicitely enabled.

),
"R6106": (
"Rewrite conditional expression to '%s'",
"improve-conditionals",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is a little vague. What about consider-factorizing-not, 'or-with-double-negation'... ? I'm on mobile but asking a llm about it might give the least surprising name for it.

@Pierre-Sassoulas
Copy link
Member

The exemple you give does make sense. What if we were raising only strictly above 2 negated conditions ? It's not the same purpose than the initial idea but it would make thé check a lot less opinionated

@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Oct 2, 2025

Or say we add an option for the threshold of negated conditions, and activate the message by default with a value of 4

@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 4.0.0, 4.1.0 Oct 11, 2025
@cdce8p cdce8p force-pushed the check-improved-conditionals branch from 87e5786 to 83a6e22 Compare October 13, 2025 10:06

This comment has been minimized.

@Pierre-Sassoulas
Copy link
Member

Regarding the name, here's some proposals after some thinking:

@cdce8p
Copy link
Member Author

cdce8p commented Oct 13, 2025

Regarding the name, [...]

How do you like consider-rewriting-conditional?

@cdce8p cdce8p force-pushed the check-improved-conditionals branch from d4a00c7 to ea50b73 Compare October 13, 2025 10:56
@Pierre-Sassoulas
Copy link
Member

We already have:
simplifiable-condition / R1726
simplifiable-if-expression / R1719
simplifiable-if-statement / R1703
simplify-boolean-expression / R1709
Very hard to tell what message warn about what here (without looking into the example). I was trying to bring a little more specificity into the new name.

@cdce8p cdce8p force-pushed the check-improved-conditionals branch from ea50b73 to 3a9d056 Compare October 13, 2025 10:59
@cdce8p
Copy link
Member Author

cdce8p commented Oct 13, 2025

Very hard to tell what message warn about what here (without looking into the example). I was trying to bring a little more specificity into the new name.

True. Though I don't think it's as bad as it looks. Each check provides a suggestion how to rewrite it. De Morgans law is technically correct but even I had to lookup the name again. So I don't think that's much help either.

Regarding simplifiable-double-negation I'm not sure it's actually a true simplification. One might argue that adding the brackets introduces a nesting which is more complex.

The check itself is fairly opinionated. Just looking at the examples we can probably agree that they are overall an improvement but regardless I still feel like it's more of a suggestion than anything else.

@cdce8p cdce8p force-pushed the check-improved-conditionals branch from 3a9d056 to f83f16f Compare October 13, 2025 11:06
@cdce8p cdce8p changed the title Add improve-conditionals check in the CodeStyle extension Add consider-rewriting-conditional check in the CodeStyle extension Oct 13, 2025
@cdce8p cdce8p mentioned this pull request Oct 13, 2025

This comment has been minimized.

@cdce8p cdce8p force-pushed the check-improved-conditionals branch from f83f16f to e94d54e Compare October 13, 2025 11:49
@cdce8p cdce8p force-pushed the check-improved-conditionals branch from 1374b13 to 0f72f23 Compare October 13, 2025 11:52
Copy link
Contributor

🤖 Effect of this PR on checked open source code: 🤖

Effect on home-assistant:
The following messages are now emitted:

  1. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (integration.homekit and 'models' in integration.homekit and integration.homekit['models'])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/loader.py#L600
  2. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (hass and integration_domain)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/loader.py#L1690
  3. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (running := current_setup_group.get() and running in _setup_started(hass))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/setup.py#L707
  4. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (context and 'source' in context)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/config_entries.py#L1413
  5. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (context and 'source' in context)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/config_entries.py#L1725
  6. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (issue.domain == HOMEASSISTANT_DOMAIN and issue_data := issue.data and issue_data.get('issue_type') == ISSUE_UNIQUE_ID_COLLISION)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/config_entries.py#L2727
  7. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (context and 'source' in context)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/config_entries.py#L3331
  8. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (domain and object_id)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/core.py#L192
  9. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (error_path and path_part := error_path[0] in schema)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/data_entry_flow.py#L175
  10. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (cur_step['progress_action'] == result.get('progress_action') and cur_step['description_placeholders'] == result.get('description_placeholders'))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/data_entry_flow.py#L430
  11. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (base_exc := exc.cause and isinstance(base_exc, MarkedYAMLError))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/config.py#L223
  12. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (cached_integration := cache.get(dep) and type(cached_integration) is Integration)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/requirements.py#L196
  13. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (cached_integration := cache.get(check_domain) and type(cached_integration) is Integration)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/requirements.py#L209
  14. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (_domain and _domain.strip(' ') == _domain)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/config_validation.py#L447
  15. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (isinstance(value, dict) and value)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/config_validation.py#L801
  16. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (key in breakpoints and run_id in breakpoints[key])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/script.py#L2077
  17. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.config_entry and config_subentry_id in self.config_entry.subentries)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/entity_platform.py#L709
  18. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (DATA_ENTITY_PLATFORM in hass.data and integration_name in hass.data[DATA_ENTITY_PLATFORM])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/entity_platform.py#L1267
  19. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (country in self.config['countries'] and country in COUNTRIES)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/selector.py#L630
  20. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (source_device_id and 'device_id' in data['changes'])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/helper_integration.py#L81
  21. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (source_device := device_registry.async_get(source_device_id) and helper_config_entry_id in source_device.config_entries)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/helper_integration.py#L146
  22. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (exposed_entities and exposed_entities['entities'])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/llm.py#L482
  23. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (llm_context.device_id and async_device_supports_timers(self.hass, llm_context.device_id))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/llm.py#L528
  24. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (llm_context.device_id and async_device_supports_timers(self.hass, llm_context.device_id))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/llm.py#L558
  25. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (key in last_variables and last_variables[key] == value)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/trace.py#L77
  26. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (url.scheme in CONFIGURATION_URL_SCHEMES and url.host)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/device_registry.py#L274
  27. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (config_entry_id in config_entries_subentries and config_subentry_id in config_entries_subentries[config_entry_id])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/device_registry.py#L1621
  28. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (config_entry := hass.config_entries.async_get_entry(config_entry_id) and config_subentry_id in config_entry.subentries)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/entity_registry.py#L775
  29. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entry.data.get('cloudhook') and 'cloud' in hass.config.components)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/config_entry_flow.py#L278
  30. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (group and ATTR_ENTITY_ID in group.attributes)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/group.py#L53
  31. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.hass and self._verified_state_writable)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/entity.py#L1015
  32. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.hass and self._verified_state_writable)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/entity.py#L1022
  33. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.has_entity_name and device_entry := self.device_entry)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/entity.py#L1053
  34. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (capabilities == entry.capabilities and original_device_class == entry.original_device_class and supported_features == entry.supported_features)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/entity.py#L1160
  35. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self._on_remove and self._async_unsubscribe_device_updates in self._on_remove)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/entity.py#L1604
  36. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (state.domain == 'sensor' and state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/area_registry.py#L549
  37. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (state.domain == 'sensor' and state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.HUMIDITY)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/area_registry.py#L563
  38. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (exception_filter and exception_filter(err))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/recorder.py#L103
  39. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (conf_key in self._config and attr in last_state.attributes)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/helpers/trigger_template_entity.py#L237
  40. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (args and args[0] in commands)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/scripts/macos/__init__.py#L50
  41. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (item.summary == current_item.summary and item.description == current_item.description and item.due == current_item.due)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/habitica/todo.py#L176
  42. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (media_type.lower() == 'radio' and source in PLAYABLE_SOURCES)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/onkyo/media_player.py#L335
  43. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.currently_playing and self.currently_playing.item)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/spotify/media_player.py#L91
  44. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (disc_key.version == 1 and isinstance(key := disc_key.key, str))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/hassio/discovery.py#L61
  45. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entry.source == config_entries.SOURCE_HASSIO and entry.unique_id == uuid)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/hassio/discovery.py#L159
  46. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (data.get('event') == 'job' and event_data := data.get('data') and event_data.get('name') in MOUNT_JOBS and event_data.get('done') is True)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/hassio/backup.py#L107
  47. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (data.get('event') == 'job' and event_data := data.get('data') and event_data.get('uuid') == job_id.hex)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/hassio/backup.py#L729
  48. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (grandchild.name == grandchild_job_name and grandchild.errors and grandchild.reference)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/hassio/backup.py#L760
  49. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (addon in panels and panels[addon][ATTR_ENABLE])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/hassio/addon_panel.py#L55
  50. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.issue and self.issue.suggestions)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/hassio/repairs.py#L82
  51. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (new_timezone == last_timezone and new_country == last_country)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/hassio/__init__.py#L412
  52. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (DOMAIN in hass.data and split_entity_id(entity_id)[0] == DEVICE_TRACKER_DOMAIN)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/person/__init__.py#L140
  53. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (event.device and event.device.id_string)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/rfxtrx/__init__.py#L184
  54. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entity := component.get_entity(entity_id) and isinstance(entity, CalendarEntity))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/calendar/trigger.py#L99
  55. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (value := obj.get(key) and isinstance(value, datetime.datetime))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/calendar/__init__.py#L115
  56. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entity := self.component.get_entity(entity_id) and isinstance(entity, CalendarEntity))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/calendar/__init__.py#L656
  57. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entity.supported_features and entity.supported_features & CalendarEntityFeature.CREATE_EVENT)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/calendar/__init__.py#L735
  58. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entity.supported_features and entity.supported_features & CalendarEntityFeature.DELETE_EVENT)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/calendar/__init__.py#L775
  59. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entity.supported_features and entity.supported_features & CalendarEntityFeature.UPDATE_EVENT)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/calendar/__init__.py#L820
  60. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (light_ids == saved_light_ids and exclude_ids == saved_exclude_ids)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/vera/__init__.py#L96
  61. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entry and hasattr(entry, 'runtime_data'))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/google_sheets/services.py#L73
  62. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.is_on and kwargs)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/govee_light_local/light.py#L187
  63. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (first[CONF_HOST] == second[CONF_HOST] and first[CONF_PORT] == second[CONF_PORT])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/nut/config_flow.py#L85
  64. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self._speed and self._power)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/bond/fan.py#L97
  65. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (identifier[0] == DOMAIN and len(identifier) == 3)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/bond/__init__.py#L128
  66. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (hub.bond_id == bond_id and any((device_id == device.device_id for device in hub.devices)))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/bond/__init__.py#L136
  67. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (port == router.port and ssl == router.ssl)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/netgear/__init__.py#L48
  68. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (discovery_info.ssdp_location and ATTR_UPNP_MANUFACTURER in discovery_info.upnp and ATTR_UPNP_SERIAL in discovery_info.upnp and ATTR_UPNP_MODEL_NAME in discovery_info.upnp and ATTR_UPNP_MODEL_NUMBER in discovery_info.upnp)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/wilight/config_flow.py#L67
  69. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not ('motor_state' in self._status and 'position_current' in self._status)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/wilight/cover.py#L93
  70. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (configured_by_user := DOMAIN in config and url := config[DOMAIN].get(CONF_URL))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/go2rtc/__init__.py#L117
  71. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self._cloud.is_logged_in and self._prefs.google_connected and self._cloud.username)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/cloud/google_config.py#L404
  72. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.enabled and self._cloud.is_logged_in and self.hass.state is CoreState.running)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/cloud/google_config.py#L461
  73. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.enabled and self._cloud.is_logged_in and self.hass.state is CoreState.running)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/cloud/google_config.py#L486
  74. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (event.data['action'] == 'update' and 'area_id' in event.data['changes'])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/cloud/google_config.py#L493
  75. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.enabled and self._cloud.is_logged_in)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/cloud/alexa_config.py#L527
  76. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (preset_modes and preset_mode in preset_modes)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/fan/__init__.py#L278
  77. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (location_info and is_ipv4_address(location_info.ip))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/cloudflare/__init__.py#L113
  78. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (valid_state and valid_state_numeric)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/group/sensor.py#L447
  79. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (description.key in coordinator.data and QSD_LACP_PORTS in coordinator.data[description.key])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/qnap_qsw/sensor.py#L307
  80. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (description.key in coordinator.data and QSD_PORTS in coordinator.data[description.key])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/qnap_qsw/sensor.py#L327
  81. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self._source.presets and preset_id in self._source.presets)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/russound_rio/media_player.py#L262
  82. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (pump_data and pump_data.get(VALUE.DATA))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/screenlogic/sensor.py#L293
  83. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (p_data and p_data.get(VALUE.DATA))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/screenlogic/binary_sensor.py#L216
  84. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entry := hass.config_entries.async_get_entry(entry_id) and entry.domain == validated_config[CONF_DOMAIN])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/device_automation/helpers.py#L98
  85. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (hs_color and self.supported_color_modes and ColorMode.HS in self.supported_color_modes)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/yeelight/light.py#L629
  86. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (rgb and self.supported_color_modes and ColorMode.RGB in self.supported_color_modes)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/yeelight/light.py#L654
  87. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (temp_in_k and self.supported_color_modes and ColorMode.COLOR_TEMP in self.supported_color_modes)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/yeelight/light.py#L679
  88. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (int(self._get_property('color_mode')) == 1 and self.hs_color)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/yeelight/light.py#L710
  89. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (current_entry and host == urlparse(current_entry['location']).hostname)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/yeelight/scanner.py#L198
  90. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (CONF_PRODUCT_NAME in discovery_info.properties and CONF_PRODUCT_TYPE in discovery_info.properties and CONF_SERIAL in discovery_info.properties)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/homewizard/config_flow.py#L127
  91. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (len(platform_split) >= 2 and platform_split[1] in TRIGGERS)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/webostv/trigger.py#L28
  92. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.state == MediaPlayerState.OFF and self._supported_features)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/webostv/media_player.py#L249
  93. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.assistant and language == self.language)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/google_assistant_sdk/__init__.py#L121
  94. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (status.user and status.user.username)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/geocaching/config_flow.py#L51
  95. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (bucket and key)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/minio/minio_helper.py#L204
  96. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (CONF_TOKEN_EXPIRY in self._entry.data and CONF_ACCESS_TOKEN in self._entry.data)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/flick_electric/__init__.py#L114
  97. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.selected_region and user_input[CONF_REGION] == self.selected_region['regionId'])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/ukraine_alarm/config_flow.py#L100
  98. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (new_state == self.state and img == self.entity_picture)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/buienradar/sensor.py#L830
  99. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (new_state == self.state and img == self.entity_picture)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/buienradar/sensor.py#L876
  100. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (current_source and current_source in self._sources)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/control4/media_player.py#L285
  101. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (current_source and current_source in self._sources)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/control4/media_player.py#L298
  102. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self._char_battery and self._char_low_battery)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/homekit/accessories.py#L592
  103. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.support_select_source and self.sources)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/homekit/type_remotes.py#L184
  104. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (value >= 30 and self._supports_stop)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/homekit/type_covers.py#L416
  105. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.char_speed and CHAR_ROTATION_SPEED in char_values)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/homekit/type_fans.py#L180
  106. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (config and DOMAIN in config)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/homekit/__init__.py#L519
  107. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (identifier in entry.identifiers and connection in entry.connections)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/homekit/__init__.py#L981
  108. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entry := hass.config_entries.async_get_entry(entry_id) and entry_data := getattr(entry, 'runtime_data', None) and secret and entry_data.pairing_qr_secret and secret == entry_data.pairing_qr_secret)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/homekit/__init__.py#L1224
  109. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.citation_details and self.citation_details[-1].length <= 0)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/anthropic/entity.py#L129
  110. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (messages and messages[-1]['role'] == ('assistant' if external_tool else 'user'))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/anthropic/entity.py#L189
  111. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (messages and messages[-1]['role'] == 'user')'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/anthropic/entity.py#L207
  112. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (messages and messages[-1]['role'] == 'assistant')'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/anthropic/entity.py#L225
  113. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (data and 'status' in data)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/fireservicerota/switch.py#L142
  114. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (data and 'body' in data)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/fireservicerota/sensor.py#L118
  115. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.data and Attribute.MAC_ADDRESS in self.data)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/aprilaire/coordinator.py#L122
  116. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (data and Attribute.MAC_ADDRESS in data)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/aprilaire/coordinator.py#L129
  117. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.data and Attribute.THERMOSTAT_MODES in self.data)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/aprilaire/coordinator.py#L135
  118. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.data and Attribute.INDOOR_TEMPERATURE_CONTROLLING_SENSOR_STATUS in self.data)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/aprilaire/coordinator.py#L143
  119. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (hass.config.external_url and hass.config.internal_url)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/media_player/browse_media.py#L87
  120. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (search_response and entity_response := cast(SearchMedia, search_response.get(target_entity_id)) and results := entity_response.result)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/media_player/intent.py#L368
  121. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (options and option in options)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/select/__init__.py#L172
  122. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (isinstance(old, HomeAssistantScene) and old.from_service)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/homeassistant/scene.py#L263
  123. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not ('should_expose' in settings and settings['should_expose'])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/homeassistant/exposed_entities.py#L449
  124. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.__code_format_cmp and self.code_format == self.__code_format_cmp.pattern)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/lock/__init__.py#L170
  125. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self._is_new_entity and wrapped_switch := registry.async_get(self._switch_entity_id))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/switch_as_x/entity.py#L104
  126. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self._volume.level and self._volume.level.level)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/bang_olufsen/media_player.py#L841
  127. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (unique_id and unique_id.count(':') == 7)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/deconz/util.py#L18
  128. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (device.model in REMOTES and trigger in REMOTES[device.model])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/deconz/device_trigger.py#L715
  129. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.preset_modes and preset_mode in self.preset_modes)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/comfoconnect/fan.py#L170
  130. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (set(sensor_names).issubset(set(self._sensors)) and sensor_names)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/ecobee/climate.py#L871
  131. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (job and job.progress.print_time_left and _is_printer_printing(self.coordinator.data['printer']))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/octoprint/sensor.py#L180
  132. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (job and job.progress.print_time and _is_printer_printing(self.coordinator.data['printer']))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/octoprint/sensor.py#L210
  133. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (camera_info and camera_info.enabled)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/octoprint/camera.py#L35
  134. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (host.api.port == config_entry.data[CONF_PORT] and host.api.use_https == config_entry.data[CONF_USE_HTTPS] and host.api.supported(None, 'privacy_mode') == config_entry.data.get(CONF_SUPPORTS_PRIVACY_MODE) and host.api.baichuan.port == config_entry.data.get(CONF_BC_PORT) and host.api.baichuan_only == config_entry.data.get(CONF_BC_ONLY))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/reolink/__init__.py#L106
  135. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (host.api.supported(int(ch), 'replay') and host.api.hdd_info)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/reolink/media_source.py#L209
  136. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (device and device.model in DEVICES and trigger in DEVICES[device.model])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/netatmo/device_trigger.py#L84
  137. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (item.identifier and '/' in item.identifier)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/netatmo/media_source.py#L148
  138. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not ('updateDataSet' in data and 'commonName' in data and self.data.agreement.display_common_name == data['commonName'])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/toon/coordinator.py#L125
  139. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (model := props.get(HOMEKIT_MODEL_LOWER) or props.get(HOMEKIT_MODEL_UPPER) and isinstance(model, str))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/zeroconf/discovery.py#L125
  140. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (flume_devices and flume_devices.device_list)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/flume/config_flow.py#L80
  141. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (notification.get('device_id') and notification.get('extra') and 'event_rule_name' in notification['extra'])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/flume/coordinator.py#L146
  142. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (isinstance(slot, int) and 0 <= slot <= 255)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/yalexs_ble/config_flow.py#L53
  143. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (validated_config.key == entry.data[CONF_KEY] and validated_config.slot == entry.data[CONF_SLOT])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/yalexs_ble/__init__.py#L105
  144. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (hasattr(self.config_entry, 'runtime_data') and self.config_entry.runtime_data)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/keenetic_ndms2/config_flow.py#L170
  145. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (os.path.isdir(model_dir) and os.path.isdir(checkpoint) and os.path.exists(pipeline_config) and os.path.exists(labels))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/tensorflow/image_processing.py#L143
  146. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (matching_item and matching_item.uid)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/todo/intent.py#L128
  147. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (supported_features and supported_features & desc.required_feature)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/todo/__init__.py#L113
  148. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entity_id := msg[CONF_ENTITY_ID] and entity := hass.data[DATA_COMPONENT].get_entity(entity_id) and isinstance(entity, TodoListEntity))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/todo/__init__.py#L386
  149. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entity.supported_features and entity.supported_features & TodoListEntityFeature.MOVE_TODO_ITEM)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/todo/__init__.py#L425
  150. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (found and found.uid)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/todo/__init__.py#L508
  151. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self._trip and self._trip.trip_id == trip_id)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/gtfs/sensor.py#L617
  152. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self._route and self._route.route_id == route_id)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/gtfs/sensor.py#L622
  153. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (key in self._attributes and self._attributes[key] == self._route.route_id)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/gtfs/sensor.py#L750
  154. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (key in self._attributes and self._attributes[key] == self._trip.trip_id)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/gtfs/sensor.py#L762
  155. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (state and state.state in self.options)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/input_select/__init__.py#L290
  156. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (LightSchema.CONF_INDIVIDUAL_COLORS in config and color in config[LightSchema.CONF_INDIVIDUAL_COLORS])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/knx/light.py#L97
  157. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (_rgbw and any(_rgbw))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/knx/light.py#L538
  158. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (_rgb and any(_rgb))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/knx/light.py#L544
  159. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (_conf and DOMAIN in _conf)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/knx/__init__.py#L110
  160. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (platform in self.data['entities'] and unique_id in self.data['entities'][platform])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/knx/storage/config_store.py#L138
  161. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (isinstance(res, dict) and RESULT in res and isinstance(json := res[RESULT], dict) and status := json.get(STATUS))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/iotty/coordinator.py#L106
  162. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entry and modem := entry.runtime_data.modem.token)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/netgear_lte/services.py#L58
  163. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (available and self.is_on)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/amcrest/camera.py#L182
  164. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (cloud_username and cloud_password and cloud_country)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/xiaomi_miio/config_flow.py#L78
  165. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (name and self.host and self.mac)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/xiaomi_miio/config_flow.py#L161
  166. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (cloud_username and cloud_password and cloud_country)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/xiaomi_miio/config_flow.py#L224
  167. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (hasattr(self._node, 'status_events') and hasattr(self._node, 'isy'))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/isy994/button.py#L118
  168. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (isy_conf and ISY_CONF_NAME in isy_conf and isy_conf[ISY_CONF_NAME])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/isy994/config_flow.py#L122
  169. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (status and status.protocol == PROTO_PROGRAM)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/isy994/helpers.py#L407
  170. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (actions and actions.protocol == PROTO_PROGRAM)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/isy994/helpers.py#L417
  171. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (_type in self._events and _device_id == self.device.device_id)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/point/binary_sensor.py#L108
  172. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (sensor_data[description.key] == 0 and device.api.type in {'RM4PRO', 'RM4MINI'})'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/broadlink/sensor.py#L120
  173. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (mime_type := asset.original_mime_type and mime_type.startswith(('image/', 'video/')))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/immich/media_source.py#L243
  174. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (params and light.is_on)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/light/__init__.py#L454
  175. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (state_on and params)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/light/__init__.py#L825
  176. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (isinstance(option, int) and 0 <= option < len(self._attr_options))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/sonos/select.py#L118
  177. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (container_ids and match := re.search('FV:2,(\d+)', container_ids))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/sonos/favorites.py#L75
  178. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (CONF_API_VERSION in entry.data and conf_api_version == supported_api_version)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/hue/migration.py#L61
  179. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (zigbee and zigbee.mac_address)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/hue/migration.py#L100
  180. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entity_id and entity_entry := entity_registry.async_get(entity_id))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/tuya/switch.py#L958
  181. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (new_config and DOMAIN in new_config)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/intent_script/__init__.py#L82
  182. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (vid == vid.upper() and pid == pid.upper() and serial_number == serial_number.lower() and manufacturer == manufacturer.lower() and description == description.lower())'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/usb/__init__.py#L112
  183. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (time_fired_ts and shared_data)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/usage_prediction/common_control.py#L128
  184. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (description.capability_ignore_list and any((all((capability in device.status[MAIN] for capability in capability_list)) for capability_list in description.capability_ignore_list)))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/smartthings/sensor.py#L1139
  185. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (capability in KEEP_CAPABILITY_QUIRK and KEEP_CAPABILITY_QUIRKcapability)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/smartthings/__init__.py#L552
  186. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (start_time and ((end_time or dt_util.utcnow()) - start_time).days > 1)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/recorder/util.py#L165
  187. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (end_time and end_time[0])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/recorder/util.py#L211
  188. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (start.minute == 0 and start.second == 0 and start.microsecond == 0)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/recorder/statistics.py#L2625
  189. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (metadata['source'] and metadata['source'] == DOMAIN)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/recorder/statistics.py#L2661
  190. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (metadata['source'] and metadata['source'] == domain)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/recorder/statistics.py#L2692
  191. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self.schema_version and self.schema_version == SCHEMA_VERSION)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/recorder/core.py#L1501
  192. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'old_metadata['mean_type'] == new_metadata['mean_type'] and old_metadata['has_sum'] == new_metadata['has_sum'] and old_metadata['name'] == new_metadata['name'] and old_metadata['unit_class'] == new_metadata['unit_class'] and old_metadata['unit_of_measurement'] == new_metadata['unit_of_measurement']'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/recorder/table_managers/statistics_meta.py#L217
  193. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (start == duplicate.start and metadata_id == duplicate.metadata_id)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/recorder/auto_repairs/statistics/duplicates.py#L102
  194. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (include_start_time_state and run_start_ts)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/recorder/history/__init__.py#L194
  195. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entity_id_to_metadata_id := instance.states_meta_manager.get_many(entity_ids, session, False) and possible_metadata_ids := extract_metadata_ids(entity_id_to_metadata_id))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/recorder/history/__init__.py#L253
  196. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (include_start_time_state and run_start_ts)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/recorder/history/__init__.py#L423
  197. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (isinstance(plant_info, dict) and 'data' in plant_info)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/growatt_server/config_flow.py#L205
  198. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (plant_info and 'data' in plant_info and plant_info['data'])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/growatt_server/__init__.py#L61
  199. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (isinstance(meter['serviceType'], str) and meter['serviceType'] in _SUPPORTED_METER_TYPES)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/duke_energy/coordinator.py#L83
  200. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self._manufacturer and self._manufacturer.lower().startswith('samsung'))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/samsungtv/config_flow.py#L448
  201. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (len(platform_split) >= 2 and platform_split[1] in TRIGGERS)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/samsungtv/trigger.py#L26
  202. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (entry.data.get(CONF_TOKEN) and entry.data.get(CONF_SESSION_ID))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/samsungtv/__init__.py#L121
  203. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (hasattr(platform, 'async_pre_backup') and hasattr(platform, 'async_post_backup'))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/backup/manager.py#L414
  204. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (password and backup.protected)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/backup/http.py#L85
  205. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (self._outdoor_temp_sensor and self._indoor_temp_sensor and self._indoor_humidity_sensor and self._calib_factor)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/mold_indicator/sensor.py#L190
  206. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (len(platform_split) >= 2 and platform_split[1] in TRIGGERS)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/lg_netcast/trigger.py#L26
  207. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (from_dt and to_dt)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/openuv/coordinator.py#L96
  208. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (cache and cache['username'] == self._client_id)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/evohome/storage.py#L81
  209. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (api_data and api_data.sensors and any(api_data.availability.values()))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/pvpc_hourly_pricing/coordinator.py#L64
  210. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (parsed and parsed.data.get('modelName') in SUPPORTED_MODEL_TYPES)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/switchbot/config_flow.py#L106
  211. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (last_state and ATTR_CURRENT_POSITION in last_state.attributes)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/switchbot/cover.py#L71
  212. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (last_state and ATTR_CURRENT_TILT_POSITION in last_state.attributes)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/switchbot/cover.py#L158
  213. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (last_state and ATTR_CURRENT_POSITION in last_state.attributes)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/switchbot/cover.py#L240
  214. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (NOTIFY_SERVICES in hass.data and integration_name in hass.data[NOTIFY_SERVICES])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/notify/legacy.py#L201
  215. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (state := hass.states.get(call.data[ATTR_ENTITY_ID]) and entity := er.async_get(hass).async_get(call.data[ATTR_ENTITY_ID]) and entity.config_entry_id)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/bring/services.py#L64
  216. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (SCRIPT_BREAKPOINT_HIT in hass.data.get(DATA_DISPATCHER, {}) and hass.data[DATA_DISPATCHER][SCRIPT_BREAKPOINT_HIT])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/trace/websocket_api.py#L150
  217. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (SCRIPT_BREAKPOINT_HIT in hass.data.get(DATA_DISPATCHER, {}) and hass.data[DATA_DISPATCHER][SCRIPT_BREAKPOINT_HIT])'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/trace/websocket_api.py#L239
  218. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (key in old_attributes and old_attributes[key] == value)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/websocket_api/messages.py#L243
  219. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (ready_future := self._ready_future and queue_size := len(self._message_queue))'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/websocket_api/http.py#L256
  220. consider-rewriting-conditional:
    Consider rewriting conditional expression to 'not (cur_id := msg.get('id') and type(cur_id) is int and cur_id >= 0 and type_ := msg.get('type') and type(type_) is str)'
    https://github.com/home-assistant/core/blob/76a0b2d61632151335452c3c7ffb94523e5f19c5/homeassistant/components/websocket_api/co...

This comment was truncated because GitHub allows only 65536 characters in a comment.

This comment was generated for commit 0f72f23

@Pierre-Sassoulas
Copy link
Member

De Morgans law is technically correct but even I had to lookup the name again.

Well, too bad, I thought "Stranger things" had popularized it (https://strangerthings.fandom.com/fr/wiki/D%C3%A9mogorgon)

The check itself is fairly opinionated. Just looking at the examples we can probably agree that they are overall an improvement but regardless I still feel like it's more of a suggestion than anything else.

Did you consider #10600 (comment) (raising only above a threshold of or-linked negations ? This would make the check a lot more reasonable imo)

Regarding simplifiable-double-negation I'm not sure it's actually a true simplification. One might argue that adding the brackets introduces a nesting which is more complex.

If we raise only on 3 or more negated or, what about 'simplify-multiple-negation' then ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement ✨ Improvement to a component Optional Checkers Related to a checked, disabled by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants