Repository navigation
Keep the session when the bridge refuses a sensor subscription - #182
Merged
Merged
Conversation
Some bridges answer a second CnRpdoRequest for a sensor that is already subscribed on the session with NOT_ALLOWED, and keep the session. Since #155, any NOT_ALLOWED closed the connection, so the sensors that were still subscribing failed and most entities became unavailable. A NOT_ALLOWED on a CnRpdoRequest now only fails that request. A session that is really gone is still detected by the heartbeat and the next other request, which get NOT_ALLOWED too. register_sensor keeps a refused sensor, and doesn't subscribe again to a sensor that is already registered: it emits its latest value instead.
A second register_sensor for a sensor whose subscription was still waiting for the bridge returned at once. When that subscription then failed, the sensor was dropped and the second caller never got values. It now waits for the first subscription, and subscribes itself when that failed. Also document the duplicate subscription and the resumed session behaviour, and test OTHER_SESSION on a subscription and NOT_ALLOWED on an unsubscription.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Some bridges answer a second
CnRpdoRequestfor a sensor that is already subscribed on the session withNOT_ALLOWED. The session stays valid: other requests and the sensor values keep working (tested in michaelarnauts/home-assistant-comfoconnect#265). Since #155,_sendtreated everyNOT_ALLOWEDas a lost session and closed the connection. The sensors that were still subscribing then failed,register_sensordropped them, and most Home Assistant entities stayed unavailable.Changes in
ComfoConnect:_send: aNOT_ALLOWEDon aCnRpdoRequestonly fails that request, the connection stays open. Every other request, andOTHER_SESSION, still closes it. A session that is really gone (the case of Reconnect when the bridge drops our session without closing it #155) refuses every request, so the heartbeat or the next other request still notices it.register_sensor:NOT_ALLOWEDthe sensor is kept, with a debug log, and no exception is raised. Either the session already has the sensor (a duplicate, or a resumed session that kept the subscriptions of the previous one, as in "The bridge dropped our session" during setup, most entities fail to load (works on 0.3.0) #181), or the session is gone and the next session subscribes to it again. Other errors still drop the sensor and raise, like before._start_session: aNOT_ALLOWEDwhen subscribing to the sensors again after a reconnect is logged at debug instead of as a warning. A resumed session refuses every sensor it still has, which gave a warning per sensor on every reconnect.docs/PROTOCOL.mdnow describes the duplicate subscription, when a LAN C resumes a session, and the exception forCnRpdoRequestType.Not covered: on a resumed session, the bridge pushes the current values before we register the sensors, and those are ignored. Such a sensor gets its first value on its next change.
Fixes #181.
Testing
test_refused_subscription_keeps_session: a subscription refused withNOT_ALLOWEDkeeps the session and the sensor, and its values still reach the callback.test_lost_session_refused_subscription: on a lost session, the refused subscription keeps the sensor and the connection, then the heartbeat reconnects and the new session subscribes to it.test_register_sensor_twice: one subscription, and the second registration gets the latest value at once.test_register_sensor_twice_without_value: a second registration during the hold doesn't restart the hold or emit anything, and the value comes once.test_refused_resubscription_after_reconnect: a refused subscription after a reconnect keeps the sensor and logs no warning.test_register_same_sensor_concurrently,..._first_failsandtest_cancelled_registration_while_waiting: a second registration during the first subscription waits for it and sends nothing, subscribes itself when the first one failed, and can be cancelled without affecting the first one.OTHER_SESSIONon a subscription still starts a new session, andNOT_ALLOWEDon an unsubscription keeps the session.pytest(408 passed),pylint10/10,black --check aiocomfoconnect/*.py.NOT_ALLOWED: the sensor was kept and the connection stayed open. The heartbeat gotNOT_ALLOWEDtoo and reconnected, and the new session subscribed to both sensors and received their values.