2 * Copyright (c) 2010-2023 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;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Refreshes values of {@link ThermostatHandler}
28 * @author Christian Kittel - Initial Contribution
31 public class RefreshGroupContentService {
33 private final List<GroupContent> groupContentList;
34 private final Logger logger = LoggerFactory.getLogger(RefreshGroupContentService.class);
35 private List<Thing> things;
38 * Creates a new instance of {@link RefreshGroupContentService}
40 * @param groupContents {@link GroupContent}
41 * @param things Things
43 public RefreshGroupContentService(List<GroupContent> groupContents, List<Thing> things) {
44 this.groupContentList = groupContents;
46 if (this.things.isEmpty()) {
47 logger.warn("Bridge contains no thermostats.");
52 * Handles the changes to all things.
54 public void handle() {
55 groupContentList.stream().flatMap(entry -> entry.thermostats.stream()).forEach(this::handleThermostat);
58 private void handleThermostat(Thermostat thermostat) {
59 things.stream().filter(thing -> thing.getHandler() instanceof ThermostatHandler)
60 .map(thing -> (ThermostatHandler) thing.getHandler())
61 .filter(thingHandler -> thingHandler.getSerialNumber().equals(thermostat.serialNumber))
62 .forEach(thingHandler -> thingHandler.handleThermostatRefresh(thermostat));