Search in sources :

Example 1 with InnogyClient

use of org.openhab.binding.innogysmarthome.internal.client.InnogyClient in project openhab-addons by openhab.

the class InnogyBridgeHandler method startClient.

/**
 * Initializes the client and connects to the innogy SmartHome service via Client API. Based on the provided
 * {@Link Configuration} while constructing {@Link InnogyClient}, the given oauth2 access and refresh tokens are
 * used or - if not yet available - new tokens are fetched from the service using the provided auth code.
 */
private void startClient() {
    try {
        logger.debug("Initializing innogy SmartHome client...");
        final InnogyClient localClient = this.client;
        if (localClient != null) {
            localClient.refreshStatus();
        }
    } catch (AuthenticationException | ApiException | IOException e) {
        if (handleClientException(e)) {
            // If exception could not be handled properly it's no use to continue so we won't continue start
            logger.debug("Error initializing innogy SmartHome client.", e);
            return;
        }
    }
    final DeviceStructureManager deviceStructMan = this.deviceStructMan;
    if (deviceStructMan == null) {
        return;
    }
    try {
        deviceStructMan.refreshDevices();
    } catch (IOException | ApiException | AuthenticationException e) {
        if (handleClientException(e)) {
            // If exception could not be handled properly it's no use to continue so we won't continue start
            logger.debug("Error starting device structure manager.", e);
            return;
        }
    }
    Device bridgeDevice = deviceStructMan.getBridgeDevice();
    if (bridgeDevice == null) {
        logger.debug("Failed to get bridge device, re-scheduling startClient.");
        scheduleRestartClient(true);
        return;
    }
    setBridgeProperties(bridgeDevice);
    bridgeId = bridgeDevice.getId();
    startWebsocket();
}
Also used : AuthenticationException(org.openhab.binding.innogysmarthome.internal.client.exception.AuthenticationException) Device(org.openhab.binding.innogysmarthome.internal.client.entity.device.Device) InnogyClient(org.openhab.binding.innogysmarthome.internal.client.InnogyClient) IOException(java.io.IOException) DeviceStructureManager(org.openhab.binding.innogysmarthome.internal.manager.DeviceStructureManager) ApiException(org.openhab.binding.innogysmarthome.internal.client.exception.ApiException)

Example 2 with InnogyClient

use of org.openhab.binding.innogysmarthome.internal.client.InnogyClient in project openhab-addons by openhab.

the class InnogyBridgeHandler method initializeClient.

/**
 * Initializes the services and InnogyClient.
 */
private void initializeClient() {
    final OAuthClientService oAuthService = oAuthFactory.createOAuthClientService(thing.getUID().getAsString(), API_URL_TOKEN, API_URL_TOKEN, bridgeConfiguration.clientId, bridgeConfiguration.clientSecret, null, true);
    this.oAuthService = oAuthService;
    if (checkOnAuthCode()) {
        final InnogyClient localClient = createInnogyClient(oAuthService, httpClient);
        client = localClient;
        deviceStructMan = new DeviceStructureManager(createFullDeviceManager(localClient));
        oAuthService.addAccessTokenRefreshListener(this);
        registerDeviceStatusListener(InnogyBridgeHandler.this);
        scheduleRestartClient(false);
    }
}
Also used : OAuthClientService(org.openhab.core.auth.client.oauth2.OAuthClientService) InnogyClient(org.openhab.binding.innogysmarthome.internal.client.InnogyClient) DeviceStructureManager(org.openhab.binding.innogysmarthome.internal.manager.DeviceStructureManager)

Aggregations

InnogyClient (org.openhab.binding.innogysmarthome.internal.client.InnogyClient)2 DeviceStructureManager (org.openhab.binding.innogysmarthome.internal.manager.DeviceStructureManager)2 IOException (java.io.IOException)1 Device (org.openhab.binding.innogysmarthome.internal.client.entity.device.Device)1 ApiException (org.openhab.binding.innogysmarthome.internal.client.exception.ApiException)1 AuthenticationException (org.openhab.binding.innogysmarthome.internal.client.exception.AuthenticationException)1 OAuthClientService (org.openhab.core.auth.client.oauth2.OAuthClientService)1