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.NAError;
20 import org.openhab.binding.netatmo.internal.api.dto.NAObject;
21 import org.openhab.binding.netatmo.internal.handler.CommonInterface;
22 import org.openhab.binding.netatmo.internal.handler.channelhelper.ChannelHelper;
23 import org.openhab.core.config.core.Configuration;
24 import org.openhab.core.thing.ChannelUID;
25 import org.openhab.core.types.State;
28 * {@link ChannelHelperCapability} give the capability to dispatch incoming data across the channel helpers.
29 * This capability is common to all things
31 * @author Gaƫl L'hopital - Initial contribution
35 public class ChannelHelperCapability extends Capability {
36 private final List<ChannelHelper> channelHelpers;
38 public ChannelHelperCapability(CommonInterface handler, List<ChannelHelper> channelHelpers) {
40 this.channelHelpers = channelHelpers;
44 public void afterNewData(@Nullable NAObject newData) {
45 super.afterNewData(newData);
46 channelHelpers.forEach(helper -> helper.setNewData(newData));
47 handler.getActiveChannels().forEach(channel -> {
48 ChannelUID channelUID = channel.getUID();
49 String channelID = channelUID.getIdWithoutGroup();
50 String groupId = channelUID.getGroupId();
51 Configuration channelConfig = channel.getConfiguration();
52 for (ChannelHelper helper : channelHelpers) {
53 State state = helper.getChannelState(channelID, groupId, channelConfig);
55 handler.updateState(channelUID, state);
63 protected void updateErrors(NAError error) {
64 if (error.getId().equals(handler.getId())) {
65 statusReason = "@text/%s".formatted(error.getCode().message);