]> git.basschouten.com Git - openhab-addons.git/commitdiff
[boschshc] Add support for Smoke Detector II (#16357)
authorPatrick <54861416+pat-git023@users.noreply.github.com>
Sun, 4 Feb 2024 21:31:01 +0000 (22:31 +0100)
committerGitHub <noreply@github.com>
Sun, 4 Feb 2024 21:31:01 +0000 (22:31 +0100)
Signed-off-by: Patrick Gell <patgit023@gmail.com>
bundles/org.openhab.binding.boschshc/README.md
bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/BoschSHCBindingConstants.java
bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/BoschSHCHandlerFactory.java
bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/smokedetector/SmokeDetector2Handler.java [new file with mode: 0644]
bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/discovery/ThingDiscoveryService.java
bundles/org.openhab.binding.boschshc/src/main/resources/OH-INF/i18n/boschshc.properties
bundles/org.openhab.binding.boschshc/src/main/resources/OH-INF/thing/thing-types.xml
bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/smokedetector/SmokeDetector2HandlerTest.java [new file with mode: 0644]

index 56be053b448e74d99eba373491b03f796353eb94..60b0e8e6db664e90b19eb09388ee322b55e69533 100644 (file)
@@ -20,6 +20,7 @@ Binding for the Bosch Smart Home.
     - [Intrusion Detection System](#intrusion-detection-system)
     - [Smart Bulb](#smart-bulb)
     - [Smoke Detector](#smoke-detector)
+    - [Smoke Detector II](#smoke-detector-ii)
     - [User-defined States](#user-defined-states)
     - [Universal Switch](#universal-switch)
     - [Universal Switch II](#universal-switch-ii)
@@ -235,6 +236,19 @@ The smoke detector warns you in case of fire.
 | ------------------ | -------------------- | :------: | ------------------------------------------------------------------------------------------------- |
 | smoke-check        | String               | &#9745;  | State of the smoke check. Also used to request a new smoke check.                                 |
 
+### Smoke Detector II
+
+The smoke detector warns you in case of fire.
+
+**Thing Type ID**: `smoke-detector`
+
+| Channel Type ID   | Item Type   | Writable | Description                                                                                                                                                                                                                 |
+|-------------------|-------------| :------: |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| smoke-check       | String      | &#9745;  | State of the smoke check. Also used to request a new smoke check.                                                                                                                                                           |
+| battery-level     | Number      | &#9744;  | Current battery level percentage as integer number. Bosch-specific battery levels are mapped to numbers as follows: `OK`: 100, `LOW_BATTERY`: 10, `CRITICAL_LOW`: 1, `CRITICALLY_LOW_BATTERY`: 1, `NOT_AVAILABLE`: `UNDEF`. |
+| low-battery       | Switch      | &#9744;  | Indicates whether the battery is low (`ON`) or OK (`OFF`).                                                                                                                                                                  |
+| signal-strength   | Number      | &#9744;  | Communication quality between the device and the Smart Home Controller. Possible values range between 0 (unknown) and 4 (best signal strength).                                                                             |
+
 
 ### User-defined States
 
index b2aee2d82485c4544e3fee73283dec25aa6817e0..4d6676c76754a05aaa043cca5e3f8072904ba7b2 100644 (file)
@@ -53,6 +53,7 @@ public class BoschSHCBindingConstants {
     public static final ThingTypeUID THING_TYPE_UNIVERSAL_SWITCH_2 = new ThingTypeUID(BINDING_ID, "universal-switch-2");
 
     public static final ThingTypeUID THING_TYPE_USER_DEFINED_STATE = new ThingTypeUID(BINDING_ID, "user-defined-state");
+    public static final ThingTypeUID THING_TYPE_SMOKE_DETECTOR_2 = new ThingTypeUID(BINDING_ID, "smoke-detector-2");
 
     // List of all Channel IDs
     // Auto-generated from thing-types.xml via script, don't modify
index b5664588eec2c8846b459d8b2c703a8194c3d51e..c512d1090556582288566136ac2817fb8de5e8cc 100644 (file)
@@ -23,6 +23,7 @@ import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConst
 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SMART_BULB;
 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SMART_PLUG_COMPACT;
 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SMOKE_DETECTOR;
+import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SMOKE_DETECTOR_2;
 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_THERMOSTAT;
 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_TWINGUARD;
 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_UNIVERSAL_SWITCH;
@@ -47,6 +48,7 @@ import org.openhab.binding.boschshc.internal.devices.motiondetector.MotionDetect
 import org.openhab.binding.boschshc.internal.devices.plug.PlugHandler;
 import org.openhab.binding.boschshc.internal.devices.shuttercontrol.ShutterControlHandler;
 import org.openhab.binding.boschshc.internal.devices.smartbulb.SmartBulbHandler;
+import org.openhab.binding.boschshc.internal.devices.smokedetector.SmokeDetector2Handler;
 import org.openhab.binding.boschshc.internal.devices.smokedetector.SmokeDetectorHandler;
 import org.openhab.binding.boschshc.internal.devices.thermostat.ThermostatHandler;
 import org.openhab.binding.boschshc.internal.devices.twinguard.TwinguardHandler;
@@ -120,7 +122,8 @@ public class BoschSHCHandlerFactory extends BaseThingHandlerFactory {
             new ThingTypeHandlerMapping(THING_TYPE_UNIVERSAL_SWITCH,
                     thing -> new UniversalSwitchHandler(thing, timeZoneProvider)),
             new ThingTypeHandlerMapping(THING_TYPE_UNIVERSAL_SWITCH_2,
-                    thing -> new UniversalSwitch2Handler(thing, timeZoneProvider)));
+                    thing -> new UniversalSwitch2Handler(thing, timeZoneProvider)),
+            new ThingTypeHandlerMapping(THING_TYPE_SMOKE_DETECTOR_2, SmokeDetector2Handler::new));
 
     @Override
     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
diff --git a/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/smokedetector/SmokeDetector2Handler.java b/bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/smokedetector/SmokeDetector2Handler.java
new file mode 100644 (file)
index 0000000..36117c2
--- /dev/null
@@ -0,0 +1,49 @@
+/**
+ * Copyright (c) 2010-2024 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.boschshc.internal.devices.smokedetector;
+
+import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_SIGNAL_STRENGTH;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.boschshc.internal.devices.AbstractSmokeDetectorHandler;
+import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
+import org.openhab.binding.boschshc.internal.services.communicationquality.CommunicationQualityService;
+import org.openhab.binding.boschshc.internal.services.communicationquality.dto.CommunicationQualityServiceState;
+import org.openhab.core.thing.Thing;
+
+/**
+ * The smoke detector 2 warns you in case of fire.
+ *
+ * @author Patrick Gell - Initial contribution
+ */
+@NonNullByDefault
+public class SmokeDetector2Handler extends AbstractSmokeDetectorHandler {
+
+    public SmokeDetector2Handler(Thing thing) {
+        super(thing);
+    }
+
+    @Override
+    protected void initializeServices() throws BoschSHCException {
+        super.initializeServices();
+
+        this.createService(CommunicationQualityService::new, this::updateChannels, List.of(CHANNEL_SIGNAL_STRENGTH),
+                true);
+    }
+
+    private void updateChannels(CommunicationQualityServiceState communicationQualityServiceState) {
+        updateState(CHANNEL_SIGNAL_STRENGTH, communicationQualityServiceState.quality.toSystemSignalStrength());
+    }
+}
index 1a7a6bbe5712037bfe1ef5394d153e172a3fafb2..0562dcacf25fbe9ac03b9c4016666a7290f3a2ba 100644 (file)
@@ -88,7 +88,8 @@ public class ThingDiscoveryService extends AbstractThingHandlerDiscoveryService<
             new AbstractMap.SimpleEntry<>("SWD2", BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT_2),
             new AbstractMap.SimpleEntry<>("TRV", BoschSHCBindingConstants.THING_TYPE_THERMOSTAT),
             new AbstractMap.SimpleEntry<>("WRC2", BoschSHCBindingConstants.THING_TYPE_UNIVERSAL_SWITCH),
-            new AbstractMap.SimpleEntry<>("SWITCH2", BoschSHCBindingConstants.THING_TYPE_UNIVERSAL_SWITCH_2)
+            new AbstractMap.SimpleEntry<>("SWITCH2", BoschSHCBindingConstants.THING_TYPE_UNIVERSAL_SWITCH_2),
+            new AbstractMap.SimpleEntry<>("SMOKE_DETECTOR2", BoschSHCBindingConstants.THING_TYPE_SMOKE_DETECTOR_2)
 // Future Extension: map deviceModel names to BoschSHC Thing Types when they are supported
 //            new AbstractMap.SimpleEntry<>("SMOKE_DETECTION_SYSTEM", BoschSHCBindingConstants.),
 //            new AbstractMap.SimpleEntry<>("PRESENCE_SIMULATION_SERVICE", BoschSHCBindingConstants.),
index c5fc3174f5f3820eb8198ca6d0b082bb92b0e287..b2a7349c9e94c3eb5606a80fd659851fac55e247 100644 (file)
@@ -25,6 +25,8 @@ thing-type.boschshc.smart-bulb.label = Smart Bulb
 thing-type.boschshc.smart-bulb.description = A smart bulb connected via Zigbee.
 thing-type.boschshc.smart-plug-compact.label = Compact Smart Plug
 thing-type.boschshc.smart-plug-compact.description = A compact smart plug with energy monitoring capabilities.
+thing-type.boschshc.smoke-detector-2.label = Smoke Detector II
+thing-type.boschshc.smoke-detector-2.description = The smoke detector warns you in case of fire.
 thing-type.boschshc.smoke-detector.label = Smoke Detector
 thing-type.boschshc.smoke-detector.description = The smoke detector warns you in case of fire.
 thing-type.boschshc.thermostat.label = Thermostat
index 9f9a4ccc6a7aff92ac645ce9b459bb340abb15f2..4aea5e096a3977edd6860ebaa6f26f5337b88d54 100644 (file)
                <config-description-ref uri="thing-type:boschshc:device"/>
        </thing-type>
 
+       <thing-type id="smoke-detector-2">
+               <supported-bridge-type-refs>
+                       <bridge-type-ref id="shc"/>
+               </supported-bridge-type-refs>
+
+               <label>Smoke Detector II</label>
+               <description>The smoke detector warns you in case of fire.</description>
+
+               <channels>
+                       <channel id="smoke-check" typeId="smoke-check"/>
+                       <channel id="battery-level" typeId="system.battery-level"/>
+                       <channel id="low-battery" typeId="system.low-battery"/>
+                       <channel id="signal-strength" typeId="system.signal-strength"/>
+               </channels>
+
+               <config-description-ref uri="thing-type:boschshc:device"/>
+       </thing-type>
+
        <!-- Channels -->
 
        <channel-type id="system-availability">
diff --git a/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/smokedetector/SmokeDetector2HandlerTest.java b/bundles/org.openhab.binding.boschshc/src/test/java/org/openhab/binding/boschshc/internal/devices/smokedetector/SmokeDetector2HandlerTest.java
new file mode 100644 (file)
index 0000000..2fa4dbd
--- /dev/null
@@ -0,0 +1,80 @@
+/**
+ * Copyright (c) 2010-2024 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.boschshc.internal.devices.smokedetector;
+
+import static org.mockito.Mockito.verify;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.junit.jupiter.api.Test;
+import org.openhab.binding.boschshc.internal.devices.AbstractSmokeDetectorHandlerTest;
+import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants;
+import org.openhab.core.library.types.DecimalType;
+import org.openhab.core.thing.ChannelUID;
+import org.openhab.core.thing.ThingTypeUID;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+
+/**
+ * Unit Tests for {@link SmokeDetector2Handler}.
+ *
+ * @author Patrick Gell - Initial contribution
+ *
+ */
+@NonNullByDefault
+public class SmokeDetector2HandlerTest extends AbstractSmokeDetectorHandlerTest<SmokeDetector2Handler> {
+
+    @Override
+    protected SmokeDetector2Handler createFixture() {
+        return new SmokeDetector2Handler(getThing());
+    }
+
+    @Override
+    protected String getDeviceID() {
+        return "hdm:ZigBee:70ac08abfe5fe5f9";
+    }
+
+    @Override
+    protected ThingTypeUID getThingTypeUID() {
+        return BoschSHCBindingConstants.THING_TYPE_SMOKE_DETECTOR_2;
+    }
+
+    @Test
+    void testUpdateChannelsCommunicationQualityService() {
+        String json = """
+                {
+                    "@type": "communicationQualityState",
+                    "quality": "UNKNOWN"
+                }
+                """;
+        JsonElement jsonObject = JsonParser.parseString(json);
+
+        getFixture().processUpdate("CommunicationQuality", jsonObject);
+        verify(getCallback()).stateUpdated(
+                new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SIGNAL_STRENGTH),
+                new DecimalType(0));
+
+        json = """
+                {
+                    "@type": "communicationQualityState",
+                    "quality": "NORMAL"
+                }
+                """;
+        jsonObject = JsonParser.parseString(json);
+
+        getFixture().processUpdate("CommunicationQuality", jsonObject);
+        verify(getCallback()).stateUpdated(
+                new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SIGNAL_STRENGTH),
+                new DecimalType(3));
+    }
+}