Search in sources :

Example 1 with LocaleProvider

use of org.openhab.core.i18n.LocaleProvider in project openhab-addons by openhab.

the class NetatmoModuleDiscoveryServiceTest method before.

@BeforeEach
public void before() {
    Bridge bridgeMock = mock(Bridge.class);
    when(bridgeMock.getUID()).thenReturn(new ThingUID("netatmo", "bridge"));
    bridgeHandlerSpy = spy(new NetatmoBridgeHandler(bridgeMock, null));
    LocaleProvider localeProviderMock = mock(LocaleProvider.class);
    TranslationProvider translationProvider = mock(TranslationProvider.class);
    service = new NetatmoModuleDiscoveryServiceAccessible(bridgeHandlerSpy, localeProviderMock, translationProvider);
}
Also used : ThingUID(org.openhab.core.thing.ThingUID) LocaleProvider(org.openhab.core.i18n.LocaleProvider) TranslationProvider(org.openhab.core.i18n.TranslationProvider) NetatmoBridgeHandler(org.openhab.binding.netatmo.internal.handler.NetatmoBridgeHandler) Bridge(org.openhab.core.thing.Bridge) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with LocaleProvider

use of org.openhab.core.i18n.LocaleProvider in project openhab-addons by openhab.

the class PS4Handler method updateApplicationTitleid.

/**
 * Sets the cached TitleId and tries to download artwork
 * for application if CHANNEL_APPLICATION_IMAGE is linked.
 *
 * @param titleId Id of application.
 */
private void updateApplicationTitleid(String titleId) {
    currentApplicationId = titleId;
    updateState(CHANNEL_APPLICATION_ID, StringType.valueOf(titleId));
    logger.debug("Current application title id: {}", titleId);
    if (!isLinked(CHANNEL_APPLICATION_IMAGE)) {
        return;
    }
    LocaleProvider lProvider = localeProvider;
    Locale locale = (lProvider != null) ? lProvider.getLocale() : Locale.US;
    RawType artWork = PS4ArtworkHandler.fetchArtworkForTitleid(titleId, config.artworkSize, locale);
    if (artWork != null) {
        currentArtwork = artWork;
        updateState(CHANNEL_APPLICATION_IMAGE, artWork);
    } else if (!titleId.isEmpty()) {
        logger.debug("Couldn't fetch artwork for title id: {}", titleId);
    }
}
Also used : Locale(java.util.Locale) LocaleProvider(org.openhab.core.i18n.LocaleProvider) RawType(org.openhab.core.library.types.RawType)

Example 3 with LocaleProvider

use of org.openhab.core.i18n.LocaleProvider in project openhab-addons by openhab.

the class OpenHabLanguageProviderTest method whenTheLocaleIsSetToGermanyThenTheLanguageCodeIsDe.

@Test
public void whenTheLocaleIsSetToGermanyThenTheLanguageCodeIsDe() {
    // given:
    LocaleProvider localeProvider = mock(LocaleProvider.class);
    when(localeProvider.getLocale()).thenReturn(Locale.GERMANY);
    LanguageProvider languageProvider = new OpenHabLanguageProvider(localeProvider);
    // when:
    Optional<String> language = languageProvider.getLanguage();
    // then:
    assertEquals(Optional.of("de"), language);
}
Also used : LocaleProvider(org.openhab.core.i18n.LocaleProvider) Test(org.junit.jupiter.api.Test)

Example 4 with LocaleProvider

use of org.openhab.core.i18n.LocaleProvider in project openhab-core by openhab.

the class BindingInfoI18nTest method assertUsingDefaultLocale.

@Test
public void assertUsingDefaultLocale() throws Exception {
    // Set german locale
    ConfigurationAdmin configAdmin = getService(ConfigurationAdmin.class);
    assertThat(configAdmin, is(notNullValue()));
    Configuration config = configAdmin.getConfiguration(I18nProviderImpl.CONFIGURATION_PID, null);
    assertThat(config, is(notNullValue()));
    Dictionary<String, Object> properties = config.getProperties();
    if (properties == null) {
        properties = new Hashtable<>();
    }
    properties.put("language", "de");
    properties.put("region", "DE");
    config.update(properties);
    // before running the test with a default locale make sure the locale has been set
    LocaleProvider localeProvider = getService(LocaleProvider.class);
    assertThat(localeProvider, is(notNullValue()));
    waitForAssert(() -> assertThat(localeProvider.getLocale().toString(), is("de_DE")));
    bindingInstaller.exec(TEST_BUNDLE_NAME, () -> {
        // use default locale
        Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos(null);
        BindingInfo bindingInfo = bindingInfos.iterator().next();
        assertThat(bindingInfo, is(notNullValue()));
        assertThat(bindingInfo.getName(), is("ACME Wetter Binding"));
        assertThat(bindingInfo.getDescription(), is("Das ACME Wetter Binding stellt verschiedene Wetterdaten wie die Temperatur, die Luftfeuchtigkeit und den Luftdruck für konfigurierbare Orte vom ACME Wetterdienst bereit"));
    });
}
Also used : Configuration(org.osgi.service.cm.Configuration) LocaleProvider(org.openhab.core.i18n.LocaleProvider) BindingInfo(org.openhab.core.binding.BindingInfo) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 5 with LocaleProvider

use of org.openhab.core.i18n.LocaleProvider in project openhab-core by openhab.

the class TranslationProviderOSGiTest method setup.

@BeforeEach
public void setup() {
    translationProvider = getService(TranslationProvider.class);
    LocaleProvider localeProvider = getService(LocaleProvider.class);
    Map<String, Object> localeCfg = new HashMap<>();
    localeCfg.put("language", "de");
    localeCfg.put("region", "DE");
    ((I18nProviderImpl) localeProvider).modified(localeCfg);
}
Also used : HashMap(java.util.HashMap) LocaleProvider(org.openhab.core.i18n.LocaleProvider) TranslationProvider(org.openhab.core.i18n.TranslationProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

LocaleProvider (org.openhab.core.i18n.LocaleProvider)14 BeforeEach (org.junit.jupiter.api.BeforeEach)8 Test (org.junit.jupiter.api.Test)5 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)5 Locale (java.util.Locale)3 TranslationProvider (org.openhab.core.i18n.TranslationProvider)3 DefaultLocaleSetter (org.openhab.core.thing.testutil.i18n.DefaultLocaleSetter)3 Configuration (org.osgi.service.cm.Configuration)3 Hashtable (java.util.Hashtable)2 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)2 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)2 ThingHandlerFactory (org.openhab.core.thing.binding.ThingHandlerFactory)2 BundleContext (org.osgi.framework.BundleContext)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 NetatmoBridgeHandler (org.openhab.binding.netatmo.internal.handler.NetatmoBridgeHandler)1 AudioManager (org.openhab.core.audio.AudioManager)1