Skip to content

Commit f45cff8

Browse files
authored
[boschshc] Add support for Smoke Detector II (openhab#16357)
Signed-off-by: Patrick Gell <[email protected]>
1 parent 6f93b03 commit f45cff8

File tree

8 files changed

+170
-2
lines changed

8 files changed

+170
-2
lines changed

bundles/org.openhab.binding.boschshc/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Binding for the Bosch Smart Home.
2020
- [Intrusion Detection System](#intrusion-detection-system)
2121
- [Smart Bulb](#smart-bulb)
2222
- [Smoke Detector](#smoke-detector)
23+
- [Smoke Detector II](#smoke-detector-ii)
2324
- [User-defined States](#user-defined-states)
2425
- [Universal Switch](#universal-switch)
2526
- [Universal Switch II](#universal-switch-ii)
@@ -235,6 +236,19 @@ The smoke detector warns you in case of fire.
235236
| ------------------ | -------------------- | :------: | ------------------------------------------------------------------------------------------------- |
236237
| smoke-check | String | &#9745; | State of the smoke check. Also used to request a new smoke check. |
237238

239+
### Smoke Detector II
240+
241+
The smoke detector warns you in case of fire.
242+
243+
**Thing Type ID**: `smoke-detector`
244+
245+
| Channel Type ID | Item Type | Writable | Description |
246+
|-------------------|-------------| :------: |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
247+
| smoke-check | String | &#9745; | State of the smoke check. Also used to request a new smoke check. |
248+
| 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`. |
249+
| low-battery | Switch | &#9744; | Indicates whether the battery is low (`ON`) or OK (`OFF`). |
250+
| 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). |
251+
238252

239253
### User-defined States
240254

bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/BoschSHCBindingConstants.java

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class BoschSHCBindingConstants {
5353
public static final ThingTypeUID THING_TYPE_UNIVERSAL_SWITCH_2 = new ThingTypeUID(BINDING_ID, "universal-switch-2");
5454

5555
public static final ThingTypeUID THING_TYPE_USER_DEFINED_STATE = new ThingTypeUID(BINDING_ID, "user-defined-state");
56+
public static final ThingTypeUID THING_TYPE_SMOKE_DETECTOR_2 = new ThingTypeUID(BINDING_ID, "smoke-detector-2");
5657

5758
// List of all Channel IDs
5859
// Auto-generated from thing-types.xml via script, don't modify

bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/devices/BoschSHCHandlerFactory.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SMART_BULB;
2424
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SMART_PLUG_COMPACT;
2525
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SMOKE_DETECTOR;
26+
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SMOKE_DETECTOR_2;
2627
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_THERMOSTAT;
2728
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_TWINGUARD;
2829
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_UNIVERSAL_SWITCH;
@@ -47,6 +48,7 @@
4748
import org.openhab.binding.boschshc.internal.devices.plug.PlugHandler;
4849
import org.openhab.binding.boschshc.internal.devices.shuttercontrol.ShutterControlHandler;
4950
import org.openhab.binding.boschshc.internal.devices.smartbulb.SmartBulbHandler;
51+
import org.openhab.binding.boschshc.internal.devices.smokedetector.SmokeDetector2Handler;
5052
import org.openhab.binding.boschshc.internal.devices.smokedetector.SmokeDetectorHandler;
5153
import org.openhab.binding.boschshc.internal.devices.thermostat.ThermostatHandler;
5254
import org.openhab.binding.boschshc.internal.devices.twinguard.TwinguardHandler;
@@ -120,7 +122,8 @@ public ThingTypeHandlerMapping(ThingTypeUID thingTypeUID, Function<Thing, BaseTh
120122
new ThingTypeHandlerMapping(THING_TYPE_UNIVERSAL_SWITCH,
121123
thing -> new UniversalSwitchHandler(thing, timeZoneProvider)),
122124
new ThingTypeHandlerMapping(THING_TYPE_UNIVERSAL_SWITCH_2,
123-
thing -> new UniversalSwitch2Handler(thing, timeZoneProvider)));
125+
thing -> new UniversalSwitch2Handler(thing, timeZoneProvider)),
126+
new ThingTypeHandlerMapping(THING_TYPE_SMOKE_DETECTOR_2, SmokeDetector2Handler::new));
124127

125128
@Override
126129
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.boschshc.internal.devices.smokedetector;
14+
15+
import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_SIGNAL_STRENGTH;
16+
17+
import java.util.List;
18+
19+
import org.eclipse.jdt.annotation.NonNullByDefault;
20+
import org.openhab.binding.boschshc.internal.devices.AbstractSmokeDetectorHandler;
21+
import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
22+
import org.openhab.binding.boschshc.internal.services.communicationquality.CommunicationQualityService;
23+
import org.openhab.binding.boschshc.internal.services.communicationquality.dto.CommunicationQualityServiceState;
24+
import org.openhab.core.thing.Thing;
25+
26+
/**
27+
* The smoke detector 2 warns you in case of fire.
28+
*
29+
* @author Patrick Gell - Initial contribution
30+
*/
31+
@NonNullByDefault
32+
public class SmokeDetector2Handler extends AbstractSmokeDetectorHandler {
33+
34+
public SmokeDetector2Handler(Thing thing) {
35+
super(thing);
36+
}
37+
38+
@Override
39+
protected void initializeServices() throws BoschSHCException {
40+
super.initializeServices();
41+
42+
this.createService(CommunicationQualityService::new, this::updateChannels, List.of(CHANNEL_SIGNAL_STRENGTH),
43+
true);
44+
}
45+
46+
private void updateChannels(CommunicationQualityServiceState communicationQualityServiceState) {
47+
updateState(CHANNEL_SIGNAL_STRENGTH, communicationQualityServiceState.quality.toSystemSignalStrength());
48+
}
49+
}

bundles/org.openhab.binding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/discovery/ThingDiscoveryService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public class ThingDiscoveryService extends AbstractThingHandlerDiscoveryService<
8888
new AbstractMap.SimpleEntry<>("SWD2", BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT_2),
8989
new AbstractMap.SimpleEntry<>("TRV", BoschSHCBindingConstants.THING_TYPE_THERMOSTAT),
9090
new AbstractMap.SimpleEntry<>("WRC2", BoschSHCBindingConstants.THING_TYPE_UNIVERSAL_SWITCH),
91-
new AbstractMap.SimpleEntry<>("SWITCH2", BoschSHCBindingConstants.THING_TYPE_UNIVERSAL_SWITCH_2)
91+
new AbstractMap.SimpleEntry<>("SWITCH2", BoschSHCBindingConstants.THING_TYPE_UNIVERSAL_SWITCH_2),
92+
new AbstractMap.SimpleEntry<>("SMOKE_DETECTOR2", BoschSHCBindingConstants.THING_TYPE_SMOKE_DETECTOR_2)
9293
// Future Extension: map deviceModel names to BoschSHC Thing Types when they are supported
9394
// new AbstractMap.SimpleEntry<>("SMOKE_DETECTION_SYSTEM", BoschSHCBindingConstants.),
9495
// new AbstractMap.SimpleEntry<>("PRESENCE_SIMULATION_SERVICE", BoschSHCBindingConstants.),

bundles/org.openhab.binding.boschshc/src/main/resources/OH-INF/i18n/boschshc.properties

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ thing-type.boschshc.smart-bulb.label = Smart Bulb
2525
thing-type.boschshc.smart-bulb.description = A smart bulb connected via Zigbee.
2626
thing-type.boschshc.smart-plug-compact.label = Compact Smart Plug
2727
thing-type.boschshc.smart-plug-compact.description = A compact smart plug with energy monitoring capabilities.
28+
thing-type.boschshc.smoke-detector-2.label = Smoke Detector II
29+
thing-type.boschshc.smoke-detector-2.description = The smoke detector warns you in case of fire.
2830
thing-type.boschshc.smoke-detector.label = Smoke Detector
2931
thing-type.boschshc.smoke-detector.description = The smoke detector warns you in case of fire.
3032
thing-type.boschshc.thermostat.label = Thermostat

bundles/org.openhab.binding.boschshc/src/main/resources/OH-INF/thing/thing-types.xml

+18
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,24 @@
361361
<config-description-ref uri="thing-type:boschshc:device"/>
362362
</thing-type>
363363

364+
<thing-type id="smoke-detector-2">
365+
<supported-bridge-type-refs>
366+
<bridge-type-ref id="shc"/>
367+
</supported-bridge-type-refs>
368+
369+
<label>Smoke Detector II</label>
370+
<description>The smoke detector warns you in case of fire.</description>
371+
372+
<channels>
373+
<channel id="smoke-check" typeId="smoke-check"/>
374+
<channel id="battery-level" typeId="system.battery-level"/>
375+
<channel id="low-battery" typeId="system.low-battery"/>
376+
<channel id="signal-strength" typeId="system.signal-strength"/>
377+
</channels>
378+
379+
<config-description-ref uri="thing-type:boschshc:device"/>
380+
</thing-type>
381+
364382
<!-- Channels -->
365383

366384
<channel-type id="system-availability">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.boschshc.internal.devices.smokedetector;
14+
15+
import static org.mockito.Mockito.verify;
16+
17+
import org.eclipse.jdt.annotation.NonNullByDefault;
18+
import org.junit.jupiter.api.Test;
19+
import org.openhab.binding.boschshc.internal.devices.AbstractSmokeDetectorHandlerTest;
20+
import org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants;
21+
import org.openhab.core.library.types.DecimalType;
22+
import org.openhab.core.thing.ChannelUID;
23+
import org.openhab.core.thing.ThingTypeUID;
24+
25+
import com.google.gson.JsonElement;
26+
import com.google.gson.JsonParser;
27+
28+
/**
29+
* Unit Tests for {@link SmokeDetector2Handler}.
30+
*
31+
* @author Patrick Gell - Initial contribution
32+
*
33+
*/
34+
@NonNullByDefault
35+
public class SmokeDetector2HandlerTest extends AbstractSmokeDetectorHandlerTest<SmokeDetector2Handler> {
36+
37+
@Override
38+
protected SmokeDetector2Handler createFixture() {
39+
return new SmokeDetector2Handler(getThing());
40+
}
41+
42+
@Override
43+
protected String getDeviceID() {
44+
return "hdm:ZigBee:70ac08abfe5fe5f9";
45+
}
46+
47+
@Override
48+
protected ThingTypeUID getThingTypeUID() {
49+
return BoschSHCBindingConstants.THING_TYPE_SMOKE_DETECTOR_2;
50+
}
51+
52+
@Test
53+
void testUpdateChannelsCommunicationQualityService() {
54+
String json = """
55+
{
56+
"@type": "communicationQualityState",
57+
"quality": "UNKNOWN"
58+
}
59+
""";
60+
JsonElement jsonObject = JsonParser.parseString(json);
61+
62+
getFixture().processUpdate("CommunicationQuality", jsonObject);
63+
verify(getCallback()).stateUpdated(
64+
new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SIGNAL_STRENGTH),
65+
new DecimalType(0));
66+
67+
json = """
68+
{
69+
"@type": "communicationQualityState",
70+
"quality": "NORMAL"
71+
}
72+
""";
73+
jsonObject = JsonParser.parseString(json);
74+
75+
getFixture().processUpdate("CommunicationQuality", jsonObject);
76+
verify(getCallback()).stateUpdated(
77+
new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SIGNAL_STRENGTH),
78+
new DecimalType(3));
79+
}
80+
}

0 commit comments

Comments
 (0)