]> git.basschouten.com Git - openhab-addons.git/blob
6f1f6f91efc8d45e778b8dc95027fe9a68e8ba08
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.ojelectronics.internal.services;
14
15 import java.util.List;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.ojelectronics.internal.ThermostatHandler;
19 import org.openhab.binding.ojelectronics.internal.models.Thermostat;
20 import org.openhab.binding.ojelectronics.internal.models.groups.GroupContent;
21 import org.openhab.core.thing.Thing;
22
23 /**
24  * Refreshes values of {@link ThermostatHandler}
25  *
26  * @author Christian Kittel - Initial Contribution
27  */
28 @NonNullByDefault
29 public class RefreshGroupContentService {
30
31     private final List<GroupContent> groupContentList;
32     private List<Thing> things;
33
34     /**
35      * Creates a new instance of {@link RefreshGroupContentService}
36      *
37      * @param groupContents {@link GroupContent}
38      * @param things Things
39      */
40     public RefreshGroupContentService(List<GroupContent> groupContents, List<Thing> things) {
41         this.groupContentList = groupContents;
42         this.things = things;
43     }
44
45     /**
46      * Handles the changes to all things.
47      */
48     public void handle() {
49         groupContentList.stream().flatMap(entry -> entry.thermostats.stream()).forEach(this::handleThermostat);
50     }
51
52     private void handleThermostat(Thermostat thermostat) {
53         things.stream().filter(thing -> thing.getHandler() instanceof ThermostatHandler)
54                 .map(thing -> (ThermostatHandler) thing.getHandler())
55                 .filter(thingHandler -> thingHandler.getSerialNumber().equals(thermostat.serialNumber))
56                 .forEach(thingHandler -> thingHandler.handleThermostatRefresh(thermostat));
57     }
58 }