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