Search in sources :

Example 6 with PointType

use of org.eclipse.smarthome.core.library.types.PointType in project smarthome by eclipse.

the class LocationItemTest method testDistance.

@Test
public void testDistance() {
    PointType pointParis = new PointType("48.8566140,2.3522219");
    PointType pointBerlin = new PointType("52.5200066,13.4049540");
    LocationItem locationParis = new LocationItem("paris");
    locationParis.setState(pointParis);
    LocationItem locationBerlin = new LocationItem("berlin");
    locationBerlin.setState(pointBerlin);
    DecimalType distance = locationParis.distanceFrom(locationParis);
    assertEquals(distance.intValue(), 0);
    double parisBerlin = locationParis.distanceFrom(locationBerlin).doubleValue();
    assertEquals(parisBerlin, 878400, 50);
}
Also used : PointType(org.eclipse.smarthome.core.library.types.PointType) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) Test(org.junit.Test)

Example 7 with PointType

use of org.eclipse.smarthome.core.library.types.PointType in project smarthome by eclipse.

the class I18nProviderImplTest method assertThatDefaultLocaleWillBeUsed.

@Test
public void assertThatDefaultLocaleWillBeUsed() {
    i18nProviderImpl.modified(new Hashtable<String, Object>());
    PointType location = i18nProviderImpl.getLocation();
    Locale setLocale = i18nProviderImpl.getLocale();
    assertNull(location);
    assertThat(i18nProviderImpl.getTimeZone(), is(TimeZone.getDefault().toZoneId()));
    assertThat(setLocale, is(Locale.getDefault()));
}
Also used : Locale(java.util.Locale) PointType(org.eclipse.smarthome.core.library.types.PointType) Test(org.junit.Test)

Example 8 with PointType

use of org.eclipse.smarthome.core.library.types.PointType in project smarthome by eclipse.

the class I18nProviderImplTest method assertThatDefaultLocaleWillBeUsedAndLocationIsSet.

@Test
public void assertThatDefaultLocaleWillBeUsedAndLocationIsSet() {
    Hashtable<String, Object> conf = new Hashtable<>();
    conf.put(LOCATION, LOCATION_DARMSTADT);
    i18nProviderImpl.modified(conf);
    PointType location = i18nProviderImpl.getLocation();
    Locale setLocale = i18nProviderImpl.getLocale();
    assertThat(location.toString(), is(LOCATION_DARMSTADT));
    assertThat(setLocale, is(Locale.getDefault()));
}
Also used : Locale(java.util.Locale) Hashtable(java.util.Hashtable) PointType(org.eclipse.smarthome.core.library.types.PointType) Test(org.junit.Test)

Example 9 with PointType

use of org.eclipse.smarthome.core.library.types.PointType in project smarthome by eclipse.

the class AstroDiscoveryService method startScan.

@Override
protected void startScan() {
    logger.debug("Starting Astro discovery scan");
    PointType location = locationProvider.getLocation();
    if (location == null) {
        logger.debug("LocationProvider.getLocation() is not set -> Will not provide any discovery results");
        return;
    }
    createResults(location);
}
Also used : PointType(org.eclipse.smarthome.core.library.types.PointType)

Example 10 with PointType

use of org.eclipse.smarthome.core.library.types.PointType in project smarthome by eclipse.

the class MapviewRenderer method renderWidget.

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
    Mapview mapview = (Mapview) w;
    String snippet = getSnippet("mapview");
    snippet = StringUtils.replace(snippet, "%category%", getCategory(w));
    snippet = StringUtils.replace(snippet, "%label%", getLabel(w));
    snippet = StringUtils.replace(snippet, "%format%", getFormat());
    // Process the color tags
    snippet = processColor(w, snippet);
    State state = itemUIRegistry.getState(mapview);
    if (state instanceof PointType) {
        PointType pointState = (PointType) state;
        double latitude = pointState.getLatitude().doubleValue();
        double longitude = pointState.getLongitude().doubleValue();
        snippet = StringUtils.replace(snippet, "%lat%", Double.toString(latitude));
        snippet = StringUtils.replace(snippet, "%lon%", Double.toString(longitude));
        snippet = StringUtils.replace(snippet, "%lonminus%", Double.toString(longitude - 0.01));
        snippet = StringUtils.replace(snippet, "%lonplus%", Double.toString(longitude + 0.01));
        snippet = StringUtils.replace(snippet, "%latminus%", Double.toString(latitude - 0.01));
        snippet = StringUtils.replace(snippet, "%latplus%", Double.toString(latitude + 0.01));
    }
    int height = mapview.getHeight();
    if (height == 0) {
        // set default height to something viewable
        height = 4;
    }
    height = height * 36;
    snippet = StringUtils.replace(snippet, "%height%", Integer.toString(height));
    sb.append(snippet);
    return null;
}
Also used : Mapview(org.eclipse.smarthome.model.sitemap.Mapview) State(org.eclipse.smarthome.core.types.State) PointType(org.eclipse.smarthome.core.library.types.PointType)

Aggregations

PointType (org.eclipse.smarthome.core.library.types.PointType)12 Test (org.junit.Test)6 Locale (java.util.Locale)5 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)3 State (org.eclipse.smarthome.core.types.State)3 Mapview (org.eclipse.smarthome.model.sitemap.Mapview)2 Hashtable (java.util.Hashtable)1 LinkedList (java.util.LinkedList)1 Temperature (javax.measure.quantity.Temperature)1 DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)1 HSBType (org.eclipse.smarthome.core.library.types.HSBType)1 PercentType (org.eclipse.smarthome.core.library.types.PercentType)1 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)1 RawType (org.eclipse.smarthome.core.library.types.RawType)1 StringListType (org.eclipse.smarthome.core.library.types.StringListType)1 StringType (org.eclipse.smarthome.core.library.types.StringType)1