Search in sources :

Example 1 with RFXComException

use of org.openhab.binding.rfxcom.internal.RFXComException in project openhab1-addons by openhab.

the class RFXComLighting3Message method convertFromState.

@Override
public void convertFromState(RFXComValueSelector valueSelector, String id, Object subType, Type type, byte seqNumber) throws RFXComException {
    this.subType = ((SubType) subType);
    seqNbr = seqNumber;
    switch(valueSelector) {
        case COMMAND:
            if (type instanceof OnOffType) {
                command = (type == OnOffType.ON ? Commands.ON : Commands.OFF);
                dimmingLevel = 0;
            } else if (type instanceof DecimalType) {
                command = Commands.fromByte(((DecimalType) type).intValue());
                dimmingLevel = 0;
            } else {
                throw new RFXComException("Can't convert " + type + " to Command");
            }
            break;
        case DIMMING_LEVEL:
            if (type instanceof OnOffType) {
                command = (type == OnOffType.ON ? Commands.ON : Commands.OFF);
                dimmingLevel = 0;
            } else if (type instanceof PercentType) {
                command = Commands.DIM;
                dimmingLevel = (byte) getDimLevelFromPercentType((PercentType) type);
                if (dimmingLevel == 0) {
                    command = Commands.OFF;
                }
            } else if (type instanceof IncreaseDecreaseType) {
                command = Commands.DIM;
                // Evert: I do not know how to get previous object state...
                dimmingLevel = 5;
            } 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) DecimalType(org.openhab.core.library.types.DecimalType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) PercentType(org.openhab.core.library.types.PercentType)

Example 2 with RFXComException

use of org.openhab.binding.rfxcom.internal.RFXComException in project openhab1-addons by openhab.

the class RFXComMessageFactory method getMessageInterface.

public static RFXComMessageInterface getMessageInterface(byte[] packet) throws RFXComException {
    PacketType packetType = getPacketType(packet[1]);
    try {
        String className = messageClasses.get(packetType);
        Class<?> cl = Class.forName(classUrl + className);
        Constructor<?> c = cl.getConstructor(byte[].class);
        return (RFXComMessageInterface) c.newInstance(packet);
    } catch (ClassNotFoundException e) {
        throw new RFXComException("Message " + packetType + "(" + packet[1] + ") not implemented", e);
    } catch (Exception e) {
        throw new RFXComException(e);
    }
}
Also used : RFXComException(org.openhab.binding.rfxcom.internal.RFXComException) PacketType(org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType) RFXComException(org.openhab.binding.rfxcom.internal.RFXComException)

Example 3 with RFXComException

use of org.openhab.binding.rfxcom.internal.RFXComException in project openhab1-addons by openhab.

the class RFXComMessageFactory method getMessageInterface.

public static RFXComMessageInterface getMessageInterface(PacketType packetType) throws RFXComException {
    try {
        String className = messageClasses.get(packetType);
        Class<?> cl = Class.forName(classUrl + className);
        return (RFXComMessageInterface) cl.newInstance();
    } catch (ClassNotFoundException e) {
        throw new RFXComException("Message " + packetType + " not implemented", e);
    } catch (Exception e) {
        throw new RFXComException(e);
    }
}
Also used : RFXComException(org.openhab.binding.rfxcom.internal.RFXComException) RFXComException(org.openhab.binding.rfxcom.internal.RFXComException)

Example 4 with RFXComException

use of org.openhab.binding.rfxcom.internal.RFXComException 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 5 with RFXComException

use of org.openhab.binding.rfxcom.internal.RFXComException 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

RFXComException (org.openhab.binding.rfxcom.internal.RFXComException)5 OnOffType (org.openhab.core.library.types.OnOffType)3 OpenClosedType (org.openhab.core.library.types.OpenClosedType)2 PacketType (org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType)1 DecimalType (org.openhab.core.library.types.DecimalType)1 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)1 PercentType (org.openhab.core.library.types.PercentType)1