Search in sources :

Example 6 with HSBType

use of org.openhab.core.library.types.HSBType in project openhab1-addons by openhab.

the class JointSpaceBinding method internalReceiveCommand.

/**
     * @{inheritDoc Processes the commands and maps them to jointspace commands
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    if (itemName != null && !this.providers.isEmpty()) {
        JointSpaceBindingProvider provider = this.providers.iterator().next();
        if (provider == null) {
            logger.warn("Doesn't find matching binding provider [itemName={}, command={}]", itemName, command);
            return;
        }
        logger.debug("Received command (item='{}', state='{}', class='{}')", new Object[] { itemName, command.toString(), command.getClass().toString() });
        String tvCommandString = null;
        // first check if we can translate the command directly
        tvCommandString = provider.getTVCommand(itemName, command.toString());
        // if not try some special notations
        if (tvCommandString == null) {
            if (command instanceof HSBType) {
                tvCommandString = provider.getTVCommand(itemName, "HSB");
            } else if (command instanceof DecimalType) {
                tvCommandString = provider.getTVCommand(itemName, "DEC");
            }
            if (tvCommandString == null) {
                tvCommandString = provider.getTVCommand(itemName, "*");
            }
        }
        if (tvCommandString == null) {
            logger.warn("Unrecognized command \"{}\"", command.toString());
            return;
        }
        if (tvCommandString.contains("key")) {
            logger.debug("Found a Key command: " + tvCommandString);
            String[] commandlist = tvCommandString.split("\\.");
            if (commandlist.length != 2) {
                logger.warn("wrong number of arguments for key command \"{}\". Should be key.X", tvCommandString);
                return;
            }
            String key = commandlist[1];
            sendTVCommand(key, ip + ":" + port);
        } else if (tvCommandString.contains("ambilight")) {
            logger.debug("Found an ambilight command: {}", tvCommandString);
            String[] commandlist = tvCommandString.split("\\.");
            String[] layer = command2LayerString(tvCommandString);
            if (commandlist.length < 2) {
                logger.warn("wrong number of arguments for ambilight command \"{}\". Should be at least ambilight.color, ambilight.mode.X, etc...", tvCommandString);
                return;
            }
            if (commandlist[1].contains("color")) {
                setAmbilightColor(ip + ":" + port, command, layer);
            } else if (commandlist[1].contains("mode")) {
                if (commandlist.length != 3) {
                    logger.warn("wrong number of arguments for ambilight.mode command \"{}\". Should be ambilight.mode.internal, ambilight.mode.manual, ambilight.mode.expert", tvCommandString);
                    return;
                }
                setAmbilightMode(commandlist[2], ip + ":" + port);
            }
        } else if (tvCommandString.contains("volume")) {
            logger.debug("Found a Volume command: {}", tvCommandString);
            sendVolume(ip + ":" + port, command);
        } else if (tvCommandString.contains("source")) {
            logger.debug("Found a Source command: {}", tvCommandString);
            String[] commandlist = tvCommandString.split("\\.");
            if (commandlist.length < 2) {
                logger.warn("wrong number of arguments for source command \"{}\". Should be at least mode.X...", tvCommandString);
                return;
            }
            sendSource(ip + ":" + port, commandlist[1]);
        } else {
            logger.warn("Unrecognized tv command \"{}\". Only key.X or ambilight[].X is supported", tvCommandString);
            return;
        }
    }
}
Also used : DecimalType(org.openhab.core.library.types.DecimalType) HSBType(org.openhab.core.library.types.HSBType) JointSpaceBindingProvider(org.openhab.binding.jointspace.JointSpaceBindingProvider)

Example 7 with HSBType

use of org.openhab.core.library.types.HSBType in project openhab1-addons by openhab.

the class JpaHistoricItem method fromPersistedItem.

/**
     * Converts the string value of the persisted item to the state of a HistoricItem.
     * 
     * @param pItem the persisted JpaPersistentItem
     * @param item the source reference Item
     * @return historic item
     */
