Skip to content
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

[unifi] Fix online/blocked channels after client is disconnected #11451

Merged

Conversation

jlaur
Copy link
Contributor

@jlaur jlaur commented Oct 25, 2021

Fixes #7001

Signed-off-by: Jacob Laursen [email protected]

Fixes a problem with the online channel never being updated to OFF after client disconnects. This was most likely introduced by Uni-Fi Controller 5.12.35. The same problem impacted the blocked channel also in the way that unblocking was not possible.

This pull request replaces #11410 with a better approach. Previous PR would keep clients in the cache after they are no longer connected to the access point. This worked for the online channel, but broke the blocked channel as a blocked client would immediately be disconnected from AP, but kept in client cache. This resulted in blocked status going back to unblocked since this was last known status.

New approach chosen is to keep a map of cid (configured key) -> _id values. When _id is returned by controller for the first time, it's kept in this cache and preferred for subsequent lookups. When client disconnects, it can no longer be found in client cache by either _id nor cid. It can however still be found in insights cache by _id. This fixes the problem as the insights cache doesn't contain IP address since controller version 5.12.35 release in beginning of 2020.

Example

When online (other clients/insights removed):

2021-10-17 22:05:37.731 [DEBUG] [i.internal.api.model.UniFiController] - Found 16 UniFi Client(s): 
 - UniFiClient{id: '5f5a2cb946e0fb0015cb4a68', mac: 'xx:xx:xx:xx:1a:79', ip: '192.168.0.28', hostname: 'oneplus-8', alias: 'oneplus 8 jacob', wired: false, blocked: false, device: UniFiDevice{id: '5cc8962d46e0fb0016dc486c', mac: 'b4:fb:e4:ca:a2:6c', name: 'Skynet', model: 'U7NHD', site: UniFiSite{name: 'oc9023uo', desc: 'Skynet'}}}
2021-10-17 22:05:37.755 [DEBUG] [i.internal.api.model.UniFiController] - Found 19 UniFi Insights(s): 
 - UniFiClient{id: '5f5a2cb946e0fb0015cb4a68', mac: 'xx:xx:xx:xx:1a:79', ip: 'null', hostname: 'oneplus-8', alias: 'oneplus 8 jacob', wired: false, blocked: false, device: null}

After going offline:

2021-10-17 22:05:47.864 [DEBUG] [i.internal.api.model.UniFiController] - Found 15 UniFi Client(s): 
2021-10-17 22:05:47.885 [DEBUG] [i.internal.api.model.UniFiController] - Found 19 UniFi Insights(s): 
 - UniFiClient{id: '5f5a2cb946e0fb0015cb4a68', mac: 'xx:xx:xx:xx:1a:79', ip: 'null', hostname: 'oneplus-8', alias: 'oneplus 8 jacob', wired: false, blocked: false, device: null}

Fixes openhab#7001

Signed-off-by: Jacob Laursen <[email protected]>
@jlaur jlaur requested a review from mgbowman as a code owner October 25, 2021 21:09
@jlaur jlaur changed the title Fix online/blocked channels. [unifi] Fix online/blocked channels Oct 25, 2021
@jlaur jlaur changed the title [unifi] Fix online/blocked channels [unifi] Fix online channel update after client is disconnected Oct 25, 2021
@jlaur jlaur changed the title [unifi] Fix online channel update after client is disconnected [unifi] Fix online/blocked channels after client is disconnected Oct 25, 2021
@jlaur
Copy link
Contributor Author

jlaur commented Oct 25, 2021

Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kaikreuzer kaikreuzer merged commit 7ec833d into openhab:main Oct 27, 2021
@kaikreuzer kaikreuzer added the bug An unexpected problem or unintended behavior of an add-on label Oct 27, 2021
@kaikreuzer kaikreuzer added this to the 3.2 milestone Oct 27, 2021
dschoepel pushed a commit to dschoepel/openhab-addons that referenced this pull request Nov 9, 2021
Fixes openhab#7001

Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Dave J Schoepel <[email protected]>
NickWaterton pushed a commit to NickWaterton/openhab-addons that referenced this pull request Dec 30, 2021
Fixes openhab#7001

Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Nick Waterton <[email protected]>
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this pull request Jan 28, 2022
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this pull request May 5, 2022
@jlaur jlaur deleted the 7001-unifi-controller-compatibility-fix branch June 13, 2022 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[unifi] Online channel not working after upgrading UniFi Controller to 5.12.35
2 participants