]> git.basschouten.com Git - openhab-addons.git/blob
302631f849ba57562e40e1c16ea9613d5c9ffd01
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.somfytahoma.internal.handler;
14
15 import static org.openhab.core.thing.Thing.PROPERTY_FIRMWARE_VERSION;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.somfytahoma.internal.model.SomfyTahomaStatus;
19 import org.openhab.core.library.types.StringType;
20 import org.openhab.core.thing.Channel;
21 import org.openhab.core.thing.Thing;
22 import org.openhab.core.thing.ThingStatus;
23
24 /**
25  * The {@link SomfyTahomaGatewayHandler} is responsible for handling commands,
26  * which are sent to one of the channels of the gateway thing.
27  *
28  * @author Ondrej Pecta - Initial contribution
29  */
30 @NonNullByDefault
31 public class SomfyTahomaGatewayHandler extends SomfyTahomaBaseThingHandler {
32
33     public SomfyTahomaGatewayHandler(Thing thing) {
34         super(thing);
35     }
36
37     @Override
38     public void refresh(String channel) {
39         String id = getGateWayId();
40         SomfyTahomaStatus status = getTahomaStatus(id);
41         String tahomaStatus = status.getStatus();
42         Channel ch = thing.getChannel(channel);
43         if (ch != null) {
44             updateState(ch.getUID(), new StringType(tahomaStatus));
45         }
46         // update the firmware property
47         String fw = status.getProtocolVersion();
48         updateProperty(PROPERTY_FIRMWARE_VERSION, fw);
49
50         updateStatus("DISCONNECTED".equals(tahomaStatus) ? ThingStatus.OFFLINE : ThingStatus.ONLINE);
51     }
52
53     public String getGateWayId() {
54         return getThing().getConfiguration().get("id").toString();
55     }
56 }