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.windowcontact;
15 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_CONTACT;
17 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.boschshc.internal.devices.AbstractBatteryPoweredDeviceHandler;
21 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
22 import org.openhab.binding.boschshc.internal.services.shuttercontact.ShutterContactService;
23 import org.openhab.binding.boschshc.internal.services.shuttercontact.ShutterContactState;
24 import org.openhab.binding.boschshc.internal.services.shuttercontact.dto.ShutterContactServiceState;
25 import org.openhab.core.library.types.OpenClosedType;
26 import org.openhab.core.thing.Thing;
27 import org.openhab.core.types.State;
30 * Detects open windows and doors.
32 * @author Stefan Kästle - Initial contribution
35 public class WindowContactHandler extends AbstractBatteryPoweredDeviceHandler {
37 public WindowContactHandler(Thing thing) {
42 protected void initializeServices() throws BoschSHCException {
43 super.initializeServices();
45 this.createService(ShutterContactService::new, this::updateChannels, List.of(CHANNEL_CONTACT));
48 private void updateChannels(ShutterContactServiceState state) {
49 State contact = state.value == ShutterContactState.CLOSED ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
50 updateState(CHANNEL_CONTACT, contact);