Allow discovery configuration of modbus platforms#46591
Allow discovery configuration of modbus platforms#46591MartinHjelmare merged 28 commits intohome-assistant:devfrom janiversen:test_new_config
Conversation
|
Hey there @adamchengtkc, @vzahradnik, mind taking a look at this pull request as its been labeled with an integration ( |
|
@vzahradnik I closed the other PR, because it had label "breaking change", and I modified the commits to make sure it is not a breaking change. Please have a look at this (look in new_config.txt for explanation of the changes). Once you approve the PR, I will add a PR to update the documentation. |
vzahradnik
left a comment
There was a problem hiding this comment.
@janiversen good job! I found one small issue in the new_config.txt. It's an easy fix.
|
Documentation PR added (#16678) so now it is ready to be merged. |
|
@janiversen looks like your Documentation PR link pointing to a wrong repo. This is the correct one. |
|
It was not wrong, I just only added the # number and not the full link. However I have updated it to the full link. |
|
Updated to newest dev, no real changes. This PR is ready to be merged. |
|
Updated PR due to changes in dev. These last changes are needed to pass the checks! The last commit was due to coverage failure, and instead of disabling coverage I added new tests. @MartinHjelmare you motivated me to change the configuration to the new style, and your review comments are very useful (not only to make the integration better, but also for me to learn more about the internals of HA). So please when you have time, please let me hear what should be changed in order to get this merged, thanks in advance. We have a bunch of open issues and other PR´s depending on this PR (because we are not allowed to change the old config). |
|
@janiversen I just noticed one thing: Modbus Cover and Climate disable polling by the platform: @property
def should_poll(self):
"""Return True if entity has to be polled for state.
False if entity pushes its state to HA.
"""
# Handle polling directly in this entity
return FalseAnd handle the update by themselves: async def async_added_to_hass(self):
"""Handle entity which will be added."""
async_track_time_interval(
self.hass, lambda arg: self._update(), self._scan_interval
)I stuck to this issue while rebasing the LIGHT against this PR. |
|
@vzahradnik good catch, I wonder why my production system works without the should_poll property...anyhow I will add this to all platforms. |
|
@janiversen also add the call |
|
@janiversen the This is the reason, I set polling to False and set up a code to handle polling by itself. It was implemented for |
|
@janiversen when I look at the current code of I can prepare a PR against your branch with required changes. Please let me know if you agree. |
|
@janiversen I confirmed that the scan_interval doesn't work in this setup. Binary sensor ignores the value and defaults to 30 seconds. For now, I made a fix for the binary sensor, later today I will fix the rest. My changes are made against this PR, I will create a PR to your branch. |
|
@vzahradnik There must be a way we can tell core which scan_interval we want to use, it does not sound logical that all platforms need to implement their own timers. I will take a look at the polling code and look for a function to call. I looked at the "old" code that allowed scan_interval to be defined e.g. at sensor level (not for each single sensor), but I cannot see how the configured scan_interval is passed on to core. No need to create a PR, I will copy your branch. |
|
While I implemented this, I looked at other integrations. So far I didn't find a better way. Anyway, I will prepare the change to at least make it work again. If you find a better way, perhaps we could implement this in a separate PR because this is the way how cover and climate work, too. |
|
@janiversen I'm not able to create a PR against your branch. All the changes are implemented here as 3 separate commits: Feel free to take a look and you can also pull from there. If you find a better solution, I am open to that. These commits at least fix the current behavior, which is broken with your change. |
|
Thanks a lot for helping out. I will amend your changes to this PR later this evening. I wish we had seen this problem a bit earlier, but luckily you found it (and corrected it) before the PR was merged. We might be able to find a better solution, but that is for another PR later....right now I am eager to submit a bunch of PRs to close most of the open issues (but they all depend on this PR). |
|
@janiversen and my plan is to finally get Light and Fan merged. I will prepare two very simple PRs to get them reviewed quickly. I remember others suggested some improvements to my Fan code, but I can work on that on another PRs... All these changes depend on this PR, so let's hope it gets merged soon. |
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
|
@MartinHjelmare I should have addressed all your suggestion (accepted or implemented all). Please let me know if you have further comments. |
|
Rebased to newest dev. |
|
I believe that build error is not caused by my changes, but a fluke. Force pushed to see if the error occurs again. |
|
Please add a breaking change paragraph to the PR description that we can copy to the release notes. Briefly describe the deprecation and what users can do to cope with the change. |
|
Updated PR, hope you like the text, otherwise feel free to change it. |
|
Can we add an example of the old style vs the new style of configuration YAML? Then it will be super clear. |
|
Of course, updated PR with example. |
|
I don't see the examples in the PR description. |
|
hrmffff pressing "update comment" absolutely helps !! my error. It is visible now. |
|
Great! |
Breaking change
Users can now use the new style configuration when configuring the modbus integration. The existing configuration style is kept, allowing users to change gradually.
Remark the existing configuration style will be removed in a couple of releases.
Example existing configuration:
Same configuration in new style:
Proposed change
Added possibility to do:
modbus:
binary_sensors: []
sensors: []
switches: []
REMARK the old configuration style is still supported, but will be removed at a later point release, therefore this is not
a breaking change.
Type of change
Example entry for
configuration.yaml:# Example configuration.yamlAdditional information
home-assistant/home-assistant.io#16678
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: