Skip to content

Commit

Permalink
[viessmann] Fix JSON parsing and update endpoints (#490)
Browse files Browse the repository at this point in the history
* [viessmann] update to new IDP version

Signed-off-by: Ronny Grun <[email protected]>

* [viessmann] update to new endpoints and fix JSON

Signed-off-by: Ronny Grun <[email protected]>

---------

Signed-off-by: Ronny Grun <[email protected]>
  • Loading branch information
rogrun authored and J-N-K committed Jun 4, 2023
1 parent c5e5663 commit 03e77e8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<FeatureErrorValue> value;
}
Original file line number Diff line number Diff line change
@@ -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<Object> audiences;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 03e77e8

Please sign in to comment.