Search in sources :

Example 1 with SoulissT12

use of org.openhab.binding.souliss.internal.network.typicals.SoulissT12 in project openhab1-addons by openhab.

the class SoulissBinding method receiveCommand.

@Override
public /**
     * Get the souliss's typical from the hash table and send a command
     *
     * @author Tonino Fazio
     * @since 1.7.0
     */
void receiveCommand(String itemName, Command command) {
    // Get the typical defined in the hash table
    SoulissGenericTypical T = SoulissGenericBindingProvider.SoulissTypicalsRecipients.getTypicalFromItem(itemName);
    logger.info("receiveCommand - {} = {} - Typical: 0x{}", itemName, command, Integer.toHexString(T.getType()));
    switch(T.getType()) {
        case Constants.Souliss_T11:
            SoulissT11 T11 = (SoulissT11) T;
            T11.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.toString()));
            break;
        case Constants.Souliss_T12:
            SoulissT12 T12 = (SoulissT12) T;
            if (itemName.equals(T12.getsItemNameAutoModeValue())) {
                T12.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T12_Use_Of_Slot_AUTOMODE + "_" + command.toString()));
            } else if (itemName.equals(T12.getsItemNameSwitchValue())) {
                T12.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T12_Use_Of_Slot_SWITCH + "_" + command.toString()));
            }
            break;
        case Constants.Souliss_T14:
            SoulissT14 T14 = (SoulissT14) T;
            T14.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.toString()));
            break;
        case Constants.Souliss_T18:
            SoulissT18 T18 = (SoulissT18) T;
            T18.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.toString()));
            break;
        case Constants.Souliss_T16:
            SoulissT16 T16 = (SoulissT16) T;
            String cmd = command.getClass().getSimpleName();
            if (cmd.equals(Constants.Openhab_RGB_TYPE)) {
                String[] HSB = command.toString().split(",");
                short[] RGB = HSBtoRGB(Float.parseFloat(HSB[0]), Float.parseFloat(HSB[1]), Float.parseFloat(HSB[2]));
                T16.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.getClass().getSimpleName()), RGB[0], RGB[1], RGB[2]);
            } else {
                T16.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.toString()));
            }
            break;
        case Constants.Souliss_T19:
            SoulissT19 T19 = (SoulissT19) T;
            if (command instanceof PercentType) {
                int percentToShort = (((PercentType) command).shortValue() * 254 / 100);
                T19.commandSEND(Constants.Souliss_T1n_Set, Short.parseShort(String.valueOf(percentToShort)));
            } else if (command instanceof DecimalType) {
                int decimalToShort = (((DecimalType) command).shortValue() * 254 / 100);
                T19.commandSEND(Constants.Souliss_T1n_Set, Short.parseShort(String.valueOf(decimalToShort)));
            } else {
                T19.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.toString()));
            }
            break;
        case Constants.Souliss_T21:
            SoulissT21 T21 = (SoulissT21) T;
            T21.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.toString()));
            break;
        case Constants.Souliss_T22:
            SoulissT22 T22 = (SoulissT22) T;
            T22.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), command.toString()));
            break;
        case Constants.Souliss_T31:
            SoulissT31 T31 = (SoulissT31) T;
            // Setpoint
            if (itemName.equals(T31.getsItemNameSetpointValue())) {
                if (command instanceof DecimalType) {
                    int uu = HalfFloatUtils.fromFloat(((DecimalType) command).floatValue());
                    byte B2 = (byte) (uu >> 8);
                    byte B1 = (byte) uu;
                    // setpoint command
                    T31.CommandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_SETPOINT_COMMAND), B1, B2);
                }
            } else // Set As Measured
            if (itemName.equals(T31.setAsMeasured.getName())) {
                T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_SETASMEASURED + "_" + command.toString()));
            } else if (itemName.equals(T31.heatingCoolingModeValue.getName())) {
                T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_HEATING_COOLING + "_" + command.toString()));
            } else if (itemName.equals(T31.fanAutoMode.getName())) {
                T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_FANAUTOMODE + "_" + command.toString()));
            } else if (itemName.equals(T31.fanOff.getName())) {
                T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_FANOFF + "_" + command.toString()));
            } else if (itemName.equals(T31.fanLow.getName())) {
                T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_FANLOW + "_" + command.toString()));
            } else if (itemName.equals(T31.fanMed.getName())) {
                T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_FANMED + "_" + command.toString()));
            } else if (itemName.equals(T31.fanHigh.getName())) {
                T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_FANHIGH + "_" + command.toString()));
            } else if (itemName.equals(T31.power.getName())) {
                T31.commandSEND(StateTraslator.commandsOHtoSOULISS(T.getType(), Constants.Souliss_T31_Use_Of_Slot_POWER + "_" + command.toString()));
            }
            break;
        default:
            logger.debug("Typical Unknown");
    }
}
Also used : SoulissT21(org.openhab.binding.souliss.internal.network.typicals.SoulissT21) SoulissT31(org.openhab.binding.souliss.internal.network.typicals.SoulissT31) SoulissT12(org.openhab.binding.souliss.internal.network.typicals.SoulissT12) SoulissT11(org.openhab.binding.souliss.internal.network.typicals.SoulissT11) SoulissT22(org.openhab.binding.souliss.internal.network.typicals.SoulissT22) PercentType(org.openhab.core.library.types.PercentType) SoulissT18(org.openhab.binding.souliss.internal.network.typicals.SoulissT18) DecimalType(org.openhab.core.library.types.DecimalType) SoulissT19(org.openhab.binding.souliss.internal.network.typicals.SoulissT19) SoulissT14(org.openhab.binding.souliss.internal.network.typicals.SoulissT14) SoulissT16(org.openhab.binding.souliss.internal.network.typicals.SoulissT16) SoulissGenericTypical(org.openhab.binding.souliss.internal.network.typicals.SoulissGenericTypical)

Example 2 with SoulissT12

use of org.openhab.binding.souliss.internal.network.typicals.SoulissT12 in project openhab1-addons by openhab.

the class SoulissGenericBindingProvider method processBindingConfiguration.

/**
     * This method create typicals and add it to hastable
     * 
     * @author Tonino Fazio
     * @since 1.7.0
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    // Create Souliss Typicals
    //
    // ...from wiki of Dario De Maio
    // In Souliss the logics that drive your lights, curtains, LED, and
    // others are pre-configured into so called Typicals. A Typical is a
    // logic with a predefined set of inputs and outputs and a know
    // behavior, are used to standardize the user interface and have a
    // configuration-less behavior.
    final String itemName = item.getName();
    logger.trace("Starting to load Souliss config for item {}", itemName);
    super.processBindingConfiguration(context, item, bindingConfig);
    String[] sNameArray = bindingConfig.split("\\:");
    String sTypical = sNameArray[0];
    int iNodeID = Integer.parseInt(sNameArray[1]);
    int iSlot = Integer.parseInt(sNameArray[2]);
    byte iBit = 0;
    String sUseSlot = "";
    // parametro
    if (sNameArray.length > 3) {
        if ((StateTraslator.stringToSOULISSTypicalCode(sTypical) == Constants.Souliss_T31) || (StateTraslator.stringToSOULISSTypicalCode(sTypical) == Constants.Souliss_T12)) {
            sUseSlot = sNameArray[3];
        } else {
            iBit = Byte.parseByte(sNameArray[3]);
        }
    }
    String sNote = item.getClass().getSimpleName();
    SoulissGenericTypical soulissTypicalNew = null;
    // Tipico Souliss
    if ((StateTraslator.stringToSOULISSTypicalCode(sTypical) == Constants.Souliss_T31) || (StateTraslator.stringToSOULISSTypicalCode(sTypical) == Constants.Souliss_T12)) {
        soulissTypicalNew = SoulissTypicalsRecipients.getTypicalFromAddress(iNodeID, iSlot, 0);
        // creazione tipico, solo se non si tratta di un T31 al quale è stato aggiunto un parametro
        if (soulissTypicalNew == null) {
            soulissTypicalNew = TypicalFactory.getClass(StateTraslator.stringToSOULISSTypicalCode(sTypical), SoulissNetworkParameter.datagramsocket, SoulissNetworkParameter.IPAddressOnLAN, iNodeID, iSlot, sNote, iBit, sUseSlot);
        }
        if (soulissTypicalNew != null) {
            // in base al campo use slot inserisco nel tipico il nome item di riferimento
            switch(sUseSlot) {
                case Constants.Souliss_T12_Use_Of_Slot_AUTOMODE:
                    ((SoulissT12) soulissTypicalNew).setsItemNameAutoModeValue(item.getName());
                    ((SoulissT12) soulissTypicalNew).setsItemTypeAutoModeValue(sNote);
                    break;
                case Constants.Souliss_T12_Use_Of_Slot_SWITCH:
                    ((SoulissT12) soulissTypicalNew).setsItemNameSwitchValue(item.getName());
                    ((SoulissT12) soulissTypicalNew).setsItemTypeSwitchValue(sNote);
                    break;
                case Constants.Souliss_T31_Use_Of_Slot_SETPOINT:
                    ((SoulissT31) soulissTypicalNew).setsItemNameSetpointValue(item.getName());
                    ((SoulissT31) soulissTypicalNew).setsItemTypeSetpointValue(sNote);
                    break;
                case Constants.Souliss_T31_Use_Of_Slot_MEASURED:
                    ((SoulissT31) soulissTypicalNew).setsItemNameMeasuredValue(item.getName());
                    ((SoulissT31) soulissTypicalNew).setsItemTypeMeasuredValue(sNote);
                    break;
                case Constants.Souliss_T31_Use_Of_Slot_SETASMEASURED:
                    ((SoulissT31) soulissTypicalNew).setAsMeasured.setName(item.getName());
                    ((SoulissT31) soulissTypicalNew).setAsMeasured.setNote(sNote);
                    break;
                case Constants.Souliss_T31_Use_Of_Slot_HEATING:
                    ((SoulissT31) soulissTypicalNew).heating.setName(item.getName());
                    ((SoulissT31) soulissTypicalNew).heating.setNote(sNote);
                    break;
                case Constants.Souliss_T31_Use_Of_Slot_COOLING:
                    ((SoulissT31) soulissTypicalNew).cooling.setName(item.getName());
                    ((SoulissT31) soulissTypicalNew).cooling.setNote(sNote);
                    break;
                case Constants.Souliss_T31_Use_Of_Slot_FANOFF:
                    ((SoulissT31) soulissTypicalNew).fanOff.setName(item.getName());
                    ((SoulissT31) soulissTypicalNew).fanOff.setNote(sNote);
                    break;
                case Constants.Souliss_T31_Use_Of_Slot_FANLOW:
                    ((SoulissT31) soulissTypicalNew).fanLow.setName(item.getName());
                    ((SoulissT31) soulissTypicalNew).fanLow.setNote(sNote);
                    break;
                case Constants.Souliss_T31_Use_Of_Slot_FANMED:
                    ((SoulissT31) soulissTypicalNew).fanMed.setName(item.getName());
                    ((SoulissT31) soulissTypicalNew).fanMed.setNote(sNote);
                    break;
                case Constants.Souliss_T31_Use_Of_Slot_FANHIGH:
                    ((SoulissT31) soulissTypicalNew).fanHigh.setName(item.getName());
                    ((SoulissT31) soulissTypicalNew).fanHigh.setNote(sNote);
                    break;
                case Constants.Souliss_T31_Use_Of_Slot_HEATING_COOLING:
                    ((SoulissT31) soulissTypicalNew).heatingCoolingModeValue.setName(item.getName());
                    ((SoulissT31) soulissTypicalNew).heatingCoolingModeValue.setNote(sNote);
                    break;
                case Constants.Souliss_T31_Use_Of_Slot_FANAUTOMODE:
                    ((SoulissT31) soulissTypicalNew).fanAutoMode.setName(item.getName());
                    ((SoulissT31) soulissTypicalNew).fanAutoMode.setNote(sNote);
                    break;
                case Constants.Souliss_T31_Use_Of_Slot_POWER:
                    ((SoulissT31) soulissTypicalNew).power.setName(item.getName());
                    ((SoulissT31) soulissTypicalNew).power.setNote(sNote);
                    break;
            }
            logger.info("Add parameter to T31/T12 : " + sUseSlot);
        }
    }
    // creazione tipico, solo se non si tratta di un T31 / T12 al quale è stato aggiunto un parametro
    if (soulissTypicalNew == null) {
        soulissTypicalNew = TypicalFactory.getClass(StateTraslator.stringToSOULISSTypicalCode(sTypical), SoulissNetworkParameter.datagramsocket, SoulissNetworkParameter.IPAddressOnLAN, iNodeID, iSlot, sNote, iBit, sUseSlot);
    }
    if (soulissTypicalNew != null) {
        SoulissTypicalsRecipients.addTypical(item.getName(), soulissTypicalNew);
        SoulissNetworkParameter.nodes = SoulissTypicalsRecipients.getNodeNumbers();
    }
}
Also used : SoulissT31(org.openhab.binding.souliss.internal.network.typicals.SoulissT31) SoulissT12(org.openhab.binding.souliss.internal.network.typicals.SoulissT12) SoulissGenericTypical(org.openhab.binding.souliss.internal.network.typicals.SoulissGenericTypical)

Aggregations

SoulissGenericTypical (org.openhab.binding.souliss.internal.network.typicals.SoulissGenericTypical)2 SoulissT12 (org.openhab.binding.souliss.internal.network.typicals.SoulissT12)2 SoulissT31 (org.openhab.binding.souliss.internal.network.typicals.SoulissT31)2 SoulissT11 (org.openhab.binding.souliss.internal.network.typicals.SoulissT11)1 SoulissT14 (org.openhab.binding.souliss.internal.network.typicals.SoulissT14)1 SoulissT16 (org.openhab.binding.souliss.internal.network.typicals.SoulissT16)1 SoulissT18 (org.openhab.binding.souliss.internal.network.typicals.SoulissT18)1 SoulissT19 (org.openhab.binding.souliss.internal.network.typicals.SoulissT19)1 SoulissT21 (org.openhab.binding.souliss.internal.network.typicals.SoulissT21)1 SoulissT22 (org.openhab.binding.souliss.internal.network.typicals.SoulissT22)1 DecimalType (org.openhab.core.library.types.DecimalType)1 PercentType (org.openhab.core.library.types.PercentType)1