Skip to content

Issue warning modbus configuration when modbus configuration is empty#112618

Merged
janiversen merged 4 commits into
home-assistant:devfrom
janiversen:no_entity
Mar 9, 2024
Merged

Issue warning modbus configuration when modbus configuration is empty#112618
janiversen merged 4 commits into
home-assistant:devfrom
janiversen:no_entity

Conversation

@janiversen
Copy link
Copy Markdown
Member

Breaking change

Proposed change

The minimum_scan_interval was controlled pr entity type, leading to timeout = -1 when no entities was defined.
this PR calculates the minimum_scan_interval across all entity types and still sets timeout = -1 when no entities is defined.

Seems from HA core POW, it does not makes sense to have modbus defined without any entities and may cause problems (e.g. most devices terminate the connection after a while without communication, but the reconnect logic depend on the entity update method).

This PR issues a warning when modbus is configured without entities. Some custom components use this configuration to add their own configuration (HIGHLY NOT RECOMMENDED) so currently we issue only a warning.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@janiversen janiversen changed the title Issue modbus configuration when modbus configuration is empty Issue warning modbus configuration when modbus configuration is empty Mar 7, 2024
@janiversen janiversen added this to the 2024.3.1 milestone Mar 7, 2024
@janiversen
Copy link
Copy Markdown
Member Author

please see review discussion with @joostlek in #112618, sorry for the confusion (a checkout branch mistake).

@joostlek
Copy link
Copy Markdown
Member

joostlek commented Mar 7, 2024

That's the same PR

@janiversen
Copy link
Copy Markdown
Member Author

it is clearly not my day, I am out of coffee !!

It should have said #112619

@janiversen janiversen requested a review from joostlek March 7, 2024 16:36
@janiversen
Copy link
Copy Markdown
Member Author

@joostlek do you want more changes or explanations?

entity_inx += 1

if no_entities:
err = f"Modbus {hub[CONF_NAME]} is instable without entities, please add entities!"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
err = f"Modbus {hub[CONF_NAME]} is instable without entities, please add entities!"
err = f"Modbus {hub[CONF_NAME]} is unstable without entities, please add entities!"

Comment on lines +394 to +397
err = f"Modbus {hub[CONF_NAME]} is instable without entities, please add entities!"
_LOGGER.warning(err)
# Ensure timeout is not started/handled.
hub[CONF_TIMEOUT] = -1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So for whom would this log message be? Because if someone adds this to support a custom integration, the message to "please add entities!" doesn't really make sense, since the custom integration is doing this for them.

In what way will it be unstable?

Maybe sentences like:

"There are no entities defined for {something}. Ignoring timeout."
"There are no entities defined for {something}. This can lead to modbus updating less predictable."

Copy link
Copy Markdown
Member Author

@janiversen janiversen Mar 8, 2024

Choose a reason for hiding this comment

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

The text is for the end-user who uses the integration, and even if the custom integration adds entities, we have no idea how (and do not want to know), so we have no way of knowing if the integration continues to be unstable.

The only valid option is to add at least one entity (some custom components are now, finally, starting to recommend that).

I have tried to adjust the text along your suggestion. WDYT ?

@janiversen janiversen requested a review from joostlek March 8, 2024 16:01
@janiversen janiversen merged commit 693f72e into home-assistant:dev Mar 9, 2024
@janiversen janiversen deleted the no_entity branch March 9, 2024 07:49
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants