]> git.basschouten.com Git - openhab-addons.git/blob
eac147886c9df32a5164ba096456e3eb23b56cab
[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.netatmo.internal.handler.capability;
14
15 import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
16 import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
17
18 import java.util.List;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.netatmo.internal.api.dto.WebhookEvent;
22 import org.openhab.binding.netatmo.internal.handler.CommonInterface;
23 import org.openhab.binding.netatmo.internal.handler.channelhelper.ChannelHelper;
24 import org.openhab.binding.netatmo.internal.providers.NetatmoDescriptionProvider;
25 import org.openhab.core.thing.ChannelUID;
26 import org.openhab.core.thing.ThingUID;
27 import org.openhab.core.types.UnDefType;
28
29 /**
30  * {@link DoorbellCapability} give to handle Welcome Doorbell specifics
31  *
32  * @author GaĆ«l L'hopital - Initial contribution
33  *
34  */
35 @NonNullByDefault
36 public class DoorbellCapability extends CameraCapability {
37     private final ThingUID thingUid;
38
39     public DoorbellCapability(CommonInterface handler, NetatmoDescriptionProvider descriptionProvider,
40             List<ChannelHelper> channelHelpers) {
41         super(handler, descriptionProvider, channelHelpers);
42         thingUid = handler.getThing().getUID();
43     }
44
45     @Override
46     public void updateWebhookEvent(WebhookEvent event) {
47         super.updateWebhookEvent(event);
48
49         handler.updateState(new ChannelUID(thingUid, GROUP_SUB_EVENT, CHANNEL_EVENT_TYPE),
50                 toStringType(event.getEventType()));
51         handler.updateState(new ChannelUID(thingUid, GROUP_SUB_EVENT, CHANNEL_EVENT_TIME),
52                 toDateTimeType(event.getTime()));
53         handler.updateState(new ChannelUID(thingUid, GROUP_SUB_EVENT, CHANNEL_EVENT_SNAPSHOT),
54                 toRawType(event.getSnapshotUrl()));
55         handler.updateState(new ChannelUID(thingUid, GROUP_SUB_EVENT, CHANNEL_EVENT_SNAPSHOT_URL),
56                 toStringType(event.getSnapshotUrl()));
57         handler.updateState(new ChannelUID(thingUid, GROUP_SUB_EVENT, CHANNEL_EVENT_VIGNETTE),
58                 toRawType(event.getVignetteUrl()));
59         handler.updateState(new ChannelUID(thingUid, GROUP_SUB_EVENT, CHANNEL_EVENT_VIGNETTE_URL),
60                 toStringType(event.getVignetteUrl()));
61
62         String message = event.getName();
63         handler.updateState(new ChannelUID(thingUid, GROUP_SUB_EVENT, CHANNEL_EVENT_MESSAGE),
64                 message == null || message.isBlank() ? UnDefType.NULL : toStringType(message));
65     }
66 }