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.netatmo.internal.handler.channelhelper;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.netatmo.internal.api.dto.Dashboard;
20 import org.openhab.binding.netatmo.internal.api.dto.Event;
21 import org.openhab.binding.netatmo.internal.api.dto.HomeEvent;
22 import org.openhab.binding.netatmo.internal.api.dto.NAObject;
23 import org.openhab.binding.netatmo.internal.api.dto.NAThing;
24 import org.openhab.core.config.core.Configuration;
25 import org.openhab.core.types.State;
28 * The {@link ChannelHelper} is the base class for all channel helpers.
30 * @author Gaƫl L'hopital - Initial contribution
34 public abstract class ChannelHelper {
35 private final Set<String> channelGroups;
37 private @Nullable NAObject data;
39 public ChannelHelper(Set<String> providedGroups) {
40 channelGroups = providedGroups;
43 public void setNewData(@Nullable NAObject data) {
47 public final @Nullable State getChannelState(String channelId, @Nullable String groupId, Configuration config) {
49 if (channelGroups.isEmpty() || (groupId != null && channelGroups.contains(groupId))) {
50 NAObject localData = data;
51 if (localData instanceof HomeEvent) {
52 result = internalGetHomeEvent(channelId, groupId, (HomeEvent) localData);
57 if (localData instanceof Event) {
58 result = internalGetEvent(channelId, (Event) localData);
63 if (localData instanceof NAThing) {
64 NAThing naThing = (NAThing) localData;
65 result = internalGetProperty(channelId, naThing, config);
69 Dashboard dashboard = naThing.getDashboardData();
70 if (dashboard != null) {
71 result = internalGetDashboard(channelId, dashboard);
77 if (localData instanceof NAObject) {
78 result = internalGetObject(channelId, localData);
83 result = internalGetOther(channelId);
88 protected @Nullable State internalGetObject(String channelId, NAObject localData) {
92 protected @Nullable State internalGetOther(String channelId) {
96 protected @Nullable State internalGetDashboard(String channelId, Dashboard dashboard) {
100 protected @Nullable State internalGetProperty(String channelId, NAThing naThing, Configuration config) {
104 protected @Nullable State internalGetEvent(String channelId, Event event) {
108 protected @Nullable State internalGetHomeEvent(String channelId, @Nullable String groupId, HomeEvent event) {