2 * Copyright (c) 2010-2021 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.bluetooth.enoceanble.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.bluetooth.BeaconBluetoothHandler;
17 import org.openhab.binding.bluetooth.notification.BluetoothScanNotification;
18 import org.openhab.core.thing.CommonTriggerEvents;
19 import org.openhab.core.thing.Thing;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * The {@link EnoceanBleRockerHandler} is responsible for handling commands, which are
25 * sent to one of the channels.
27 * @author Patrick Fink - Initial contribution
30 public class EnoceanBleRockerHandler extends BeaconBluetoothHandler {
32 private final Logger logger = LoggerFactory.getLogger(EnoceanBleRockerHandler.class);
34 public EnoceanBleRockerHandler(Thing thing) {
39 public void onScanRecordReceived(BluetoothScanNotification scanNotification) {
40 super.onScanRecordReceived(scanNotification);
41 final byte[] manufacturerData = scanNotification.getManufacturerData();
42 logger.debug("Received new scan notification for {}: {}", device.getAddress(), manufacturerData);
44 if (manufacturerData != null && manufacturerData.length > 0) {
45 EnoceanBlePtm215Event event = new EnoceanBlePtm215Event(manufacturerData);
46 logger.debug("Parsed manufacturer data to PTM215B event: {}", event);
47 triggerChannel(resolveChannel(event), resolveTriggerEvent(event));
49 } catch (IllegalStateException e) {
50 logger.warn("PTM215B event could not be parsed correctly, exception occured:", e);
54 protected String resolveChannel(EnoceanBlePtm215Event event) {
55 if (event.isButton1()) {
56 return EnoceanBleBindingConstants.CHANNEL_ID_ROCKER1;
58 if (event.isButton2()) {
59 return EnoceanBleBindingConstants.CHANNEL_ID_ROCKER2;
61 throw new IllegalStateException(
62 "PTM215B event cannot be resolved correctly to a channel, probably received message is invalid");
65 protected String resolveTriggerEvent(EnoceanBlePtm215Event event) {
67 if (event.isPressed()) {
68 return CommonTriggerEvents.DIR1_PRESSED;
70 return CommonTriggerEvents.DIR1_RELEASED;
74 if (event.isPressed()) {
75 return CommonTriggerEvents.DIR2_PRESSED;
77 return CommonTriggerEvents.DIR2_RELEASED;
80 throw new IllegalStateException(
81 "PTM215B event cannot be resolved correctly to an openHAB event, probably received message is invalid");