use of org.openhab.core.library.types.OpenClosedType in project openhab1-addons by openhab.
the class PowerDogLocalApiBinding method internalReceiveCommand.
/**
* @{inheritDoc
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
logger.debug("internalReceiveCommand({},{}) is called!", itemName, command);
State newState = null;
// cast Interfaces
if (command instanceof OnOffType) {
newState = (OnOffType) command;
} else if (command instanceof OpenClosedType) {
newState = (OpenClosedType) command;
} else if (command instanceof PercentType) {
newState = (PercentType) command;
} else if (command instanceof DecimalType) {
newState = (DecimalType) command;
}
if (newState != null) {
eventPublisher.postUpdate(itemName, newState);
}
}
use of org.openhab.core.library.types.OpenClosedType in project openhab1-addons by openhab.
the class MCP23017Binding method handleGpioPinDigitalStateChangeEvent.
/**
* @{inheritDoc}
*/
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
GpioPin pin = event.getPin();
// Assume we are high...
OpenClosedType state = OpenClosedType.CLOSED;
if (event.getState() == PinState.LOW) {
// To err is human...
state = OpenClosedType.OPEN;
}
this.eventPublisher.postUpdate(pin.getName(), state);
logger.debug("GPIO pin state change: {} = {}", pin, state);
}
use of org.openhab.core.library.types.OpenClosedType in project openhab1-addons by openhab.
the class PowerDogLocalApiBinding method internalReceiveUpdate.
/**
* @{inheritDoc
*/
@Override
protected void internalReceiveUpdate(String itemName, State newState) {
logger.debug("internalReceiveUpdate({},{}) is called!", itemName, newState);
// cycle on all available powerdogs
for (PowerDogLocalApiBindingProvider provider : providers) {
if (!provider.providesBindingFor(itemName)) {
continue;
}
// only in case of an outbinding, this need to be handled
if (provider.getOutBindingItemNames().contains(itemName)) {
// check if item may send update already now
// time indicated in config is the minimum time between two
// updates
Long lastUpdateTimeStamp = lastUpdateMap.get(itemName);
if (lastUpdateTimeStamp == null) {
lastUpdateTimeStamp = 0L;
}
long age = System.currentTimeMillis() - lastUpdateTimeStamp;
boolean itemMayUpdate = (age >= provider.getRefreshInterval(itemName));
if (itemMayUpdate) {
// Convert new State to PowerDog set Current_Value string
String value = "0";
if (newState instanceof OnOffType) {
if (newState == OnOffType.ON) {
value = "1";
}
} else // the best solution, but it is sufficient
if (newState instanceof OpenClosedType) {
if (newState == OpenClosedType.OPEN) {
value = "1";
}
} else // see comment above
if (newState instanceof PercentType) {
value = newState.toString();
} else if (newState instanceof DecimalType) {
value = newState.toString();
}
// Get the unit serverId from the binding, and relate that
// to the config
String unit = provider.getServerId(itemName);
PowerDogLocalApiServerConfig server = serverList.get(unit);
try {
logger.debug("PowerDogLocalApi sending to PowerDog");
// Perform XML RPC call
PowerDog powerdog = (PowerDog) XmlRpcProxy.createProxy(server.url(), "", new Class[] { PowerDog.class }, false);
XmlRpcStruct response = powerdog.setLinearSensorDevice(server.password, provider.getValueId(itemName), value);
lastUpdateMap.put(itemName, System.currentTimeMillis());
logger.debug("PowerDog.setLinearSensorDevice() result: {}", response.toString());
} catch (Exception e) {
logger.warn("PowerDogLocalApi sending to PowerDog failed");
logger.warn(e.getMessage());
}
}
}
}
}
use of org.openhab.core.library.types.OpenClosedType in project openhab1-addons by openhab.
the class RFXComThermostat2Message method convertFromState.
@Override
public void convertFromState(RFXComValueSelector valueSelector, String id, Object subType, Type type, byte seqNumber) throws RFXComException {
this.subType = ((SubType) subType);
seqNbr = seqNumber;
String[] ids = id.split("\\.");
unitcode = Byte.parseByte(ids[0]);
switch(valueSelector) {
case COMMAND:
if (type instanceof OnOffType) {
command = (type == OnOffType.ON ? Commands.ON : Commands.OFF);
} else if (type instanceof OpenClosedType) {
command = (type == OpenClosedType.CLOSED ? Commands.ON : Commands.OFF);
} else {
throw new RFXComException("Can't convert " + type + " to Command");
}
break;
default:
throw new RFXComException("Can't convert " + type + " to " + valueSelector);
}
}
use of org.openhab.core.library.types.OpenClosedType in project openhab1-addons by openhab.
the class RFXComThermostat3Message method convertFromState.
@Override
public void convertFromState(RFXComValueSelector valueSelector, String id, Object subType, Type type, byte seqNumber) throws RFXComException {
this.subType = ((SubType) subType);
seqNbr = seqNumber;
String[] ids = id.split("\\.");
unitcode = Byte.parseByte(ids[0]);
switch(valueSelector) {
case COMMAND:
if (type instanceof OnOffType) {
command = (type == OnOffType.ON ? Commands.ON : Commands.OFF);
} else if (type instanceof OpenClosedType) {
command = (type == OpenClosedType.CLOSED ? Commands.ON : Commands.OFF);
} else {
throw new RFXComException("Can't convert " + type + " to Command");
}
break;
default:
throw new RFXComException("Can't convert " + type + " to " + valueSelector);
}
}
Aggregations