]> git.basschouten.com Git - openhab-addons.git/blob
1fc8cc543e0becf0493913ebb1ffa808bea41bd5
[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.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.miio.internal.basic.BasicChannelTypeProvider;
18 import org.openhab.binding.miio.internal.basic.MiIoDatabaseWatchService;
19 import org.openhab.binding.miio.internal.cloud.CloudConnector;
20 import org.openhab.core.i18n.LocaleProvider;
21 import org.openhab.core.i18n.TranslationProvider;
22 import org.openhab.core.thing.Bridge;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.binding.BaseThingHandler;
25 import org.openhab.core.thing.binding.BridgeHandler;
26 import org.openhab.core.thing.binding.ThingHandler;
27 import org.openhab.core.thing.binding.builder.BridgeBuilder;
28 import org.openhab.core.thing.type.ChannelTypeRegistry;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /**
33  * The {@link MiIoGatewayHandler} is responsible for handling commands, which are
34  * sent to one of the channels.
35  *
36  * @author Marcel Verpaalen - Initial contribution
37  */
38 @NonNullByDefault
39 public class MiIoGatewayHandler extends MiIoBasicHandler implements BridgeHandler {
40
41     private final Logger logger = LoggerFactory.getLogger(MiIoGatewayHandler.class);
42
43     public MiIoGatewayHandler(Bridge thing, MiIoDatabaseWatchService miIoDatabaseWatchService,
44             CloudConnector cloudConnector, ChannelTypeRegistry channelTypeRegistry,
45             BasicChannelTypeProvider basicChannelTypeProvider, TranslationProvider i18nProvider,
46             LocaleProvider localeProvider) {
47         super(thing, miIoDatabaseWatchService, cloudConnector, channelTypeRegistry, basicChannelTypeProvider,
48                 i18nProvider, localeProvider);
49     }
50
51     @Override
52     public Bridge getThing() {
53         return (Bridge) super.getThing();
54     }
55
56     /**
57      * Creates a bridge builder, which allows to modify the bridge. The method
58      * {@link BaseThingHandler#updateThing(Thing)} must be called to persist the changes.
59      *
60      * @return {@link BridgeBuilder} which builds an exact copy of the bridge
61      */
62     @Override
63     protected BridgeBuilder editThing() {
64         return BridgeBuilder.create(thing.getThingTypeUID(), thing.getUID()).withBridge(thing.getBridgeUID())
65                 .withChannels(thing.getChannels()).withConfiguration(thing.getConfiguration())
66                 .withLabel(thing.getLabel()).withLocation(thing.getLocation()).withProperties(thing.getProperties());
67     }
68
69     @Override
70     public void childHandlerInitialized(ThingHandler childHandler, Thing childThing) {
71         logger.debug("Child registered with gateway: {}  {} -> {} {}", childThing.getUID(), childThing.getLabel(),
72                 getThing().getUID(), getThing().getLabel());
73         childDevices.put(childThing, (MiIoLumiHandler) childHandler);
74     }
75
76     @Override
77     public void childHandlerDisposed(ThingHandler childHandler, Thing childThing) {
78         logger.debug("Child released from gateway: {}  {} -> {} {}", childThing.getUID(), childThing.getLabel(),
79                 getThing().getUID(), getThing().getLabel());
80         childDevices.remove(childThing);
81     }
82
83     public @Nullable BridgeHandler getHandler() {
84         return this;
85     }
86 }