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.lutron.internal.handler;
15 import static org.openhab.binding.lutron.internal.LutronBindingConstants.CHANNEL_OCCUPANCYSTATUS;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.lutron.internal.protocol.DeviceCommand;
19 import org.openhab.binding.lutron.internal.protocol.lip.LutronCommandType;
20 import org.openhab.core.library.types.OnOffType;
21 import org.openhab.core.thing.Bridge;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.ThingStatus;
25 import org.openhab.core.thing.ThingStatusDetail;
26 import org.openhab.core.types.Command;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
32 * @author Allan Tong - Initial contribution
33 * @author Bob Adair - Added initDeviceState method
36 public class OccupancySensorHandler extends LutronHandler {
37 private final Logger logger = LoggerFactory.getLogger(OccupancySensorHandler.class);
39 private int integrationId;
41 public OccupancySensorHandler(Thing thing) {
46 public void handleCommand(ChannelUID channelUID, Command command) {
50 public void initialize() {
51 Number id = (Number) getThing().getConfiguration().get("integrationId");
53 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "No integrationId");
56 integrationId = id.intValue();
57 logger.debug("Initializing Occupancy Sensor handler for integration ID {}", id);
63 protected void initDeviceState() {
64 logger.debug("Initializing device state for Occupancy Sensor {}", getIntegrationId());
65 Bridge bridge = getBridge();
67 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "No bridge configured");
68 } else if (bridge.getStatus() == ThingStatus.ONLINE) {
69 updateStatus(ThingStatus.ONLINE); // can't poll this device, so assume it is online if the bridge is
71 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
76 public int getIntegrationId() {
77 return this.integrationId;
81 public void handleUpdate(LutronCommandType type, String... parameters) {
82 if (type == LutronCommandType.DEVICE && parameters.length == 2
83 && DeviceCommand.OCCUPIED_STATE_COMPONENT.equals(parameters[0])) {
84 if (DeviceCommand.STATE_OCCUPIED.equals(parameters[1])) {
85 updateState(CHANNEL_OCCUPANCYSTATUS, OnOffType.ON);
86 } else if (DeviceCommand.STATE_UNOCCUPIED.equals(parameters[1])) {
87 updateState(CHANNEL_OCCUPANCYSTATUS, OnOffType.OFF);