Extend Modbus binary sensor to support discrete inputs#30004
Conversation
|
Hi @vzahradnik, It seems you haven't yet signed a CLA. Please do so here. Once you do that we will be able to review and accept this pull request. Thanks! |
|
Hey there @adamchengtkc, mind taking a look at this pull request as its been labeled with a integration ( |
|
A duplicate of #27397 ? |
|
I see in #27397 they try to keep the compatibility and to introduce optional parameter discrete_inputs are not coils and both of them are not registers according to the Modbus terminology. Anyway, I will respect your decision what should be adopted. Thanks! |
|
I don't have a device that require setting discrete_input and I don't have a preference on either approach. Perhaps it would be good if you can reference this PR and raise this with the author of #27397 ? |
|
Sure, I will leave a comment there. Thanks! |
|
See #27397 (comment) for the question. |
|
How can I implement the above configuration in HA? |
|
Hi @tkaczu2, this change is not yet merged so there is no official way how to do that. Home Assistant supports loading custom components: You can copy existing components there, like whole Modbus folder, and Home Assistant will override default implementation with this custom one. Not recommended approach, but it works. If you have your custom Modbus folder (i.e. As a last step, configure your Modbus entry according to my proposed config above. The only major change is that You can also check PR #27397, which does the same thing, however the config syntax is backwards compatible. Pick up what works best for you. |
|
I updated the implementation to be backward compatible as suggested by @balloob in #27397. Change was manually tested and works with different configurations without any issue. Also, I created another PR, home-assistant/home-assistant.io#12036, to update documentation for this change. Here's an output from my log: 2020-02-10 17:56:16 WARNING (MainThread) [homeassistant.components.modbus.binary_sensor] The 'coils' option (with value '[OrderedDict([('name', 'plc_01_s8a'), ('hub', 'plc_01'), ('slave', 1), ('coil', 0)]), OrderedDict([('name', 'plc_01_s8b'), ('hub', 'plc_01'), ('slave', 1), ('address', 1)]), OrderedDict([('name', 'plc_01_s8c'), ('hub', 'plc_01'), ('slave', 1), ('coil', 2)])]') is deprecated, please replace it with 'inputs'
2020-02-10 17:56:16 WARNING (MainThread) [homeassistant.components.modbus.binary_sensor] The 'coil' option (with value '0') is deprecated, please replace it with 'address'
2020-02-10 17:56:16 WARNING (MainThread) [homeassistant.components.modbus.binary_sensor] The 'coil' option (with value '2') is deprecated, please replace it with 'address' |
|
|
||
| def read_discrete_inputs(self, unit, address, count): | ||
| """Read discrete inputs.""" | ||
| with self._lock: |
There was a problem hiding this comment.
We normally don't want sync locks in our thread pool. We shouldn't address this in this PR, but it would be something to improve for the future.
It would be ok to replace the sync lock with an asyncio lock. That would require changing the context around the affected methods from sync to async.
There was a problem hiding this comment.
Maybe I will take a look at it someday. I try to rework Modbus one step at a time. It's not the most perfect integration, but it gets better.
Breaking Change:
Backward compatibility was added to accept old configs and warn users in the logs.
Description:
This PR extends Modbus Binary Sensor to also read data from discrete inputs. New variable input_type was added to define if user wants to read from coil or discrete_input. Coil is the default option.
Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#12036
Example entry for
configuration.yaml:Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed: