Search in sources :

Example 1 with FatekException

use of org.simplify4u.jfatek.FatekException in project openhab1-addons by openhab.

the class FatekColorItem method valueForIncreaseDecrease.

private HSBType valueForIncreaseDecrease(FatekPLC fatekPLC, Command command) throws CommandException {
    HSBType val = null;
    try {
        // first read current state
        Map<Reg, RegValue> regVal = new FatekReadMixDataCmd(fatekPLC, reg1, reg2, reg3).send();
        HSBType currentVal = reg2HSB(regVal.get(reg1), regVal.get(reg1), regVal.get(reg3));
        int b = currentVal.getBrightness().intValue();
        if (IncreaseDecreaseType.INCREASE.equals(command)) {
            b = Math.min(b + step, 100);
        } else if (IncreaseDecreaseType.DECREASE.equals(command)) {
            b = Math.max(b - step, 0);
        } else {
            throw new CommandException(this, command, "Unknown IncreaseDecrease type");
        }
        if (b != currentVal.getBrightness().intValue()) {
            val = new HSBType(currentVal.getHue(), currentVal.getSaturation(), new PercentType(b));
        }
    } catch (FatekIOException | FatekException e) {
        throw new CommandException(this, command, e);
    }
    return val;
}
Also used : FatekIOException(org.simplify4u.jfatek.io.FatekIOException) FatekReadMixDataCmd(org.simplify4u.jfatek.FatekReadMixDataCmd) Reg(org.simplify4u.jfatek.registers.Reg) FatekException(org.simplify4u.jfatek.FatekException) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType) RegValue(org.simplify4u.jfatek.registers.RegValue)

Example 2 with FatekException

use of org.simplify4u.jfatek.FatekException in project openhab1-addons by openhab.

the class FatekNumberItem method command.

@Override
public void command(FatekPLC fatekPLC, Command command) throws CommandException {
    if (command instanceof DecimalType) {
        BigDecimal val = ((DecimalType) command).toBigDecimal();
        if (factor != null) {
            val = val.divide(factor);
        }
        try {
            FatekWriteMixDataCmd cmd = new FatekWriteMixDataCmd(fatekPLC);
            if (floatValue) {
                cmd.addReg(reg1, val.floatValue());
            } else {
                cmd.addReg(reg1, val.longValue());
            }
            cmd.send();
        } catch (FatekIOException | FatekException e) {
            throw new CommandException(this, command, e);
        }
    } else {
        throw new UnsupportedCommandException(this, command);
    }
}
Also used : FatekWriteMixDataCmd(org.simplify4u.jfatek.FatekWriteMixDataCmd) FatekIOException(org.simplify4u.jfatek.io.FatekIOException) FatekException(org.simplify4u.jfatek.FatekException) DecimalType(org.openhab.core.library.types.DecimalType) BigDecimal(java.math.BigDecimal)

Example 3 with FatekException

use of org.simplify4u.jfatek.FatekException in project openhab1-addons by openhab.

the class FatekRollershutterItem method command.

@Override
public void command(FatekPLC fatekPLC, Command command) throws CommandException {
    boolean up;
    boolean down;
    if (StopMoveType.STOP.equals(command)) {
        up = false;
        down = false;
    } else if (UpDownType.UP.equals(command)) {
        up = true;
        down = false;
    } else if (UpDownType.DOWN.equals(command)) {
        up = false;
        down = true;
    } else {
        throw new UnsupportedCommandException(this, command);
    }
    try {
        FatekWriteMixDataCmd cmd = new FatekWriteMixDataCmd(fatekPLC);
        cmd.addReg(reg2, up);
        cmd.addReg(reg3, down);
        cmd.send();
    } catch (FatekIOException | FatekException e) {
        throw new CommandException(this, command, e);
    }
}
Also used : FatekWriteMixDataCmd(org.simplify4u.jfatek.FatekWriteMixDataCmd) FatekIOException(org.simplify4u.jfatek.io.FatekIOException) FatekException(org.simplify4u.jfatek.FatekException)

Example 4 with FatekException

use of org.simplify4u.jfatek.FatekException in project openhab1-addons by openhab.

the class FatekColorItem method command.

@Override
public void command(FatekPLC fatekPLC, Command command) throws CommandException {
    try {
        final HSBType val;
        if (command instanceof OnOffType) {
            val = valueForOnOff(fatekPLC, command);
        } else if (command instanceof IncreaseDecreaseType) {
            val = valueForIncreaseDecrease(fatekPLC, command);
        } else if (command instanceof HSBType) {
            val = (HSBType) command;
        } else {
            throw new UnsupportedCommandException(this, command);
        }
        if (val != null) {
            int v1;
            int v2;
            int v3;
            if (isColorRGB) {
                Color c = val.toColor();
                v1 = c.getRed();
                v2 = c.getGreen();
                v3 = c.getBlue();
            } else {
                v1 = val.getHue().intValue();
                v2 = val.getSaturation().intValue();
                v3 = val.getBrightness().intValue();
            }
            FatekWriteMixDataCmd cmd = new FatekWriteMixDataCmd(fatekPLC);
            cmd.addReg(reg1, v1);
            cmd.addReg(reg2, v2);
            cmd.addReg(reg3, v3);
            cmd.send();
        }
    } catch (FatekIOException | FatekException e) {
        throw new CommandException(this, command, e);
    }
}
Also used : FatekWriteMixDataCmd(org.simplify4u.jfatek.FatekWriteMixDataCmd) FatekIOException(org.simplify4u.jfatek.io.FatekIOException) OnOffType(org.openhab.core.library.types.OnOffType) Color(java.awt.Color) FatekException(org.simplify4u.jfatek.FatekException) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) HSBType(org.openhab.core.library.types.HSBType)

Example 5 with FatekException

use of org.simplify4u.jfatek.FatekException in project openhab1-addons by openhab.

the class FatekSwitchItem method command.

@Override
public void command(FatekPLC fatekPLC, Command command) throws CommandException {
    boolean value;
    if (OnOffType.ON.equals(command)) {
        value = true;
    } else if (OnOffType.OFF.equals(command)) {
        value = false;
    } else {
        throw new UnsupportedCommandException(this, command);
    }
    Reg reg;
    if (reg2 == null) {
        if (negate1) {
            value = !value;
        }
        reg = reg1;
    } else {
        value = !negate2;
        reg = reg2;
    }
    try {
        new FatekWriteMixDataCmd(fatekPLC).addReg(reg, value).send();
    } catch (FatekIOException | FatekException e) {
        throw new CommandException(this, command, e);
    }
}
Also used : FatekWriteMixDataCmd(org.simplify4u.jfatek.FatekWriteMixDataCmd) FatekIOException(org.simplify4u.jfatek.io.FatekIOException) Reg(org.simplify4u.jfatek.registers.Reg) FatekException(org.simplify4u.jfatek.FatekException)

Aggregations

FatekException (org.simplify4u.jfatek.FatekException)5 FatekIOException (org.simplify4u.jfatek.io.FatekIOException)5 FatekWriteMixDataCmd (org.simplify4u.jfatek.FatekWriteMixDataCmd)4 HSBType (org.openhab.core.library.types.HSBType)2 Reg (org.simplify4u.jfatek.registers.Reg)2 Color (java.awt.Color)1 BigDecimal (java.math.BigDecimal)1 DecimalType (org.openhab.core.library.types.DecimalType)1 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)1 OnOffType (org.openhab.core.library.types.OnOffType)1 PercentType (org.openhab.core.library.types.PercentType)1 FatekReadMixDataCmd (org.simplify4u.jfatek.FatekReadMixDataCmd)1 RegValue (org.simplify4u.jfatek.registers.RegValue)1