2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.boschshc.internal.devices;
15 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_SMOKE_CHECK;
17 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
21 import org.openhab.binding.boschshc.internal.services.smokedetectorcheck.SmokeDetectorCheckService;
22 import org.openhab.binding.boschshc.internal.services.smokedetectorcheck.dto.SmokeDetectorCheckServiceState;
23 import org.openhab.core.library.types.StringType;
24 import org.openhab.core.thing.ChannelUID;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.types.Command;
29 * Abstract handler implementation for devices with a smoke detector.
31 * @author Christian Oeing - Initial contribution
32 * @author Gerd Zanker - AbstractSmokeDetectorHandler refactoring for reuse
35 public abstract class AbstractSmokeDetectorHandler extends AbstractBatteryPoweredDeviceHandler {
37 private SmokeDetectorCheckService smokeDetectorCheckService;
39 public AbstractSmokeDetectorHandler(Thing thing) {
41 this.smokeDetectorCheckService = new SmokeDetectorCheckService();
45 protected void initializeServices() throws BoschSHCException {
46 super.initializeServices();
48 this.registerService(smokeDetectorCheckService, this::updateChannels, List.of(CHANNEL_SMOKE_CHECK));
52 public void handleCommand(ChannelUID channelUID, Command command) {
53 super.handleCommand(channelUID, command);
55 switch (channelUID.getId()) {
56 case CHANNEL_SMOKE_CHECK:
57 this.handleServiceCommand(this.smokeDetectorCheckService, command);
62 private void updateChannels(SmokeDetectorCheckServiceState state) {
63 updateState(CHANNEL_SMOKE_CHECK, new StringType(state.value.toString()));