2 * Copyright (c) 2010-2024 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;
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.List;
18 import java.util.concurrent.ScheduledExecutorService;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.netatmo.internal.handler.capability.CapabilityMap;
23 import org.openhab.core.thing.Bridge;
24 import org.openhab.core.thing.ChannelUID;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.ThingStatus;
27 import org.openhab.core.thing.ThingStatusDetail;
28 import org.openhab.core.thing.ThingStatusInfo;
29 import org.openhab.core.thing.binding.BaseThingHandler;
30 import org.openhab.core.thing.binding.ThingHandlerService;
31 import org.openhab.core.thing.binding.builder.ThingBuilder;
32 import org.openhab.core.types.Command;
33 import org.openhab.core.types.State;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * {@link ModuleHandler} is the base class for all Netatmo things
40 * @author Gaƫl L'hopital - Initial contribution
44 public class ModuleHandler extends BaseThingHandler implements CommonInterface {
45 private final Logger logger = LoggerFactory.getLogger(ModuleHandler.class);
46 private CapabilityMap capabilities = new CapabilityMap();
48 public ModuleHandler(Thing thing) {
53 public void initialize() {
54 logger.debug("Initializing handler for thing {}", getThing().getUID());
59 public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
60 logger.debug("bridgeStatusChanged for thing {} to {}", getThing().getUID(), bridgeStatusInfo);
65 public void dispose() {
71 public void handleCommand(ChannelUID channelUID, Command command) {
72 commonHandleCommand(channelUID, command);
76 public void setThingStatus(ThingStatus thingStatus, ThingStatusDetail thingStatusDetail,
77 @Nullable String thingStatusReason) {
78 updateStatus(thingStatus, thingStatusDetail, thingStatusReason);
82 public CapabilityMap getCapabilities() {
87 public ThingBuilder editThing() {
88 return super.editThing();
92 public void updateThing(Thing thing) {
93 super.updateThing(thing);
97 public void updateState(ChannelUID channelUID, State state) {
98 super.updateState(channelUID, state);
102 public boolean isLinked(ChannelUID channelUID) {
103 return super.isLinked(channelUID);
107 public @Nullable Bridge getBridge() {
108 return super.getBridge();
112 public void triggerChannel(String channelID, String event) {
113 super.triggerChannel(channelID, event);
117 public Collection<Class<? extends ThingHandlerService>> getServices() {
118 List<Class<? extends ThingHandlerService>> result = new ArrayList<>();
119 capabilities.values().forEach(cap -> result.addAll(cap.getServices()));
124 public Logger getLogger() {
129 public ScheduledExecutorService getScheduler() {