Search in sources :

Example 6 with OpenClosedType

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);
    }
}
Also used : OnOffType(org.openhab.core.library.types.OnOffType) State(org.openhab.core.types.State) OpenClosedType(org.openhab.core.library.types.OpenClosedType) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType)

Example 7 with OpenClosedType

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);
}
Also used : GpioPin(com.pi4j.io.gpio.GpioPin) OpenClosedType(org.openhab.core.library.types.OpenClosedType)

Example 8 with OpenClosedType

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());
                }
            }
        }
    }
}
Also used : PowerDogLocalApiBindingProvider(org.openhab.binding.powerdoglocalapi.PowerDogLocalApiBindingProvider) PercentType(org.openhab.core.library.types.PercentType) MalformedURLException(java.net.MalformedURLException) OnOffType(org.openhab.core.library.types.OnOffType) OpenClosedType(org.openhab.core.library.types.OpenClosedType) DecimalType(org.openhab.core.library.types.DecimalType) XmlRpcStruct(redstone.xmlrpc.XmlRpcStruct)

Example 9 with OpenClosedType

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);
    }
}
Also used : RFXComException(org.openhab.binding.rfxcom.internal.RFXComException) OnOffType(org.openhab.core.library.types.OnOffType) OpenClosedType(org.openhab.core.library.types.OpenClosedType)

Example 10 with OpenClosedType

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);
    }
}
Also used : RFXComException(org.openhab.binding.rfxcom.internal.RFXComException) OnOffType(org.openhab.core.library.types.OnOffType) OpenClosedType(org.openhab.core.library.types.OpenClosedType)

Aggregations

OpenClosedType (org.openhab.core.library.types.OpenClosedType)12 OnOffType (org.openhab.core.library.types.OnOffType)11 DecimalType (org.openhab.core.library.types.DecimalType)7 PercentType (org.openhab.core.library.types.PercentType)5 UpDownType (org.openhab.core.library.types.UpDownType)4 DateTimeType (org.openhab.core.library.types.DateTimeType)3 StringType (org.openhab.core.library.types.StringType)3 RFXComException (org.openhab.binding.rfxcom.internal.RFXComException)2 HSBType (org.openhab.core.library.types.HSBType)2 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)2 GpioPin (com.pi4j.io.gpio.GpioPin)1 Color (java.awt.Color)1 MalformedURLException (java.net.MalformedURLException)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 ModbusRequest (net.wimpi.modbus.msg.ModbusRequest)1 WriteMultipleRegistersRequest (net.wimpi.modbus.msg.WriteMultipleRegistersRequest)1 WriteSingleRegisterRequest (net.wimpi.modbus.msg.WriteSingleRegisterRequest)1 InputRegister (net.wimpi.modbus.procimg.InputRegister)1 Register (net.wimpi.modbus.procimg.Register)1