]> git.basschouten.com Git - openhab-addons.git/blob
8e7c3a922bb86c6b099ee11999c5de63dd6f970b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.NAObject;
22 import org.openhab.binding.netatmo.internal.api.dto.WebhookEvent;
23 import org.openhab.binding.netatmo.internal.handler.CommonInterface;
24 import org.openhab.binding.netatmo.internal.handler.channelhelper.ChannelHelper;
25 import org.openhab.binding.netatmo.internal.providers.NetatmoDescriptionProvider;
26 import org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils;
27 import org.openhab.core.types.UnDefType;
28
29 /**
30  * {@link AlarmEventCapability} gives the ability to handle Alarm modules events
31  *
32  * @author GaĆ«l L'hopital - Initial contribution
33  *
34  */
35 @NonNullByDefault
36 public class AlarmEventCapability extends HomeSecurityThingCapability {
37
38     public AlarmEventCapability(CommonInterface handler, NetatmoDescriptionProvider descriptionProvider,
39             List<ChannelHelper> channelHelpers) {
40         super(handler, descriptionProvider, channelHelpers);
41     }
42
43     @Override
44     protected void updateWebhookEvent(WebhookEvent event) {
45         super.updateWebhookEvent(event);
46
47         handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_TYPE, toStringType(event.getEventType()));
48         handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_TIME, toDateTimeType(event.getTime()));
49         handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_SUBTYPE,
50                 event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL));
51         final String message = event.getName();
52         handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_MESSAGE,
53                 message == null || message.isBlank() ? UnDefType.NULL : toStringType(message));
54     }
55
56     @Override
57     public List<NAObject> updateReadings() {
58         return getSecurityCapability().map(cap -> cap.getDeviceLastEvent(handler.getId(), moduleType.apiName))
59                 .map(event -> List.of((NAObject) event)).orElse(List.of());
60     }
61 }