]> git.basschouten.com Git - openhab-addons.git/blob
233adbd1df18c38319ed4651937271dff90f900f
[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.miio.internal.handler;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.miio.internal.basic.MiIoDatabaseWatchService;
17 import org.openhab.binding.miio.internal.cloud.CloudConnector;
18 import org.openhab.core.thing.ChannelUID;
19 import org.openhab.core.thing.Thing;
20 import org.openhab.core.types.Command;
21 import org.openhab.core.types.RefreshType;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * The {@link MiIoGenericHandler} is responsible for handling commands for devices that are not yet defined.
27  * Once the device has been determined, the proper handler is loaded.
28  *
29  * @author Marcel Verpaalen - Initial contribution
30  */
31 @NonNullByDefault
32 public class MiIoGenericHandler extends MiIoAbstractHandler {
33     private final Logger logger = LoggerFactory.getLogger(MiIoGenericHandler.class);
34
35     public MiIoGenericHandler(Thing thing, MiIoDatabaseWatchService miIoDatabaseWatchService,
36             CloudConnector cloudConnector) {
37         super(thing, miIoDatabaseWatchService, cloudConnector);
38     }
39
40     @Override
41     public void handleCommand(ChannelUID channelUID, Command command) {
42         if (command == RefreshType.REFRESH) {
43             logger.debug("Refreshing {}", channelUID);
44             updateData();
45             return;
46         }
47         if (handleCommandsChannels(channelUID, command)) {
48             return;
49         }
50     }
51
52     @Override
53     protected synchronized void updateData() {
54         if (skipUpdate()) {
55             return;
56         }
57         logger.debug("Periodic update for '{}' ({})", getThing().getUID().toString(), getThing().getThingTypeUID());
58         try {
59             refreshNetwork();
60         } catch (Exception e) {
61             logger.debug("Error while updating '{}'", getThing().getUID().toString(), e);
62         }
63     }
64 }