]> git.basschouten.com Git - openhab-addons.git/blob
bba63f40473ce4376ffe7f0873f1432bae771ad6
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.ArrayList;
16 import java.util.List;
17 import java.util.stream.Collectors;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.ojelectronics.internal.ThermostatHandler;
21 import org.openhab.binding.ojelectronics.internal.models.groups.GroupContentModel;
22 import org.openhab.core.thing.Thing;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * Refreshes values of {@link ThermostatHandler}
28  *
29  * @author Christian Kittel - Initial Contribution
30  */
31 @NonNullByDefault
32 public class RefreshGroupContentService {
33
34     private final List<GroupContentModel> groupContentList;
35     private final Logger logger = LoggerFactory.getLogger(RefreshGroupContentService.class);
36     private List<Thing> things;
37
38     /**
39      * Creates a new instance of {@link RefreshGroupContentService}
40      *
41      * @param groupContents {@link GroupContentModel}
42      * @param things Things
43      */
44     public RefreshGroupContentService(List<GroupContentModel> groupContents, List<Thing> things) {
45         this.groupContentList = groupContents;
46         this.things = things;
47         if (this.things.isEmpty()) {
48             logger.warn("Bridge contains no thermostats.");
49         }
50     }
51
52     /**
53      * Handles the changes to all things.
54      */
55     public void handle() {
56         new RefreshThermostatsService(groupContentList.stream().flatMap(entry -> entry.thermostats.stream())
57                 .collect(Collectors.toCollection(ArrayList::new)), things).handle();
58     }
59 }