mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
map the types by cloning the internal calendar
fixes #16 Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright (c) 2015-2016 Kai Kreuzer and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.openhab.core.compat1x.internal;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.openhab.core.library.types.DateTimeType;
|
||||
|
||||
public class TypeMapperTest {
|
||||
|
||||
@Test
|
||||
public void testDateTypeType() {
|
||||
DateTimeType ohType1 = new DateTimeType();
|
||||
DateTimeType ohType2 = (DateTimeType) TypeMapper.mapToOpenHABType(TypeMapper.mapToESHType(ohType1));
|
||||
assertEquals(ohType1, ohType2);
|
||||
}
|
||||
|
||||
}
|
||||
+16
-2
@@ -8,6 +8,9 @@
|
||||
*/
|
||||
package org.openhab.core.compat1x.internal;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.eclipse.smarthome.core.library.types.DateTimeType;
|
||||
import org.eclipse.smarthome.core.library.types.DecimalType;
|
||||
import org.eclipse.smarthome.core.library.types.HSBType;
|
||||
@@ -65,7 +68,7 @@ public class TypeMapper {
|
||||
} else if (typeClass.equals(PercentType.class)) {
|
||||
result = new org.openhab.core.library.types.PercentType(type.toString());
|
||||
} else if (typeClass.equals(DateTimeType.class)) {
|
||||
result = new org.openhab.core.library.types.DateTimeType(type.toString());
|
||||
result = new org.openhab.core.library.types.DateTimeType(cloneCalendar(type));
|
||||
} else if (typeClass.equals(PointType.class)) {
|
||||
result = new org.openhab.core.library.types.PointType(type.toString());
|
||||
}
|
||||
@@ -114,7 +117,7 @@ public class TypeMapper {
|
||||
} else if (typeClass.equals(org.openhab.core.library.types.PercentType.class)) {
|
||||
result = new PercentType(type.toString());
|
||||
} else if (typeClass.equals(org.openhab.core.library.types.DateTimeType.class)) {
|
||||
result = new DateTimeType(type.toString());
|
||||
result = new DateTimeType(cloneCalendar(type));
|
||||
} else if (typeClass.equals(org.openhab.core.library.types.PointType.class)) {
|
||||
result = new PointType(type.toString());
|
||||
} else if (typeClass.equals(org.openhab.library.tel.types.CallType.class)) {
|
||||
@@ -124,4 +127,15 @@ public class TypeMapper {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Calendar cloneCalendar(Object type) {
|
||||
try {
|
||||
Field calField = type.getClass().getDeclaredField("calendar");
|
||||
calField.setAccessible(true);
|
||||
Calendar cal = (Calendar) calField.get(type);
|
||||
return (Calendar) cal.clone();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user