[boschshc] Add support for Smoke Detector II (#16357)

Signed-off-by: Patrick Gell <patgit023@gmail.com>
This commit is contained in:
Patrick 2024-02-04 22:31:01 +01:00 committed by GitHub
parent 6f93b03d8d
commit f45cff82d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 170 additions and 2 deletions

View 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

View 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

View 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) {

View File

@ -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());
}
}

View 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.),

View 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

View File

@ -361,6 +361,24 @@
<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">

View File

@ -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));
}
}