]> git.basschouten.com Git - openhab-addons.git/blob
656104a1eb8fb4ef9bf7a733200dbdcaaec08c2a
[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.windowcontact;
14
15 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_BYPASS_STATE;
16 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_SIGNAL_STRENGTH;
17
18 import java.util.List;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
22 import org.openhab.binding.boschshc.internal.services.bypass.BypassService;
23 import org.openhab.binding.boschshc.internal.services.bypass.dto.BypassServiceState;
24 import org.openhab.binding.boschshc.internal.services.communicationquality.CommunicationQualityService;
25 import org.openhab.binding.boschshc.internal.services.communicationquality.dto.CommunicationQualityServiceState;
26 import org.openhab.core.thing.Thing;
27
28 /**
29  * Handler for Door/Window Contact II
30  * 
31  * @author David Pace - Initial contribution
32  *
33  */
34 @NonNullByDefault
35 public class WindowContact2Handler extends WindowContactHandler {
36
37     public WindowContact2Handler(Thing thing) {
38         super(thing);
39     }
40
41     @Override
42     protected void initializeServices() throws BoschSHCException {
43         super.initializeServices();
44
45         this.createService(BypassService::new, this::updateChannels, List.of(CHANNEL_BYPASS_STATE), true);
46         this.createService(CommunicationQualityService::new, this::updateChannels, List.of(CHANNEL_SIGNAL_STRENGTH),
47                 true);
48     }
49
50     private void updateChannels(BypassServiceState bypassServiceState) {
51         updateState(CHANNEL_BYPASS_STATE, bypassServiceState.state.toOnOffTypeOrUndef());
52     }
53
54     private void updateChannels(CommunicationQualityServiceState communicationQualityServiceState) {
55         updateState(CHANNEL_SIGNAL_STRENGTH, communicationQualityServiceState.quality.toSystemSignalStrength());
56     }
57 }