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.capability;
15 import java.util.List;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.netatmo.internal.api.dto.NAObject;
20 import org.openhab.binding.netatmo.internal.handler.CommonInterface;
21 import org.openhab.binding.netatmo.internal.handler.channelhelper.ChannelHelper;
22 import org.openhab.core.config.core.Configuration;
23 import org.openhab.core.thing.ChannelUID;
24 import org.openhab.core.types.State;
27 * {@link ChannelHelperCapability} give the capability to dispatch incoming data across the channel helpers.
29 * @author Gaƫl L'hopital - Initial contribution
33 public class ChannelHelperCapability extends Capability {
34 private final List<ChannelHelper> channelHelpers;
36 public ChannelHelperCapability(CommonInterface handler, List<ChannelHelper> channelHelpers) {
38 this.channelHelpers = channelHelpers;
42 public void afterNewData(@Nullable NAObject newData) {
43 super.afterNewData(newData);
44 channelHelpers.forEach(helper -> helper.setNewData(newData));
45 handler.getActiveChannels().forEach(channel -> {
46 ChannelUID channelUID = channel.getUID();
47 String channelID = channelUID.getIdWithoutGroup();
48 String groupId = channelUID.getGroupId();
49 Configuration channelConfig = channel.getConfiguration();
50 for (ChannelHelper helper : channelHelpers) {
51 State state = helper.getChannelState(channelID, groupId, channelConfig);
53 handler.updateState(channelUID, state);