2 * Copyright (c) 2010-2021 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.somfytahoma.internal.handler;
15 import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.STATUS;
16 import static org.openhab.core.thing.Thing.PROPERTY_FIRMWARE_VERSION;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.somfytahoma.internal.model.SomfyTahomaStatus;
21 import org.openhab.core.library.types.StringType;
22 import org.openhab.core.thing.Channel;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.ThingStatus;
25 import org.openhab.core.thing.ThingStatusDetail;
28 * The {@link SomfyTahomaGatewayHandler} is responsible for handling commands,
29 * which are sent to one of the channels of the gateway thing.
31 * @author Ondrej Pecta - Initial contribution
34 public class SomfyTahomaGatewayHandler extends SomfyTahomaBaseThingHandler {
36 public SomfyTahomaGatewayHandler(Thing thing) {
41 public void initializeThing(@Nullable ThingStatus bridgeStatus) {
42 if (bridgeStatus != null) {
43 if (bridgeStatus == ThingStatus.ONLINE) {
46 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
49 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED);
54 public void refresh(String channel) {
55 String id = getGateWayId();
56 SomfyTahomaStatus status = getTahomaStatus(id);
57 String tahomaStatus = status.getStatus();
58 Channel ch = thing.getChannel(channel);
60 updateState(ch.getUID(), new StringType(tahomaStatus));
62 // update the firmware property
63 String fw = status.getProtocolVersion();
64 updateProperty(PROPERTY_FIRMWARE_VERSION, fw);
66 updateStatus("DISCONNECTED".equals(tahomaStatus) ? ThingStatus.OFFLINE : ThingStatus.ONLINE);
69 public String getGateWayId() {
70 return getThing().getConfiguration().get("id").toString();