public static HistoricItem fromPersistedItem(JpaPersistentItem pItem, Item item) {
    State state;
    if (item instanceof NumberItem) {
        state = new DecimalType(Double.valueOf(pItem.getValue()));
    } else if (item instanceof DimmerItem) {
        state = new PercentType(Integer.valueOf(pItem.getValue()));
    } else if (item instanceof SwitchItem) {
        state = OnOffType.valueOf(pItem.getValue());
    } else if (item instanceof ContactItem) {
        state = OpenClosedType.valueOf(pItem.getValue());
    } else if (item instanceof RollershutterItem) {
        state = PercentType.valueOf(pItem.getValue());
    } else if (item instanceof ColorItem) {
        state = new HSBType(pItem.getValue());
    } else if (item instanceof DateTimeItem) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date(Long.valueOf(pItem.getValue())));
        state = new DateTimeType(cal);
    } else if (item instanceof LocationItem) {
        PointType pType = null;
        String[] comps = pItem.getValue().split(";");
        if (comps.length >= 2) {
            pType = new PointType(new DecimalType(comps[0]), new DecimalType(comps[1]));
            if (comps.length == 3) {
                pType.setAltitude(new DecimalType(comps[2]));
            }
        }
        state = pType;
    } else if (item instanceof CallItem) {
        state = new CallType(pItem.getValue());
    } else {
        state = new StringType(pItem.getValue());
    }
    return new JpaHistoricItem(item.getName(), state, pItem.getTimestamp());
}
Also used : LocationItem(org.openhab.core.library.items.LocationItem) StringType(org.openhab.core.library.types.StringType) ContactItem(org.openhab.core.library.items.ContactItem) Calendar(java.util.Calendar) CallType(org.openhab.library.tel.types.CallType) ColorItem(org.openhab.core.library.items.ColorItem) PercentType(org.openhab.core.library.types.PercentType) DateTimeItem(org.openhab.core.library.items.DateTimeItem) Date(java.util.Date) NumberItem(org.openhab.core.library.items.NumberItem) DateTimeType(org.openhab.core.library.types.DateTimeType) State(org.openhab.core.types.State) DimmerItem(org.openhab.core.library.items.DimmerItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) DecimalType(org.openhab.core.library.types.DecimalType) PointType(org.openhab.core.library.types.PointType) CallItem(org.openhab.library.tel.items.CallItem) HSBType(org.openhab.core.library.types.HSBType) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 8 with HSBType

use of org.openhab.core.library.types.HSBType in project openhab1-addons by openhab.

the class AbstractDynamoDBItem method asHistoricItem.

/*
     * (non-Javadoc)
     *
     * @see org.openhab.persistence.dynamodb.internal.DynamoItem#asHistoricItem(org.openhab.core.items.Item)
     */
@Override
public HistoricItem asHistoricItem(final Item item) {
    final State[] state = new State[1];
    accept(new DynamoDBItemVisitor() {

        @Override
        public void visit(DynamoDBStringItem dynamoStringItem) {
            if (item instanceof ColorItem) {
                state[0] = new HSBType(dynamoStringItem.getState());
            } else if (item instanceof LocationItem) {
                state[0] = new PointType(dynamoStringItem.getState());
            } else if (item instanceof DateTimeItem) {
                Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
                try {
                    cal.setTime(DATEFORMATTER.parse(dynamoStringItem.getState()));
                } catch (ParseException e) {
                    LOGGER.error("Failed to parse {} as date. Outputting UNDEF instead", dynamoStringItem.getState());
                    state[0] = UnDefType.UNDEF;
                }
                state[0] = new DateTimeType(cal);
            } else if (dynamoStringItem.getState().equals(UNDEFINED_PLACEHOLDER)) {
                state[0] = UnDefType.UNDEF;
            } else if (item instanceof CallItem) {
                String parts = dynamoStringItem.getState();
                String[] strings = parts.split("##");
                String dest = strings[0];
                String orig = strings[1];
                state[0] = new CallType(orig, dest);
            } else {
                state[0] = new StringType(dynamoStringItem.getState());
            }
        }

        @Override
        public void visit(DynamoDBBigDecimalItem dynamoBigDecimalItem) {
            if (item instanceof NumberItem) {
                state[0] = new DecimalType(dynamoBigDecimalItem.getState());
            } else if (item instanceof DimmerItem) {
                state[0] = new PercentType(dynamoBigDecimalItem.getState());
            } else if (item instanceof SwitchItem) {
                state[0] = dynamoBigDecimalItem.getState().compareTo(BigDecimal.ONE) == 0 ? OnOffType.ON : OnOffType.OFF;
            } else if (item instanceof ContactItem) {
                state[0] = dynamoBigDecimalItem.getState().compareTo(BigDecimal.ONE) == 0 ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
            } else if (item instanceof RollershutterItem) {
                state[0] = new PercentType(dynamoBigDecimalItem.getState());
            } else {
                LOGGER.warn("Not sure how to convert big decimal item {} to type {}. Using StringType as fallback", dynamoBigDecimalItem.getName(), item.getClass());
                state[0] = new StringType(dynamoBigDecimalItem.getState().toString());
            }
        }
    });
    return new DynamoDBHistoricItem(getName(), state[0], getTime());
}
Also used : LocationItem(org.openhab.core.library.items.LocationItem) StringType(org.openhab.core.library.types.StringType) CallType(org.openhab.library.tel.types.CallType) ColorItem(org.openhab.core.library.items.ColorItem) DateTimeItem(org.openhab.core.library.items.DateTimeItem) DimmerItem(org.openhab.core.library.items.DimmerItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) HSBType(org.openhab.core.library.types.HSBType) SwitchItem(org.openhab.core.library.items.SwitchItem) Calendar(java.util.Calendar) ContactItem(org.openhab.core.library.items.ContactItem) PercentType(org.openhab.core.library.types.PercentType) NumberItem(org.openhab.core.library.items.NumberItem) DateTimeType(org.openhab.core.library.types.DateTimeType) State(org.openhab.core.types.State) PointType(org.openhab.core.library.types.PointType) DecimalType(org.openhab.core.library.types.DecimalType) CallItem(org.openhab.library.tel.items.CallItem) ParseException(java.text.ParseException)

