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();
}
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);
}
}
Aggregations