From a4781b477068aca39491fe1f6bac64c227d869c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20L=27hopital?= Date: Sat, 8 Oct 2022 18:49:44 +0200 Subject: [PATCH] [netatmo] Adding Door/Window sensor (#13503) * Initial PR to add NADoorTag to netatmo binding Signed-off-by: clinique --- bundles/org.openhab.binding.netatmo/README.md | 13 +++++ .../internal/NetatmoBindingConstants.java | 1 + .../netatmo/internal/api/data/ModuleType.java | 4 ++ .../channelhelper/DoorTagChannelHelper.java | 52 +++++++++++++++++++ .../resources/OH-INF/i18n/netatmo.properties | 4 ++ .../main/resources/OH-INF/thing/channels.xml | 7 +++ .../main/resources/OH-INF/thing/security.xml | 7 +++ 7 files changed, 88 insertions(+) create mode 100644 bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/channelhelper/DoorTagChannelHelper.java diff --git a/bundles/org.openhab.binding.netatmo/README.md b/bundles/org.openhab.binding.netatmo/README.md index 128246477..cf9214f33 100644 --- a/bundles/org.openhab.binding.netatmo/README.md +++ b/bundles/org.openhab.binding.netatmo/README.md @@ -9,6 +9,7 @@ The Netatmo binding integrates the following Netatmo products: - *Outdoor Camera / Presence*. Reports last event, consult picture and video from event/camera. - *Doorbell* - *Smoke Detector* +- *Smart Door Sensor* See https://www.netatmo.com/ for details on their product. @@ -94,6 +95,7 @@ Now that you have got your bridge _ONLINE_ you can now start a scan with the bin | thermostat | Thing | NATherm1 | The Thermostat device placed in a given room. | id | | room | Thing | NARoom | A room in your house. | id | | valve | Thing | NRV | A valve controlling a radiator. | id | +| tag | Thing | NACamDoorTag | A door / window sensor | id | @@ -610,6 +612,17 @@ Note: live feeds either locally or via VPN are not available in Netatmo API. | battery | low-battery | Switch | Read-only | Low battery | +**Supported channels for the Door Tag thing:** + +| Channel Group | Channel ID | Item Type | Read/Write | Description | +|---------------|-------------------|--------------|------------|------------------------------------------------------| +| tag | status | Contact | Read-only | Status of tag (OPEN,CLOSED) | +| signal | strength | Number | Read-only | Signal strength (0 for no signal, 1 for weak...) | +| signal | value | Number:Power | Read-only | Signal strength in dBm | +| timestamp | last-seen | DateTime | Read-only | Last time the module reported its presence | +| battery | value | Number | Read-only | Battery level | +| battery | low-battery | Switch | Read-only | Low battery | + ### Welcome Person Netatmo API distinguishes two kinds of persons: diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/NetatmoBindingConstants.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/NetatmoBindingConstants.java index 4165bb6ba..d23fcb568 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/NetatmoBindingConstants.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/NetatmoBindingConstants.java @@ -55,6 +55,7 @@ public class NetatmoBindingConstants { public static final String GROUP_PRESENCE = "presence"; public static final String GROUP_SIREN = "siren"; public static final String GROUP_PERSON = "person"; + public static final String GROUP_TAG = "tag"; public static final String GROUP_PROPERTIES = "properties"; public static final String GROUP_SETPOINT = "setpoint"; public static final String GROUP_LOCATION = "location"; diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/ModuleType.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/ModuleType.java index fc313af17..58e985510 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/ModuleType.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/data/ModuleType.java @@ -41,6 +41,7 @@ import org.openhab.binding.netatmo.internal.handler.capability.WeatherCapability import org.openhab.binding.netatmo.internal.handler.channelhelper.AirQualityChannelHelper; import org.openhab.binding.netatmo.internal.handler.channelhelper.ApiBridgeChannelHelper; import org.openhab.binding.netatmo.internal.handler.channelhelper.CameraChannelHelper; +import org.openhab.binding.netatmo.internal.handler.channelhelper.DoorTagChannelHelper; import org.openhab.binding.netatmo.internal.handler.channelhelper.EnergyChannelHelper; import org.openhab.binding.netatmo.internal.handler.channelhelper.EventChannelHelper; import org.openhab.binding.netatmo.internal.handler.channelhelper.EventDoorbellChannelHelper; @@ -80,6 +81,9 @@ public enum ModuleType { ChannelGroup.SIGNAL, ChannelGroup.EVENT, new ChannelGroup(CameraChannelHelper.class, GROUP_CAM_STATUS, GROUP_CAM_LIVE)), + TAG(FeatureArea.SECURITY, "NACamDoorTag", WELCOME, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL, + ChannelGroup.BATTERY, ChannelGroup.TIMESTAMP, new ChannelGroup(DoorTagChannelHelper.class, GROUP_TAG)), + SIREN(FeatureArea.SECURITY, "NIS", WELCOME, Set.of(ChannelHelperCapability.class), ChannelGroup.SIGNAL, ChannelGroup.BATTERY, ChannelGroup.TIMESTAMP, new ChannelGroup(SirenChannelHelper.class, GROUP_SIREN)), diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/channelhelper/DoorTagChannelHelper.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/channelhelper/DoorTagChannelHelper.java new file mode 100644 index 000000000..e7f98084f --- /dev/null +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/channelhelper/DoorTagChannelHelper.java @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.netatmo.internal.handler.channelhelper; + +import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.CHANNEL_STATUS; + +import java.util.Set; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.binding.netatmo.internal.api.dto.HomeStatusModule; +import org.openhab.binding.netatmo.internal.api.dto.NAThing; +import org.openhab.core.config.core.Configuration; +import org.openhab.core.library.types.OpenClosedType; +import org.openhab.core.types.State; +import org.openhab.core.types.UnDefType; + +/** + * The {@link DoorTagChannelHelper} handles channels of door sensor things. + * + * @author Gaƫl L'hopital - Initial contribution + * + */ +@NonNullByDefault +public class DoorTagChannelHelper extends ChannelHelper { + + public DoorTagChannelHelper(Set providedGroups) { + super(providedGroups); + } + + @Override + protected @Nullable State internalGetProperty(String channelId, NAThing naThing, Configuration config) { + if (naThing instanceof HomeStatusModule) { + HomeStatusModule doorTag = (HomeStatusModule) naThing; + if (CHANNEL_STATUS.equalsIgnoreCase(channelId)) { + return doorTag.getStatus().map(status -> (State) OpenClosedType.valueOf(status.toUpperCase())) + .orElse(UnDefType.UNDEF); + } + } + return null; + } +} diff --git a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo.properties b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo.properties index 82cd51dc6..2d075ccc0 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo.properties +++ b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo.properties @@ -87,6 +87,7 @@ channel-group-type.netatmo.sub-event-doorbell.channel.vignette.label = Vignette channel-group-type.netatmo.sub-event-doorbell.channel.vignette.description = Vignette of the Snapshot. channel-group-type.netatmo.sub-event-doorbell.channel.vignette-url.label = Vignette URL channel-group-type.netatmo.sub-event-doorbell.channel.vignette-url.description = URL of the vignette. +channel-group-type.netatmo.tag.label = Door Tag channel-group-type.netatmo.temperature-extended.label = Temperature channel-group-type.netatmo.temperature-extended.channel.max-time.label = Today Max Timestamp channel-group-type.netatmo.temperature-extended.channel.max-time.description = Moment when temperature was measured at its maximum today. @@ -301,6 +302,7 @@ channel-type.netatmo.siren-status.label = Status channel-type.netatmo.siren-status.description = Status of the siren channel-type.netatmo.siren-status.state.option.no_sound = Silent channel-type.netatmo.siren-status.state.option.sound = Alarm +channel-type.netatmo.tag-status.label = Door Status channel-type.netatmo.th-mode.label = Thermostat Mode channel-type.netatmo.th-mode.description = Chosen thermostat mode (home, frost guard, manual, max). channel-type.netatmo.th-mode.state.option.HOME = Home @@ -378,6 +380,8 @@ thing-type.netatmo.account.label = Netatmo Account thing-type.netatmo.account.description = This bridge represents an account, gateway to Netatmo API. thing-type.netatmo.doorbell.label = Smart Video Doorbell thing-type.netatmo.doorbell.description = The Netatmo Smart Video Doorbell device. +thing-type.netatmo.tag.label = Smart Door Sensor +thing-type.netatmo.tag.description = The Netatmo Smart Door or Window sensor. thing-type.netatmo.home-coach.label = Healthy Home Coach thing-type.netatmo.home-coach.description = Healthy home coach reporting health-index, temperature, humidity, pressure, air quality and sound level. thing-type.netatmo.home.label = Home diff --git a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/thing/channels.xml b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/thing/channels.xml index 71c77eda4..7599a1958 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/thing/channels.xml +++ b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/thing/channels.xml @@ -37,6 +37,13 @@ + + Contact + + Door + + + Switch diff --git a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/thing/security.xml b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/thing/security.xml index e9f9507c8..cf410d75a 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/thing/security.xml +++ b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/thing/security.xml @@ -187,6 +187,13 @@ + + + + + + +