From 03e77e8c696d4ce4d577fd4d9893eadbcab28147 Mon Sep 17 00:00:00 2001 From: Ronny Grun Date: Sun, 4 Jun 2023 09:40:16 +0200 Subject: [PATCH] [viessmann] Fix JSON parsing and update endpoints (#490) * [viessmann] update to new IDP version Signed-off-by: Ronny Grun * [viessmann] update to new endpoints and fix JSON Signed-off-by: Ronny Grun --------- Signed-off-by: Ronny Grun --- .../internal/ViessmannBindingConstants.java | 4 +-- .../viessmann/internal/api/ViessmannApi.java | 11 +++++-- .../dto/features/FeatureErrorEntries.java | 26 ++++++++++++++++ .../dto/features/FeatureErrorValue.java | 30 +++++++++++++++++++ .../dto/features/FeatureProperties.java | 1 + 5 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/dto/features/FeatureErrorEntries.java create mode 100644 bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/dto/features/FeatureErrorValue.java diff --git a/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/ViessmannBindingConstants.java b/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/ViessmannBindingConstants.java index 1f2d3de6dc..3b6c311bda 100644 --- a/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/ViessmannBindingConstants.java +++ b/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/ViessmannBindingConstants.java @@ -44,8 +44,8 @@ public class ViessmannBindingConstants { public static final String VIESSMANN_HOST = "api.viessmann.com"; public static final String VIESSMANN_BASE_URL = "https://api.viessmann.com/"; public static final String IAM_BASE_URL = "https://iam.viessmann.com/"; - public static final String VIESSMANN_AUTHORIZE_URL = IAM_BASE_URL + "idp/v2/authorize"; - public static final String VIESSMANN_TOKEN_URL = IAM_BASE_URL + "idp/v2/token"; + public static final String VIESSMANN_AUTHORIZE_URL = IAM_BASE_URL + "idp/v3/authorize"; + public static final String VIESSMANN_TOKEN_URL = IAM_BASE_URL + "idp/v3/token"; public static final String VIESSMANN_SCOPE = "IoT%20User%20offline_access"; public static final int REFRESH_TOKEN_EXPIRE = 15552000; diff --git a/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/api/ViessmannApi.java b/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/api/ViessmannApi.java index 917992b3f6..3cffdec897 100644 --- a/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/api/ViessmannApi.java +++ b/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/api/ViessmannApi.java @@ -212,18 +212,23 @@ public void checkExpiringToken() { } public @Nullable FeaturesDTO getAllFeatures(String deviceId) throws ViessmannCommunicationException { - String response = executeGet(VIESSMANN_BASE_URL + "iot/v1/equipment/installations/" + installationId + String response = executeGet(VIESSMANN_BASE_URL + "iot/v1/features/installations/" + installationId + "/gateways/" + gatewaySerial + "/devices/" + deviceId + "/features/"); if (response != null) { response = response.replace("enum", "enumValue"); + int i = response.indexOf("\"entries\":{\"type\":\"array\",\"value\""); + while (i > 0) { + response = response.substring(0, i) + "\"errorEntries\"" + response.substring(i + 9, response.length()); + i = response.indexOf("\"entries\":{\"type\":\"array\",\"value\""); + } return GSON.fromJson(response, FeaturesDTO.class); } return null; } public @Nullable EventsDTO getSelectedEvents(String eventType) throws ViessmannCommunicationException { - String response = executeGet(VIESSMANN_BASE_URL + "iot/v1/events-history/events?installationId=" - + installationId + "&gatewaySerial=" + gatewaySerial + "&eventType=" + eventType); + String response = executeGet(VIESSMANN_BASE_URL + "iot/v2/events-history/installations/" + installationId + + "/events?eventType=" + eventType); return GSON.fromJson(response, EventsDTO.class); } diff --git a/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/dto/features/FeatureErrorEntries.java b/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/dto/features/FeatureErrorEntries.java new file mode 100644 index 0000000000..cb89e00526 --- /dev/null +++ b/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/dto/features/FeatureErrorEntries.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2021-2023 Contributors to the SmartHome/J project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.smarthomej.binding.viessmann.internal.dto.features; + +import java.util.List; + +/** + * The {@link FeatureErrorEntries} provides all data of a feature + * + * @author Ronny Grun - Initial contribution + */ +public class FeatureErrorEntries { + + public String type; + public List value; +} diff --git a/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/dto/features/FeatureErrorValue.java b/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/dto/features/FeatureErrorValue.java new file mode 100644 index 0000000000..16c55c29b9 --- /dev/null +++ b/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/dto/features/FeatureErrorValue.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2021-2023 Contributors to the SmartHome/J project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.smarthomej.binding.viessmann.internal.dto.features; + +import java.util.List; + +/** + * The {@link FeatureErrorValue} provides all data of a feature + * + * @author Ronny Grun - Initial contribution + */ +public class FeatureErrorValue { + public String errorCode; + + public String accessLevel; + + public String priority; + + public List audiences; +} diff --git a/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/dto/features/FeatureProperties.java b/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/dto/features/FeatureProperties.java index 721f752f0c..20d64984ca 100644 --- a/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/dto/features/FeatureProperties.java +++ b/bundles/org.smarthomej.binding.viessmann/src/main/java/org/smarthomej/binding/viessmann/internal/dto/features/FeatureProperties.java @@ -27,6 +27,7 @@ public class FeatureProperties { public FeatureInteger shift; public FeatureDouble slope; public FeatureEntriesWeekDays entries; + public FeatureErrorEntries errorEntries; public FeatureBoolean overlapAllowed; public FeatureInteger temperature; public FeatureString start;