use of org.openhab.core.types.Type in project openhab1-addons by openhab.
the class SonosBinding method processVariableMap.
@SuppressWarnings("rawtypes")
public void processVariableMap(RemoteDevice device, Map<String, StateVariableValue> values) {
if (device != null && values != null) {
SonosZonePlayer associatedPlayer = sonosZonePlayerCache.getByDevice(device);
if (associatedPlayer == null) {
logger.debug("There is no Sonos Player defined matching the device {}", device);
return;
}
for (String stateVariable : values.keySet()) {
// find all the CommandTypes that are defined for each
// StateVariable
List<SonosCommandType> supportedCommands = SonosCommandType.getCommandByVariable(stateVariable);
StateVariableValue status = values.get(stateVariable);
for (SonosCommandType sonosCommandType : supportedCommands) {
// create a new State based on the type of Sonos Command and
// the status value in the map
Type newState = null;
try {
newState = createStateForType((Class<? extends State>) sonosCommandType.getTypeClass(), status.getValue().toString());
} catch (BindingConfigParseException e) {
logger.error("Error parsing a value {} to a state variable of type {}", status.toString(), sonosCommandType.getTypeClass().toString());
}
for (SonosBindingProvider provider : providers) {
List<String> qualifiedItems = provider.getItemNames(sonosZonePlayerCache.getByDevice(device).getId(), sonosCommandType.getSonosCommand());
List<String> qualifiedItemsByUDN = provider.getItemNames(sonosZonePlayerCache.getByDevice(device).getUdn().getIdentifierString(), sonosCommandType.getSonosCommand());
for (String item : qualifiedItemsByUDN) {
if (!qualifiedItems.contains(item)) {
qualifiedItems.add(item);
}
}
for (String anItem : qualifiedItems) {
// get the openHAB commands attached to each Item at
// this given Provider
List<Command> commands = provider.getCommands(anItem, sonosCommandType.getSonosCommand());
if (provider.getAcceptedDataTypes(anItem).contains(sonosCommandType.getTypeClass())) {
if (newState != null) {
eventPublisher.postUpdate(anItem, (State) newState);
} else {
throw new IllegalClassException("Cannot process update for the command of type " + sonosCommandType.toString());
}
} else {
logger.warn("Cannot cast {} to an accepted state type for item {}", sonosCommandType.getTypeClass().toString(), anItem);
}
}
}
}
}
}
}
use of org.openhab.core.types.Type in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMappingB1_Controlled.
/**
* Convenience method: testing KNXCoretypeMapper for type “Datapoint Types B1 Controlled"
*
* @throws KNXFormatException
*/
private void testTypeMappingB1_Controlled(DPT dpt, String valueLow, String valueHigh) throws KNXFormatException {
testToTypeClass(dpt, DecimalType.class);
// Use a too short byte array
assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, DecimalType.class));
Type type = testToType(dpt, new byte[] { 0 }, DecimalType.class);
testToDPTValue(dpt, type, "0 " + valueLow);
type = testToType(dpt, new byte[] { 1 }, DecimalType.class);
testToDPTValue(dpt, type, "0 " + valueHigh);
type = testToType(dpt, new byte[] { 2 }, DecimalType.class);
testToDPTValue(dpt, type, "1 " + valueLow);
type = testToType(dpt, new byte[] { 3 }, DecimalType.class);
testToDPTValue(dpt, type, "1 " + valueHigh);
type = testToType(dpt, new byte[] { (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "1 " + valueHigh);
// Use a too long byte array expecting that additional bytes will be ignored
type = testToType(dpt, new byte[] { (byte) 0xFF, 0 }, DecimalType.class);
testToDPTValue(dpt, type, "1 " + valueHigh);
}
use of org.openhab.core.types.Type in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMappingDate_11_001.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “Time" KNX ID: 11.001 DPT_DATE
*
* Test correct year evaluation according KNX spec.
*
* @throws KNXFormatException
*/
@Test
public void testTypeMappingDate_11_001() throws KNXFormatException {
DPT dpt = DPTXlatorDate.DPT_DATE;
testToTypeClass(dpt, DateTimeType.class);
// Use a too short byte array
assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, DateTimeType.class));
// Use a too long byte array expecting that additional bytes will be ignored
Type type = testToType(dpt, new byte[] { 0x01, 0x01, 0x00, (byte) 0xFF }, DateTimeType.class);
testToDPTValue(dpt, type, "2000-01-01");
type = testToType(dpt, new byte[] { 0x01, 0x01, 0x00 }, DateTimeType.class);
testToDPTValue(dpt, type, "2000-01-01");
type = testToType(dpt, new byte[] { 0x01, 0x01, 99 }, DateTimeType.class);
testToDPTValue(dpt, type, "1999-01-01");
type = testToType(dpt, new byte[] { 0x01, 0x01, 90 }, DateTimeType.class);
testToDPTValue(dpt, type, "1990-01-01");
type = testToType(dpt, new byte[] { 0x01, 0x01, 89 }, DateTimeType.class);
testToDPTValue(dpt, type, "2089-01-01");
// Test roll over (which is actually not in the KNX spec)
type = testToType(dpt, new byte[] { 31, 0x02, 0x00 }, DateTimeType.class);
testToDPTValue(dpt, type, "2000-03-02");
}
use of org.openhab.core.types.Type in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMappingB1.
/**
* Convenience method: testing KNXCoretypeMapper for type “Datapoint Types B1"
*
* @throws KNXFormatException
*/
private void testTypeMappingB1(DPT dpt, Class<? extends Type> expectedClass, String valueLow, String valueHigh) throws KNXFormatException {
testToTypeClass(dpt, expectedClass);
// Use a too short byte array
assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, expectedClass));
Type type = testToType(dpt, new byte[] { 0 }, expectedClass);
testToDPTValue(dpt, type, valueLow);
type = testToType(dpt, new byte[] { 1 }, expectedClass);
testToDPTValue(dpt, type, valueHigh);
type = testToType(dpt, new byte[] { 2 }, expectedClass);
testToDPTValue(dpt, type, valueLow);
type = testToType(dpt, new byte[] { 3 }, expectedClass);
testToDPTValue(dpt, type, valueHigh);
type = testToType(dpt, new byte[] { (byte) 0xFF }, expectedClass);
testToDPTValue(dpt, type, valueHigh);
// Use a too long byte array expecting that additional bytes will be ignored
type = testToType(dpt, new byte[] { (byte) 0xFF, 0 }, expectedClass);
testToDPTValue(dpt, type, valueHigh);
}
use of org.openhab.core.types.Type in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMapping8BitUnsigned_5_006.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “8-Bit Unsigned Value" KNX ID: 5.006 DPT_TARRIF
*
* @throws KNXFormatException
*/
@Test
public void testTypeMapping8BitUnsigned_5_006() throws KNXFormatException {
DPT dpt = DPTXlator8BitUnsigned.DPT_TARIFF;
testToTypeClass(dpt, DecimalType.class);
// Use a too short byte array
assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, DecimalType.class));
Type type = testToType(dpt, new byte[] { 0 }, DecimalType.class);
testToDPTValue(dpt, type, "0");
type = testToType(dpt, new byte[] { (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "255");
// Use a too long byte array expecting that additional bytes will be ignored
type = testToType(dpt, new byte[] { (byte) 0xFF, 0 }, DecimalType.class);
testToDPTValue(dpt, type, "255");
}
Aggregations