Search in sources :

Example 1 with UpnpIOService

use of org.openhab.core.io.transport.upnp.UpnpIOService in project openhab-addons by openhab.

the class WemoBaseThingHandler method removeSubscriptions.

private void removeSubscriptions() {
    if (subscriptions.isEmpty()) {
        return;
    }
    UpnpIOService service = this.service;
    if (service == null) {
        return;
    }
    if (!service.isRegistered(this)) {
        logger.debug("Trying to remove GENA subscriptions for {}, but service is not registered", getThing().getUID());
        return;
    }
    logger.debug("Removing GENA subscriptions for {}", getUDN());
    subscriptions.forEach((serviceId, lastRenewed) -> {
        logger.debug("Removing subscription for service {}", serviceId);
        service.removeSubscription(this, serviceId);
    });
    subscriptions.clear();
}
Also used : UpnpIOService(org.openhab.core.io.transport.upnp.UpnpIOService)

Example 2 with UpnpIOService

use of org.openhab.core.io.transport.upnp.UpnpIOService in project openhab-addons by openhab.

the class WemoBaseThingHandler method initialize.

@Override
public void initialize() {
    UpnpIOService service = this.service;
    if (service != null) {
        logger.debug("Registering UPnP participant for {}", getThing().getUID());
        service.registerParticipant(this);
        initializeHost();
    }
}
Also used : UpnpIOService(org.openhab.core.io.transport.upnp.UpnpIOService)

Example 3 with UpnpIOService

use of org.openhab.core.io.transport.upnp.UpnpIOService in project openhab-addons by openhab.

the class WemoBaseThingHandler method addSubscription.

protected void addSubscription(String serviceId) {
    if (subscriptions.containsKey(serviceId)) {
        logger.debug("{} already subscribed to {}", getUDN(), serviceId);
        return;
    }
    if (subscriptions.isEmpty()) {
        logger.debug("Adding first GENA subscription for {}, scheduling renewal job", getUDN());
        scheduleSubscriptionRenewalJob();
    }
    subscriptions.put(serviceId, Instant.ofEpochSecond(0));
    UpnpIOService service = this.service;
    if (service == null) {
        return;
    }
    if (!service.isRegistered(this)) {
        logger.debug("Registering UPnP participant for {}", getUDN());
        service.registerParticipant(this);
    }
    if (!service.isRegistered(this)) {
        logger.debug("Trying to add GENA subscription {} for {}, but service is not registered", serviceId, getUDN());
        return;
    }
    logger.debug("Adding GENA subscription {} for {}", serviceId, getUDN());
    service.addSubscription(this, serviceId, WemoBindingConstants.SUBSCRIPTION_DURATION_SECONDS);
}
Also used : UpnpIOService(org.openhab.core.io.transport.upnp.UpnpIOService)

Example 4 with UpnpIOService

use of org.openhab.core.io.transport.upnp.UpnpIOService in project openhab-addons by openhab.

the class WemoBaseThingHandler method removeSubscription.

protected void removeSubscription(String serviceId) {
    UpnpIOService service = this.service;
    if (service == null) {
        return;
    }
    subscriptions.remove(serviceId);
    if (subscriptions.isEmpty()) {
        logger.debug("Removing last GENA subscription for {}, cancelling renewal job", getUDN());
        cancelSubscriptionRenewalJob();
    }
    if (!service.isRegistered(this)) {
        logger.debug("Trying to remove GENA subscription {} for {}, but service is not registered", serviceId, getUDN());
        return;
    }
    logger.debug("Unsubscribing {} from service {}", getUDN(), serviceId);
    service.removeSubscription(this, serviceId);
}
Also used : UpnpIOService(org.openhab.core.io.transport.upnp.UpnpIOService)

Example 5 with UpnpIOService

use of org.openhab.core.io.transport.upnp.UpnpIOService in project openhab-addons by openhab.

the class GenericWemoOSGiTest method setUpServices.

protected void setUpServices() throws IOException {
    WemoUtil.serviceAvailableFunction = (host, port) -> true;
    // StorageService is required from the ManagedThingProvider
    VolatileStorageService volatileStorageService = new VolatileStorageService();
    registerService(volatileStorageService);
    // Mock the UPnP Service, that is required from the UPnP IO Service
    mockUpnpService = new MockUpnpService(false, true);
    mockUpnpService.startup();
    registerService(mockUpnpService, UpnpService.class.getName());
    managedThingProvider = getService(ManagedThingProvider.class);
    assertThat(managedThingProvider, is(notNullValue()));
    thingRegistry = getService(ThingRegistry.class);
    assertThat(thingRegistry, is(notNullValue()));
    // UPnP IO Service is required from the WemoDiscoveryService and WemoHandlerFactory
    upnpIOService = getService(UpnpIOService.class);
    assertThat(upnpIOService, is(notNullValue()));
    mockCaller = Mockito.spy(new WemoHttpCall());
    WemoHttpCallFactory wemoHttpCallFactory = () -> mockCaller;
    registerService(wemoHttpCallFactory, WemoHttpCallFactory.class.getName());
    ChannelTypeProvider channelTypeProvider = mock(ChannelTypeProvider.class);
    when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), any(Locale.class))).thenReturn(ChannelTypeBuilder.state(DEFAULT_CHANNEL_TYPE_UID, "label", CoreItemFactory.SWITCH).build());
    registerService(channelTypeProvider);
}
Also used : MockUpnpService(org.jupnp.mock.MockUpnpService) UpnpService(org.jupnp.UpnpService) WemoHttpCallFactory(org.openhab.binding.wemo.internal.WemoHttpCallFactory) Locale(java.util.Locale) MockUpnpService(org.jupnp.mock.MockUpnpService) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) WemoHttpCall(org.openhab.binding.wemo.internal.http.WemoHttpCall) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ChannelTypeProvider(org.openhab.core.thing.type.ChannelTypeProvider) VolatileStorageService(org.openhab.core.test.storage.VolatileStorageService) UpnpIOService(org.openhab.core.io.transport.upnp.UpnpIOService) ThingRegistry(org.openhab.core.thing.ThingRegistry)

Aggregations

UpnpIOService (org.openhab.core.io.transport.upnp.UpnpIOService)7 Locale (java.util.Locale)1 UpnpService (org.jupnp.UpnpService)1 MockUpnpService (org.jupnp.mock.MockUpnpService)1 WemoHttpCallFactory (org.openhab.binding.wemo.internal.WemoHttpCallFactory)1 WemoHttpCall (org.openhab.binding.wemo.internal.http.WemoHttpCall)1 VolatileStorageService (org.openhab.core.test.storage.VolatileStorageService)1 ManagedThingProvider (org.openhab.core.thing.ManagedThingProvider)1 ThingRegistry (org.openhab.core.thing.ThingRegistry)1 ChannelTypeProvider (org.openhab.core.thing.type.ChannelTypeProvider)1 ChannelTypeUID (org.openhab.core.thing.type.ChannelTypeUID)1