2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.ojelectronics.internal.services;
15 import java.util.List;
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;
24 * Refreshes values of {@link ThermostatHandler}
26 * @author Christian Kittel - Initial Contribution
29 public class RefreshGroupContentService {
31 private final List<GroupContent> groupContentList;
32 private List<Thing> things;
35 * Creates a new instance of {@link RefreshGroupContentService}
37 * @param groupContents {@link GroupContent}
38 * @param things Things
40 public RefreshGroupContentService(List<GroupContent> groupContents, List<Thing> things) {
41 this.groupContentList = groupContents;
46 * Handles the changes to all things.
48 public void handle() {
49 groupContentList.stream().flatMap(entry -> entry.thermostats.stream()).forEach(this::handleThermostat);
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));