-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Modbus light integration #42120
Add Modbus light integration #42120
Conversation
@janiversen I tried to adapt your # Check state
state = hass.states.get(entity_id).state If you have a huch what's going on, please let me know. In this PR, I didn't include the tests to get this merged as soon as possible. The |
Seems light do not have a state, it must be called something else, It must be in your read code.I will take a look at your PR tomorrow |
It is possible. I will definitely take a look at it. However, I can add tests in another PR. At the moment, I don't want to create PR for Thanks, we'll talk tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All ok.
Seems light do have a state (you use state.state) so the change to the tests should be simple
I think the problem is in the way how we initialize the components. While the INFO:homeassistant.loader:Loaded light from homeassistant.components.light
INFO:homeassistant.loader:Loaded modbus from homeassistant.components.modbus From the log, I can see the light is initialized before Modbus. But it should be initialized inside Modbus. @janiversen in some PR you mentioned a way how to debug the async code. I'm not sure where it was. Can you tell once again please? Thanks! |
It does sound wrong that light is initialized before modbus (or there are one more thing I do not understand). It does sound like a configuration issue. I debug a lot, using Visual Code, it works like a charm setting a breakpoint and wait. It´s been a while however since I debugged runtime code. In order to keep things small I try to debug using the test module. |
Just thinking loud, since light is defined inside modbus, that way I locate the device might be wrong (look in conftest.py). |
Please make the test code available, and I will try to run it and see if I detect anything. |
I also think that we need to adapt the test code for loading the platform. OK, I will push the code. It's almost identical to the switch. |
The test code is available now. I took the latest test code for switch from PR #42604, and changed the switch component to light. |
The problem is in light.py line 35 “ if discovery_info is None:”. Discovery_info is None, and I do not have a lot of clues as to why, except if the platform is not loaded. |
Looking a bit closer and comparing with switch.py, it seems switch.py does: Maybe that is the change you need to make ? |
Exactly there's the problem. Loading a config through discovery_info is the recommended way now. It will never be None during entity initialization. But I have no clue how to load the entity from tests and pass discovery_info. After I start working on whole config refactor we talked about, tests will fail for the Switch too. Once I figure this out, tests should start working. First thing, I should find a way how to debug the code. I'll try VS Code as you suggested. |
That might be the problem, but I have been testing a while using: And I can see that you build the config wrong, you should use CONF_LIGHTS. I do not know how discovery_info is structured, can you print it to the log and let me see it, then I can tell you what to make different. As far as I know test do not (yet) support discovery_info, but let me do a little research. |
I think I have found out the differences, there are a lot of “test_config_flow*” that sets discovery_info and does a couple of other things. May I suggest a couple of things:
Then I will:
Sounds like a plan to you ? Btw I have nearly completed tests for writing (switch). |
Just ran the switch tests with this PR, and they works unchanged. |
For testing, you can consider the dict of I will check the
It is a plan. I'll prepare the changes tomorrow. |
@janiversen here's the output of OrderedDict([('name', 'hub1'), ('type', 'tcp'), ('host', '127.0.0.1'), ('port', 5020), ('lights', [OrderedDict([('name', 'Switch1'), ('slave', 1), ('coil', 1), ('scan_interval', 15.0), ('command_on', 1), ('verify_state', True), ('command_off', 0)])]), ('timeout', 3.0), ('delay', 0)]) For a reference, it is constructed out of this yaml: modbus:
- name: hub1
type: tcp
host: 127.0.0.1
port: 5020
lights:
- name: Switch1
slave: 1
coil: 1
I also removed the test. Now it's your turn :) |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just submitted #50089 because I saw that async_track_time_interval was called with self.hass, which is undefined.
I added the comments here, so you can add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Please add tests for the turn_on/turn_off service calls.
@vzahradnik test_init.py line 270: |
I will first debug the issue #50010. It has higher priority for me... Then I will look at your comments here. Thanks! |
@vzahradnik when you update, you will see that class modbusHub have changed, you now need to call async_pymodbus_call(.... CALL_TYPE*) see e.g. cover.py |
Thanks! |
Having talked with @vzahradnik today on discord, we have agreed that I bring this PR up to date, and solve the requests from Martin. I am still not sure if I can push to the branch (given that maintainers have permission to edit) or I have to make a new PR. |
Members can push to the branch as long as the PR is open and the author hasn't unchecked that permission. I normally use the vscode pull request extension to check out PRs. Makes it a breeze. |
Thanks, I am on my way to get that extension installed. |
@MartinHjelmare I have now update this PR as I promised, I have solved all your request. This version is basically 98% identical to switch, but very different on the UI. Later @vzahradnik will add more functionality. In theory I have approved this PR, but since I have worked on it that does not count (in my mind at least). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Congratulations. I think we need to have a look at the doc. because I have reworked the document structure. |
* Add Modbus Light and add unit tests * Update to original PR. * Review comments. * Review 2. Co-authored-by: jan Iversen <[email protected]>
Proposed change
This PR adds the Modbus Light entity, which is based on Modbus Switch. At the moment, it supports only the
turn_on()
andturn_off()
methods, but it can be extended.We've discussed this feature in PR #33551. Feel free to take a look for reference.
Type of change
Example entry for
configuration.yaml
:Additional information
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: