@@ -635,46 +635,53 @@ public void initialize() {
635
635
* @param resource a Resource object containing the new state.
636
636
*/
637
637
public void onResource (Resource resource ) {
638
- if (!disposing ) {
639
- boolean resourceConsumed = false ;
640
- String incomingResourceId = resource .getId ();
641
- if (resourceId .equals (incomingResourceId )) {
642
- if (resource .hasFullState ()) {
643
- thisResource = resource ;
644
- if (!updatePropertiesDone ) {
645
- updateProperties (resource );
646
- resourceConsumed = updatePropertiesDone ;
647
- }
648
- }
649
- if (!updateDependenciesDone ) {
650
- resourceConsumed = true ;
651
- cancelTask (updateDependenciesTask , false );
652
- updateDependenciesTask = scheduler .submit (() -> updateDependencies ());
653
- }
654
- } else if (SUPPORTED_SCENE_TYPES .contains (resource .getType ())) {
655
- Resource cachedScene = sceneContributorsCache .get (incomingResourceId );
656
- if (Objects .nonNull (cachedScene )) {
657
- Setters .setResource (resource , cachedScene );
658
- resourceConsumed = updateChannels (resource );
659
- sceneContributorsCache .put (incomingResourceId , resource );
660
- }
661
- } else {
662
- Resource cachedService = serviceContributorsCache .get (incomingResourceId );
663
- if (Objects .nonNull (cachedService )) {
664
- Setters .setResource (resource , cachedService );
665
- resourceConsumed = updateChannels (resource );
666
- serviceContributorsCache .put (incomingResourceId , resource );
667
- if (ResourceType .LIGHT == resource .getType () && !updateLightPropertiesDone ) {
668
- updateLightProperties (resource );
669
- }
638
+ if (disposing ) {
639
+ return ;
640
+ }
641
+ boolean resourceConsumed = false ;
642
+ if (resourceId .equals (resource .getId ())) {
643
+ if (resource .hasFullState ()) {
644
+ thisResource = resource ;
645
+ if (!updatePropertiesDone ) {
646
+ updateProperties (resource );
647
+ resourceConsumed = updatePropertiesDone ;
670
648
}
671
649
}
672
- if (resourceConsumed ) {
673
- logger .debug ("{} -> onResource() consumed resource {}" , resourceId , resource );
650
+ if (!updateDependenciesDone ) {
651
+ resourceConsumed = true ;
652
+ cancelTask (updateDependenciesTask , false );
653
+ updateDependenciesTask = scheduler .submit (() -> updateDependencies ());
674
654
}
655
+ } else {
656
+ Resource cachedResource = getResourceFromCache (resource );
657
+ if (cachedResource != null ) {
658
+ Setters .setResource (resource , cachedResource );
659
+ resourceConsumed = updateChannels (resource );
660
+ putResourceToCache (resource );
661
+ if (ResourceType .LIGHT == resource .getType () && !updateLightPropertiesDone ) {
662
+ updateLightProperties (resource );
663
+ }
664
+ }
665
+ }
666
+ if (resourceConsumed ) {
667
+ logger .debug ("{} -> onResource() consumed resource {}" , resourceId , resource );
668
+ }
669
+ }
670
+
671
+ private void putResourceToCache (Resource resource ) {
672
+ if (SUPPORTED_SCENE_TYPES .contains (resource .getType ())) {
673
+ sceneContributorsCache .put (resource .getId (), resource );
674
+ } else {
675
+ serviceContributorsCache .put (resource .getId (), resource );
675
676
}
676
677
}
677
678
679
+ private @ Nullable Resource getResourceFromCache (Resource resource ) {
680
+ return SUPPORTED_SCENE_TYPES .contains (resource .getType ()) //
681
+ ? sceneContributorsCache .get (resource .getId ())
682
+ : serviceContributorsCache .get (resource .getId ());
683
+ }
684
+
678
685
/**
679
686
* Update the thing internal state depending on a full list of resources sent from the bridge. If the resourceType
680
687
* is SCENE then call updateScenes(), otherwise if the resource refers to this thing, consume it via onResource() as
0 commit comments