forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lutron] Add sysvar handler for HomeWorks QS (openhab#8132)
* Add new sysvar thing * Add internal support for SYSVAR and SHADEGRP protocol commands * Enable sysvar monitoring in bridge when needed Signed-off-by: Bob Adair <[email protected]>
- Loading branch information
Showing
9 changed files
with
253 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...binding.lutron/src/main/java/org/openhab/binding/lutron/internal/config/SysvarConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) 2010-2020 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.lutron.internal.config; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
/** | ||
* Configuration settings for a {@link org.openhab.binding.lutron.internal.handler.SysvarHandler}. | ||
* | ||
* @author Bob Adair - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class SysvarConfig { | ||
public int integrationId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...nding.lutron/src/main/java/org/openhab/binding/lutron/internal/handler/SysvarHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/** | ||
* Copyright (c) 2010-2020 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.lutron.internal.handler; | ||
|
||
import static org.openhab.binding.lutron.internal.LutronBindingConstants.CHANNEL_VARSTATE; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.eclipse.smarthome.core.library.types.DecimalType; | ||
import org.eclipse.smarthome.core.thing.Bridge; | ||
import org.eclipse.smarthome.core.thing.ChannelUID; | ||
import org.eclipse.smarthome.core.thing.Thing; | ||
import org.eclipse.smarthome.core.thing.ThingStatus; | ||
import org.eclipse.smarthome.core.thing.ThingStatusDetail; | ||
import org.eclipse.smarthome.core.types.Command; | ||
import org.openhab.binding.lutron.internal.config.SysvarConfig; | ||
import org.openhab.binding.lutron.internal.protocol.LutronCommandType; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Handler responsible for getting/setting sysvar state for HomeWorks QS | ||
* | ||
* @author Bob Adair - Initial contribution | ||
* | ||
*/ | ||
@NonNullByDefault | ||
public class SysvarHandler extends LutronHandler { | ||
private static final Integer ACTION_GETSETSYSVAR = 1; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(SysvarHandler.class); | ||
|
||
private @Nullable SysvarConfig config; | ||
private int integrationId; | ||
|
||
public SysvarHandler(Thing thing) { | ||
super(thing); | ||
} | ||
|
||
@Override | ||
public int getIntegrationId() { | ||
SysvarConfig config = this.config; | ||
if (config != null) { | ||
return config.integrationId; | ||
} else { | ||
throw new IllegalStateException("handler not initialized"); | ||
} | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
SysvarConfig config = getThing().getConfiguration().as(SysvarConfig.class); | ||
this.config = config; | ||
if (config.integrationId <= 0) { | ||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "No integrationId configured"); | ||
} else { | ||
integrationId = config.integrationId; | ||
logger.debug("Initializing Sysvar handler for integration ID {}", integrationId); | ||
initDeviceState(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void initDeviceState() { | ||
logger.debug("Initializing handler state for sysvar id {}", integrationId); | ||
Bridge bridge = getBridge(); | ||
if (bridge == null) { | ||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "No bridge configured"); | ||
} else if (bridge.getStatus() == ThingStatus.ONLINE) { | ||
updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.NONE, "Awaiting initial response"); | ||
querySysvar(ACTION_GETSETSYSVAR); // handleUpdate() will set thing status to online when response arrives | ||
} else { | ||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE); | ||
} | ||
} | ||
|
||
@Override | ||
public void channelLinked(ChannelUID channelUID) { | ||
if (channelUID.getId().equals(CHANNEL_VARSTATE)) { | ||
// Refresh state when new item is linked. | ||
querySysvar(ACTION_GETSETSYSVAR); | ||
} | ||
} | ||
|
||
@Override | ||
public void handleCommand(ChannelUID channelUID, Command command) { | ||
if (channelUID.getId().equals(CHANNEL_VARSTATE)) { | ||
if (command instanceof Number) { | ||
int state = ((Number) command).intValue(); | ||
sysvar(ACTION_GETSETSYSVAR, state); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void handleUpdate(LutronCommandType type, String... parameters) { | ||
if (type == LutronCommandType.SYSVAR && parameters.length > 1 | ||
&& ACTION_GETSETSYSVAR.toString().equals(parameters[0])) { | ||
BigDecimal state = new BigDecimal(parameters[1]); | ||
if (getThing().getStatus() == ThingStatus.UNKNOWN) { | ||
updateStatus(ThingStatus.ONLINE); | ||
} | ||
updateState(CHANNEL_VARSTATE, new DecimalType(state)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.