Example 9 with HSBType

use of org.openhab.core.library.types.HSBType in project openhab1-addons by openhab.

the class OpenhabHSBData method getCommandValue.

@Override
public HSBType getCommandValue() {
    DecimalType h = new DecimalType(data.getHue());
    PercentType s = new PercentType((int) data.getSaturation());
    PercentType b = new PercentType((int) data.getBrightness());
    return new HSBType(h, s, b);
}
Also used : DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType)

Example 10 with HSBType

use of org.openhab.core.library.types.HSBType in project openhab1-addons by openhab.

the class ItemStateRequestProcessor method getState.

private StateTransformable getState(Item item) {
    StateTransformable state = null;
    if (item.getState() instanceof HSBType) {
        HSBType hsb = (HSBType) item.getState();
        state = new HSBData(hsb.getHue().longValue(), hsb.getHue().longValue(), hsb.getHue().longValue());
    } else if (item.getState() instanceof DateTimeType) {
        DateTimeType dt = (DateTimeType) item.getState();
        DateTimeDataType data = new DateTimeDataType(dt.toString());
        state = new DateTimeData(data);
    } else if (item.getState() instanceof DecimalType) {
    } else if (item.getState() instanceof OnOffType) {
    } else if (item.getState() instanceof OpenClosedType) {
    } else if (item.getState() instanceof PercentType) {
    } else if (item.getState() instanceof UpDownType) {
    }
    return state;
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) DateTimeDataType(org.creek.mailcontrol.model.types.DateTimeDataType) StateTransformable(org.creek.mailcontrol.model.data.StateTransformable) HSBData(org.creek.mailcontrol.model.data.HSBData) OnOffType(org.openhab.core.library.types.OnOffType) OpenClosedType(org.openhab.core.library.types.OpenClosedType) DecimalType(org.openhab.core.library.types.DecimalType) DateTimeData(org.creek.mailcontrol.model.data.DateTimeData) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType)

Aggregations

HSBType (org.openhab.core.library.types.HSBType)30 DecimalType (org.openhab.core.library.types.DecimalType)20 PercentType (org.openhab.core.library.types.PercentType)19 Color (java.awt.Color)8 StringType (org.openhab.core.library.types.StringType)8 DateTimeType (org.openhab.core.library.types.DateTimeType)7 Calendar (java.util.Calendar)6 ColorItem (org.openhab.core.library.items.ColorItem)6 ContactItem (org.openhab.core.library.items.ContactItem)5 DateTimeItem (org.openhab.core.library.items.DateTimeItem)5 DimmerItem (org.openhab.core.library.items.DimmerItem)5 NumberItem (org.openhab.core.library.items.NumberItem)5 RollershutterItem (org.openhab.core.library.items.RollershutterItem)5 SwitchItem (org.openhab.core.library.items.SwitchItem)5 OnOffType (org.openhab.core.library.types.OnOffType)5 Test (org.junit.Test)4 State (org.openhab.core.types.State)4 DmxService (org.openhab.binding.dmx.DmxService)3 Item (org.openhab.core.items.Item)3 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)3