Only subscribe to state changes for added controls (#2864)

- Instead of receiving all state changes when the device controls are open, only receive state changes for entities that were added as controls. This potentially reduces the amount of data used while controls are open.
This commit is contained in:
Joris Pelgröm 2022-09-10 21:17:49 +02:00 committed by GitHub
parent 69beab3a2a
commit a31afb3455
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -168,18 +168,16 @@ class HaControlsProviderService : ControlsProviderService() {
// Listen for the state changed events.
webSocketScope.launch {
integrationRepository.getEntityUpdates()?.collect {
if (controlIds.contains(it.entityId)) {
val control = domainToHaControl[it.domain]?.createControl(
applicationContext,
it as Entity<Map<String, Any>>,
RegistriesDataHandler.getAreaForEntity(it.entityId, areaRegistry, deviceRegistry, entityRegistry),
entityRequiresAuth(it.entityId),
baseUrl
)
if (control != null)
subscriber.onNext(control)
}
integrationRepository.getEntityUpdates(controlIds)?.collect {
val control = domainToHaControl[it.domain]?.createControl(
applicationContext,
it as Entity<Map<String, Any>>,
RegistriesDataHandler.getAreaForEntity(it.entityId, areaRegistry, deviceRegistry, entityRegistry),
entityRequiresAuth(it.entityId),
baseUrl
)
if (control != null)
subscriber.onNext(control)
}
}
webSocketScope.launch {