import org.slf4j.LoggerFactory;
/**
- * The {@link OpenWebNetLightingHandler} is responsible for handling commands/messages for a Lighting OpenWebNet device.
+ * The {@link OpenWebNetLightingHandler} is responsible for handling
+ * commands/messages for a Lighting OpenWebNet device.
* It extends the abstract {@link OpenWebNetThingHandler}.
*
* @author Massimo Valla - Initial contribution
// interval to interpret ON as response to requestStatus
private static final int BRIGHTNESS_STATUS_REQUEST_INTERVAL_MSEC = 250;
- // time to wait before sending a statusRequest, to avoid repeated requests and ensure dimmer has reached its final
- // level
+ // time to wait before sending a statusRequest, to avoid repeated requests and
+ // ensure dimmer has reached its final level
private static final int BRIGHTNESS_STATUS_REQUEST_DELAY_MSEC = 900;
private static final int UNKNOWN_STATE = 1000;
private int brightnessBeforeOff = UNKNOWN_STATE; // latest brightness before device was set to off
- private int sw[] = { UNKNOWN_STATE, UNKNOWN_STATE }; // current switch(es) state
-
public OpenWebNetLightingHandler(Thing thing) {
super(thing);
}
logger.debug("--- refreshDevice() : refreshing SINGLE... ({})", thing.getUID());
ThingTypeUID thingType = thing.getThingTypeUID();
if (THING_TYPE_ZB_ON_OFF_SWITCH_2UNITS.equals(thingType)) {
- // Unfortunately using USB Gateway OpenWebNet both switch endpoints cannot be requested at the same
- // time using UNIT 00 because USB stick returns NACK, so we need to send a request status for both
- // endpoints
+ /*
+ * Unfortunately using USB Gateway OpenWebNet both switch endpoints cannot be
+ * requested at the same time using UNIT 00 because USB stick returns NACK,
+ * so we need to send a request status for both endpoints
+ */
requestChannelState(new ChannelUID(thing.getUID(), CHANNEL_SWITCH_02));
}
requestChannelState(new ChannelUID(thing.getUID(), CHANNEL_SWITCH_01));
BRIGHTNESS_STATUS_REQUEST_DELAY_MSEC);
} else {
if (msg.isOn()) {
- // if we have not just sent a requestStatus, on ON event we send requestStatus to know current level
+ // if we have not just sent a requestStatus, on ON event we send requestStatus
+ // to know current level
long deltaStatusReq = now - lastStatusRequestSentTS;
if (deltaStatusReq > BRIGHTNESS_STATUS_REQUEST_INTERVAL_MSEC) {
logger.debug(" $BRI 'ON' is new notification from network, scheduling requestStatus...");
- // we must wait BRIGHTNESS_STATUS_REQUEST_DELAY_MSEC to be sure dimmer has reached its final level
+ // we must wait BRIGHTNESS_STATUS_REQUEST_DELAY_MSEC to be sure dimmer has
+ // reached its final level
scheduler.schedule(() -> {
requestChannelState(new ChannelUID(thing.getUID(), CHANNEL_BRIGHTNESS));
}, BRIGHTNESS_STATUS_REQUEST_DELAY_MSEC, TimeUnit.MILLISECONDS);
return;
} else {
- // otherwise we interpret this ON event as the requestStatus response event with level=1
+ // otherwise we interpret this ON event as the requestStatus response event with
+ // level=1
// so we proceed to call updateBrightnessState()
logger.debug(" $BRI 'ON' is the requestStatus response level");
}
if (brH != null) {
if (msg.isOn() || msg.isOff()) {
String channelId;
- int switchId = 0;
if (brH.isBusGateway()) {
channelId = CHANNEL_SWITCH;
} else {
WhereZigBee w = (WhereZigBee) (msg.getWhere());
if (WhereZigBee.UNIT_02.equals(w.getUnit())) {
channelId = CHANNEL_SWITCH_02;
- switchId = 1;
} else {
channelId = CHANNEL_SWITCH_01;
}
}
- int currentSt = sw[switchId];
- int newSt = (msg.isOn() ? 1 : 0);
- if (newSt != currentSt) {
- updateState(channelId, (newSt == 1 ? OnOffType.ON : OnOffType.OFF));
- sw[switchId] = newSt;
- logger.debug(" {} ONOFF CHANGED to {}", ownId, newSt);
- } else {
- logger.debug(" {} ONOFF no change", ownId);
- }
+ updateState(channelId, OnOffType.from(msg.isOn()));
} else {
logger.debug("updateOnOffState() Ignoring unsupported WHAT for thing {}. Frame={}", getThing().getUID(),
msg.getFrameValue());