use of org.eclipse.smarthome.core.library.types.DateTimeType in project smarthome by eclipse.
the class WeatherUndergroundHandler method updateForecastChannel.
private State updateForecastChannel(String channelId, WeatherUndergroundJsonForecast forecast) {
WUQuantity quantity;
int day = getDay(channelId);
WeatherUndergroundJsonForecastDay dayForecast = forecast.getSimpleForecast(day);
String channelTypeId = getChannelTypeId(channelId);
switch(channelTypeId) {
case "forecastTime":
return undefOrState(dayForecast.getForecastTime(), new DateTimeType(dayForecast.getForecastTime()));
case "conditions":
return undefOrState(dayForecast.getConditions(), new StringType(dayForecast.getConditions()));
case "minTemperature":
quantity = getTemperature(dayForecast.getMinTemperatureC(), dayForecast.getMinTemperatureF());
return undefOrQuantity(quantity);
case "maxTemperature":
quantity = getTemperature(dayForecast.getMaxTemperatureC(), dayForecast.getMaxTemperatureF());
return undefOrQuantity(quantity);
case "relativeHumidity":
return undefOrState(dayForecast.getRelativeHumidity(), new QuantityType<>(dayForecast.getRelativeHumidity(), SmartHomeUnits.PERCENT));
case "probaPrecipitation":
return undefOrState(dayForecast.getProbaPrecipitation(), new QuantityType<>(dayForecast.getProbaPrecipitation(), SmartHomeUnits.PERCENT));
case "precipitationDay":
quantity = getPrecipitation(dayForecast.getPrecipitationDayMm(), dayForecast.getPrecipitationDayIn());
return undefOrQuantity(quantity);
case "snow":
quantity = getWUQuantity(CENTI(SIUnits.METRE), ImperialUnits.INCH, dayForecast.getSnowCm(), dayForecast.getSnowIn());
return undefOrQuantity(quantity);
case "maxWindDirection":
return undefOrState(dayForecast.getMaxWindDirection(), new StringType(dayForecast.getMaxWindDirection()));
case "maxWindDirectionDegrees":
return undefOrState(dayForecast.getMaxWindDirectionDegrees(), new QuantityType<>(dayForecast.getMaxWindDirectionDegrees(), SmartHomeUnits.DEGREE_ANGLE));
case "maxWindSpeed":
quantity = getSpeed(dayForecast.getMaxWindSpeedKmh(), dayForecast.getMaxWindSpeedMph());
return undefOrQuantity(quantity);
case "averageWindDirection":
return undefOrState(dayForecast.getAverageWindDirection(), new StringType(dayForecast.getAverageWindDirection()));
case "averageWindDirectionDegrees":
return undefOrState(dayForecast.getAverageWindDirectionDegrees(), new QuantityType<>(dayForecast.getAverageWindDirectionDegrees(), SmartHomeUnits.DEGREE_ANGLE));
case "averageWindSpeed":
quantity = getSpeed(dayForecast.getAverageWindSpeedKmh(), dayForecast.getAverageWindSpeedMph());
return undefOrQuantity(quantity);
case "iconKey":
return undefOrState(dayForecast.getIconKey(), new StringType(dayForecast.getIconKey()));
case "icon":
State icon = HttpUtil.downloadImage(dayForecast.getIcon().toExternalForm());
if (icon == null) {
logger.debug("Failed to download the content of URL {}", dayForecast.getIcon().toExternalForm());
return null;
}
return icon;
default:
return null;
}
}
use of org.eclipse.smarthome.core.library.types.DateTimeType in project smarthome by eclipse.
the class ItemUIRegistryImplTest method getLabel_labelWithZonedDate.
@Test
public void getLabel_labelWithZonedDate() throws ItemNotFoundException {
String testLabel = "Label [%1$td.%1$tm.%1$tY]";
Widget w = mock(Widget.class);
Item item = mock(Item.class);
when(w.getLabel()).thenReturn(testLabel);
when(w.getItem()).thenReturn("Item");
when(registry.getItem("Item")).thenReturn(item);
when(item.getState()).thenReturn(new DateTimeType("2011-06-01T00:00:00Z"));
String label = uiRegistry.getLabel(w);
assertEquals("Label [01.06.2011]", label);
}
use of org.eclipse.smarthome.core.library.types.DateTimeType in project smarthome by eclipse.
the class ItemUIRegistryImplTest method getLabel_labelWithDate.
@Test
public void getLabel_labelWithDate() throws ItemNotFoundException {
String testLabel = "Label [%1$td.%1$tm.%1$tY]";
when(widget.getLabel()).thenReturn(testLabel);
when(item.getState()).thenReturn(new DateTimeType("2011-06-01T00:00:00"));
String label = uiRegistry.getLabel(widget);
assertEquals("Label [01.06.2011]", label);
}
use of org.eclipse.smarthome.core.library.types.DateTimeType in project smarthome by eclipse.
the class StateUtil method getAllStates.
public static List<State> getAllStates() {
LinkedList<State> states = new LinkedList<>();
DateTimeType dateTime = new DateTimeType();
states.add(dateTime);
DecimalType decimal = new DecimalType(23);
states.add(decimal);
PercentType percent = new PercentType(50);
states.add(percent);
HSBType hsb = new HSBType("50,75,42");
states.add(hsb);
states.add(OnOffType.ON);
states.add(OnOffType.OFF);
states.add(OpenClosedType.OPEN);
states.add(OpenClosedType.CLOSED);
states.add(PlayPauseType.PLAY);
states.add(PlayPauseType.PAUSE);
PointType point = new PointType("42.23,23.5");
states.add(point);
RawType raw = new RawType(new byte[0], "application/octet-stream");
states.add(raw);
states.add(RewindFastforwardType.REWIND);
states.add(RewindFastforwardType.FASTFORWARD);
StringListType stringList = new StringListType(new String[] { "foo", "bar" });
states.add(stringList);
StringType string = new StringType("foo");
states.add(string);
states.add(UnDefType.NULL);
states.add(UnDefType.UNDEF);
states.add(UpDownType.UP);
states.add(UpDownType.DOWN);
QuantityType<Temperature> quantityType = new QuantityType<Temperature>("12 °C");
states.add(quantityType);
return states;
}
use of org.eclipse.smarthome.core.library.types.DateTimeType in project smarthome by eclipse.
the class StringItemTest method setDateTimeTypeType.
@Test
public void setDateTimeTypeType() {
StringItem item = new StringItem("test");
State state = new DateTimeType();
item.setState(state);
assertEquals(state, item.getState());
}
Aggregations