Search in sources :

Example 1 with DateTimeType

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;
    }
}
Also used : DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) StringType(org.eclipse.smarthome.core.library.types.StringType) State(org.eclipse.smarthome.core.types.State) WeatherUndergroundJsonForecastDay(org.eclipse.smarthome.binding.weatherunderground.internal.json.WeatherUndergroundJsonForecastDay)

Example 2 with DateTimeType

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);
}
Also used : ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) Item(org.eclipse.smarthome.core.items.Item) DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) Widget(org.eclipse.smarthome.model.sitemap.Widget) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 3 with DateTimeType

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);
}
Also used : DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 4 with DateTimeType

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;
}
Also used : Temperature(javax.measure.quantity.Temperature) StringType(org.eclipse.smarthome.core.library.types.StringType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) LinkedList(java.util.LinkedList) DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) QuantityType(org.eclipse.smarthome.core.library.types.QuantityType) State(org.eclipse.smarthome.core.types.State) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PointType(org.eclipse.smarthome.core.library.types.PointType) RawType(org.eclipse.smarthome.core.library.types.RawType) HSBType(org.eclipse.smarthome.core.library.types.HSBType) StringListType(org.eclipse.smarthome.core.library.types.StringListType)

Example 5 with DateTimeType

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());
}
Also used : DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) State(org.eclipse.smarthome.core.types.State) Test(org.junit.Test)

Aggregations

DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)16 Test (org.junit.Test)10 ZonedDateTime (java.time.ZonedDateTime)7 State (org.eclipse.smarthome.core.types.State)6 ZoneOffset (java.time.ZoneOffset)4 Configuration (org.eclipse.smarthome.config.core.Configuration)4 StringType (org.eclipse.smarthome.core.library.types.StringType)4 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Ignore (org.junit.Ignore)3 Item (org.eclipse.smarthome.core.items.Item)2 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)2 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)2 Widget (org.eclipse.smarthome.model.sitemap.Widget)2 BigDecimal (java.math.BigDecimal)1 LinkedList (java.util.LinkedList)1 Temperature (javax.measure.quantity.Temperature)1 WeatherUndergroundJsonForecastDay (org.eclipse.smarthome.binding.weatherunderground.internal.json.WeatherUndergroundJsonForecastDay)1 HSBType (org.eclipse.smarthome.core.library.types.HSBType)1 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)1