2 * Copyright (c) 2010-2023 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.miio.internal.handler;
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;
33 * The {@link MiIoGatewayHandler} is responsible for handling commands, which are
34 * sent to one of the channels.
36 * @author Marcel Verpaalen - Initial contribution
39 public class MiIoGatewayHandler extends MiIoBasicHandler implements BridgeHandler {
41 private final Logger logger = LoggerFactory.getLogger(MiIoGatewayHandler.class);
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);
52 public Bridge getThing() {
53 return (Bridge) super.getThing();
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.
60 * @return {@link BridgeBuilder} which builds an exact copy of the bridge
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());
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);
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);
83 public @Nullable BridgeHandler getHandler() {