-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[boschshc] Provide alarm channel for smoke detectors (#18194)
Signed-off-by: David Pace <[email protected]>
- Loading branch information
1 parent
28ce3c2
commit ea978fe
Showing
19 changed files
with
448 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...boschshc/internal/devices/smokedetector/AbstractSmokeDetectorHandlerWithAlarmService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) 2010-2025 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_ALARM; | ||
|
||
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.alarm.AlarmService; | ||
import org.openhab.binding.boschshc.internal.services.alarm.dto.AlarmServiceState; | ||
import org.openhab.core.library.types.StringType; | ||
import org.openhab.core.thing.ChannelUID; | ||
import org.openhab.core.thing.Thing; | ||
import org.openhab.core.types.Command; | ||
|
||
/** | ||
* Abstract handler for smoke detectors that have an <code>Alarm</code> service. | ||
* <p> | ||
* Note that this includes Smoke Detector and Smoke Detector II, but not Twinguard. | ||
* | ||
* @author David Pace - Initial contribution | ||
* | ||
*/ | ||
@NonNullByDefault | ||
public abstract class AbstractSmokeDetectorHandlerWithAlarmService extends AbstractSmokeDetectorHandler { | ||
|
||
private AlarmService alarmService; | ||
|
||
protected AbstractSmokeDetectorHandlerWithAlarmService(Thing thing) { | ||
super(thing); | ||
this.alarmService = new AlarmService(); | ||
} | ||
|
||
@Override | ||
protected void initializeServices() throws BoschSHCException { | ||
super.initializeServices(); | ||
|
||
this.registerService(alarmService, this::updateChannels, List.of(CHANNEL_ALARM)); | ||
} | ||
|
||
private void updateChannels(AlarmServiceState state) { | ||
updateState(CHANNEL_ALARM, new StringType(state.value.toString())); | ||
} | ||
|
||
@Override | ||
public void handleCommand(ChannelUID channelUID, Command command) { | ||
super.handleCommand(channelUID, command); | ||
|
||
if (CHANNEL_ALARM.equals(channelUID.getId())) { | ||
this.handleServiceCommand(this.alarmService, command); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...hshc/src/main/java/org/openhab/binding/boschshc/internal/services/alarm/AlarmService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2010-2025 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.services.alarm; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException; | ||
import org.openhab.binding.boschshc.internal.services.BoschSHCService; | ||
import org.openhab.binding.boschshc.internal.services.alarm.dto.AlarmServiceState; | ||
import org.openhab.binding.boschshc.internal.services.alarm.dto.AlarmState; | ||
import org.openhab.core.library.types.StringType; | ||
import org.openhab.core.types.Command; | ||
|
||
/** | ||
* Alarm service for smoke detectors. | ||
* | ||
* @author David Pace - Initial contribution | ||
* | ||
*/ | ||
@NonNullByDefault | ||
public class AlarmService extends BoschSHCService<AlarmServiceState> { | ||
public AlarmService() { | ||
super("Alarm", AlarmServiceState.class); | ||
} | ||
|
||
@Override | ||
public AlarmServiceState handleCommand(Command command) throws BoschSHCException { | ||
if (command instanceof StringType stringCommand) { | ||
AlarmServiceState state = new AlarmServiceState(); | ||
state.value = AlarmState.from(stringCommand.toFullString()); | ||
return state; | ||
} | ||
return super.handleCommand(command); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...main/java/org/openhab/binding/boschshc/internal/services/alarm/dto/AlarmServiceState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2010-2025 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.services.alarm.dto; | ||
|
||
import org.openhab.binding.boschshc.internal.services.dto.BoschSHCServiceState; | ||
|
||
/** | ||
* State for alarm services of smoke detectors. | ||
* | ||
* @author David Pace - Initial contribution | ||
* | ||
*/ | ||
public class AlarmServiceState extends BoschSHCServiceState { | ||
public AlarmServiceState() { | ||
super("alarmState"); | ||
} | ||
|
||
public AlarmState value; | ||
} |
42 changes: 42 additions & 0 deletions
42
...hc/src/main/java/org/openhab/binding/boschshc/internal/services/alarm/dto/AlarmState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2010-2025 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.services.alarm.dto; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Possible states of smoke detector alarms. | ||
* | ||
* @author David Pace - Initial contribution | ||
* | ||
*/ | ||
public enum AlarmState { | ||
IDLE_OFF, | ||
PRIMARY_ALARM, | ||
SECONDARY_ALARM, | ||
INTRUSION_ALARM, | ||
INTRUSION_ALARM_ON_REQUESTED, | ||
INTRUSION_ALARM_OFF_REQUESTED; | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(AlarmState.class); | ||
|
||
public static AlarmState from(String identifier) { | ||
try { | ||
return valueOf(identifier); | ||
} catch (IllegalArgumentException e) { | ||
LOGGER.warn("Unsupported alarm state: {}", identifier); | ||
return IDLE_OFF; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.