]> git.basschouten.com Git - openhab-addons.git/blob
f024fc78cdf069b977458bf8fbc7c0f6060f5c7f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.channelhelper;
14
15 import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
16 import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.netatmo.internal.api.dto.HomeEvent;
21 import org.openhab.core.library.types.DateTimeType;
22 import org.openhab.core.types.State;
23
24 /**
25  * The {@link EventDoorbellChannelHelper} handles specific channels of doorbell events
26  *
27  * @author GaĆ«l L'hopital - Initial contribution
28  *
29  */
30 @NonNullByDefault
31 public class EventDoorbellChannelHelper extends EventChannelHelper {
32
33     public EventDoorbellChannelHelper() {
34         super(GROUP_DOORBELL_LAST_EVENT, GROUP_DOORBELL_SUB_EVENT);
35     }
36
37     @Override
38     protected @Nullable State internalGetHomeEvent(String channelId, @Nullable String groupId, HomeEvent event) {
39         if (groupId != null && GROUP_DOORBELL_SUB_EVENT.startsWith(groupId)) {
40             switch (channelId) {
41                 case CHANNEL_EVENT_TYPE:
42                     return toStringType(event.getEventType());
43                 case CHANNEL_EVENT_TIME:
44                     return new DateTimeType(event.getTime());
45                 case CHANNEL_EVENT_MESSAGE:
46                     return toStringType(event.getName());
47                 case CHANNEL_EVENT_SNAPSHOT:
48                     return toRawType(event.getSnapshotUrl());
49                 case CHANNEL_EVENT_SNAPSHOT_URL:
50                     return toStringType(event.getSnapshotUrl());
51                 case CHANNEL_EVENT_VIGNETTE:
52                     return toRawType(event.getVignetteUrl());
53                 case CHANNEL_EVENT_VIGNETTE_URL:
54                     return toStringType(event.getVignetteUrl());
55             }
56         }
57         return super.internalGetHomeEvent(channelId, groupId, event);
58     }
59 }