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.ecobee.internal.dto.thermostat.summary;
15 import java.util.Arrays;
16 import java.util.List;
19 import java.util.stream.Collectors;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.ecobee.internal.dto.AbstractResponseDTO;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import com.google.gson.annotations.SerializedName;
30 * The {@link SummaryResponseDTO} contains the
32 * @author Mark Hilbush - Initial contribution
35 public class SummaryResponseDTO extends AbstractResponseDTO {
37 private final transient Logger logger = LoggerFactory.getLogger(SummaryResponseDTO.class);
40 * Number of thermostats listed in the Revision List.
42 public @Nullable Integer thermostatCount;
45 * The list of CSV revision values.
47 public @Nullable List<RevisionDTO> revisionList;
50 * The list of CSV status values.
52 @SerializedName("statusList")
53 public @Nullable List<RunningDTO> runningList;
55 public boolean hasChanged(@Nullable SummaryResponseDTO previousSummary) {
56 if (previousSummary == null) {
57 logger.debug("SummaryResponse: No previous summary");
61 boolean changed = false;
62 if (revisionHasChanged(previousSummary.revisionList)) {
65 if (runningHasChanged(previousSummary.runningList)) {
71 private boolean revisionHasChanged(@Nullable List<RevisionDTO> previousList) {
72 List<RevisionDTO> currentList = revisionList;
73 if (previousList == null || currentList == null) {
74 logger.debug("SummaryResponse: Previous and/or current revision list is null");
77 // Check to see if there are different thermostat Ids in current vs previous
78 Set<String> previousIds = previousList.stream().map(RevisionDTO::getId).collect(Collectors.toSet());
79 Set<String> currentIds = currentList.stream().map(RevisionDTO::getId).collect(Collectors.toSet());
80 if (!previousIds.equals(currentIds)) {
81 logger.debug("SummaryResponse: Thermostat id maps are different");
82 logger.trace(" : Curr: {}", Arrays.toString(currentIds.toArray()));
83 logger.trace(" : Prev: {}", Arrays.toString(previousIds.toArray()));
86 // Create a map of each thermostat id with its RevisionDTO object
87 Map<String, RevisionDTO> previousMap = previousList.stream()
88 .collect(Collectors.toMap(RevisionDTO::getId, RevisionDTO::getThis));
89 // Go through list of current RevisionDTOs to see if something has changed
90 for (RevisionDTO current : currentList) {
91 RevisionDTO previous = previousMap.get(current.getId());
92 if (current.hasChanged(previous)) {
93 logger.debug("SummaryResponse: Revisions has changed");
94 logger.trace(" : Curr: {}", current.toString());
95 logger.trace(" : Prev: {}", previous.toString());
102 private boolean runningHasChanged(@Nullable List<RunningDTO> previousList) {
103 List<RunningDTO> currentList = runningList;
104 if (previousList == null || currentList == null) {
105 logger.debug("SummaryResponse: Previous and/or current running list is null");
108 // Check to see if there are different thermostat Ids in current vs previous
109 Set<String> previousIds = previousList.stream().map(RunningDTO::getId).collect(Collectors.toSet());
110 Set<String> currentIds = currentList.stream().map(RunningDTO::getId).collect(Collectors.toSet());
111 if (!previousIds.equals(currentIds)) {
112 logger.debug("SummaryResponse: Thermostat id maps are different");
113 logger.trace(" : Curr: {}", Arrays.toString(currentIds.toArray()));
114 logger.trace(" : Prev: {}", Arrays.toString(previousIds.toArray()));
117 // Create a map of each thermostat id with its RunningDTO object
118 Map<String, RunningDTO> previousMap = previousList.stream()
119 .collect(Collectors.toMap(RunningDTO::getId, RunningDTO::getThis));
120 // Go through list of current RunningDTOs to see if something has changed
121 for (RunningDTO current : currentList) {
122 RunningDTO previous = previousMap.get(current.getId());
123 if (current.hasChanged(previous)) {
124 logger.debug("SummaryResponse: Running Equipment has changed");
125 logger.trace(" : Curr: {}", current.toString());
126 logger.trace(" : Prev: {}", previous.toString());