Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added availability topic in HA as V1 devices report state every 4 hours at most, and V2 devices report every 2 hours at most. Added a state file that gets saved on shutdown and sensor reload. This file saves the last seen timestamp and online state for each sensor so that it has consistancy across reboots. This file also contains the shutdown timestamp so that we can ignore stale state data in case the service is shut down for a long time, or if the service crashes and a fresh state file is not written. If the state data is stale, the service will just start fresh assuming all devices are online. Added timeout setting for sensors to configure a timeout per device if desired. Otherwise it'll default to 4 hours for V2 devices and 8 hours for V1 and unknown devices. This is twice the max status period to allow for one missed status update. Also added a global availability topic that is set online when the service is running. Both the global availability and the per device availability must be set to online for a device to be available. Switched mqtt connection method so it connects faster and availability topics are sent after the connection is active rather than before. This also allows the main thread to loop and check availability of the sensors. The main loop also checks communication with the dongle, by getting the mac address, which allows us to close and reopen the dongle if we lose communication with the device. This is an issue I've been dealing with for a long time. Fixed shutdown by sending the correct signal in the service file and properly handling it in shutdown. Wait for dongle loop to finish before closing the fd. Updated logging. Set the sample logging conf to INFO instead of DEBUG and updated log messages to primarily log mqtt messages/events, etc at this level. Passing in LOGGER to the dongle class so logs from the dongle show up in the log file. Fix packet parsing to not throw away partial packets which can be parsed correctly when the rest of the message is received. Fix new device scan to add the device even if the additional calls timeout, as long as we got a result from the scan. Fix automatic device adding for already linked devices to default the class to opening instead of None. This means even motion sensors will be initially added as a contact sensor, but should get fixed when the sensors.yaml configuration is updated. Signed-off-by: Nathan Bahr <[email protected]>
- Loading branch information