Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Add availability status to Modbus entities #31073
This change adds support for reporting availability of the Modbus platform. In the current state, if Modbus communication fails, sensors won't notify the state machine, and the UI is not updated. It is a problem because the user is not aware of an issue unless he checks for Home Assistant logs.
Support was added for all existing Modbus components and manually tested.
Type of change
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
The integration reached or maintains the following Integration Quality Scale:
I think this is a great addition. Polling of HA periodically crash my modbus TCP gateway. Would love to track the availability and do an automation with a ESP DC relay that trigger a power cycle.
I think the main thing to change is the syntax on catching multiple exception as required by pylint. Here is copied from http://pylint.pycqa.org/en/latest/technical_reference/features.html
@adamchengtkc technically I think that the first Exception is enough. I kept the rest just because it was in the original code. While I tested this, I noticed that the AttributeException is not always thrown, and the status is not reported to the state machine. For the time being, I will modify the code as you suggested.
However, with Modbus, there are more problems to solve. This one is just the most crucial for me. If the Modbus server goes down, Home Assistant log files grow very quickly. We're talking a few hundred kilobytes per second; if you have more Modbus hubs, they will grow even more. The
I adapted the code as advised by @balloob. Also, I added connectivity checks for Modbus writes - otherwise errors are not catched, and are extensively logged.
At the moment, Modbus still generates a lot of errors due to loss of connectivity, but at least it's not in these components, which log the unavailable status only once now.
I will deal with the extensive Modbus logging in a separate pull request.