2 * Copyright (c) 2010-2024 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.netatmo.internal.handler.capability;
15 import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
16 import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
18 import java.util.List;
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.core.thing.ChannelUID;
27 import org.openhab.core.thing.ThingUID;
28 import org.openhab.core.types.UnDefType;
31 * {@link AlarmEventCapability} gives the ability to handle Alarm modules events
33 * @author Gaƫl L'hopital - Initial contribution
37 public class AlarmEventCapability extends HomeSecurityThingCapability {
39 public AlarmEventCapability(CommonInterface handler, NetatmoDescriptionProvider descriptionProvider,
40 List<ChannelHelper> channelHelpers) {
41 super(handler, descriptionProvider, channelHelpers);
45 protected void updateWebhookEvent(WebhookEvent event) {
46 super.updateWebhookEvent(event);
48 final ThingUID thingUid = handler.getThing().getUID();
49 handler.updateState(new ChannelUID(thingUid, GROUP_LAST_EVENT, CHANNEL_EVENT_TYPE),
50 toStringType(event.getEventType()));
51 handler.updateState(new ChannelUID(thingUid, GROUP_LAST_EVENT, CHANNEL_EVENT_TIME),
52 toDateTimeType(event.getTime()));
53 handler.updateState(new ChannelUID(thingUid, GROUP_LAST_EVENT, CHANNEL_EVENT_SUBTYPE),
54 event.getSubTypeDescription().map(d -> toStringType(d)).orElse(UnDefType.NULL));
55 final String message = event.getName();
56 handler.updateState(new ChannelUID(thingUid, GROUP_LAST_EVENT, CHANNEL_EVENT_MESSAGE),
57 message == null || message.isBlank() ? UnDefType.NULL : toStringType(message));
61 public List<NAObject> updateReadings() {
62 return getSecurityCapability().map(cap -> cap.getDeviceLastEvent(handler.getId(), moduleType.apiName))
63 .map(event -> List.of((NAObject) event)).orElse(List.of());