]> git.basschouten.com Git - openhab-addons.git/blob
3db982c14c1d5f068c6c0af52461b4eca0a3dce2
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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;
14
15 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_SMOKE_CHECK;
16
17 import java.util.List;
18
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;
27
28 /**
29  * Abstract handler implementation for devices with a smoke detector.
30  *
31  * @author Christian Oeing - Initial contribution
32  * @author Gerd Zanker - AbstractSmokeDetectorHandler refactoring for reuse
33  */
34 @NonNullByDefault
35 public abstract class AbstractSmokeDetectorHandler extends AbstractBatteryPoweredDeviceHandler {
36
37     private SmokeDetectorCheckService smokeDetectorCheckService;
38
39     public AbstractSmokeDetectorHandler(Thing thing) {
40         super(thing);
41         this.smokeDetectorCheckService = new SmokeDetectorCheckService();
42     }
43
44     @Override
45     protected void initializeServices() throws BoschSHCException {
46         super.initializeServices();
47
48         this.registerService(smokeDetectorCheckService, this::updateChannels, List.of(CHANNEL_SMOKE_CHECK));
49     }
50
51     @Override
52     public void handleCommand(ChannelUID channelUID, Command command) {
53         super.handleCommand(channelUID, command);
54
55         switch (channelUID.getId()) {
56             case CHANNEL_SMOKE_CHECK:
57                 this.handleServiceCommand(this.smokeDetectorCheckService, command);
58                 break;
59         }
60     }
61
62     private void updateChannels(SmokeDetectorCheckServiceState state) {
63         updateState(CHANNEL_SMOKE_CHECK, new StringType(state.value.toString()));
64     }
65 }