Skip to content

Commit

Permalink
[amazonechocontrol]
Browse files Browse the repository at this point in the history
Fix for Announcment Channel
Signed-off-by: Michael Geramb <mail@michael-geramb.at> (github: mgeramb)
  • Loading branch information
Michael Geramb committed Jul 18, 2019
1 parent a0f751b commit 73796fb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import org.openhab.binding.amazonechocontrol.internal.jsons.JsonFeed;
import org.openhab.binding.amazonechocontrol.internal.jsons.JsonMediaState;
import org.openhab.binding.amazonechocontrol.internal.jsons.JsonMusicProvider;
import org.openhab.binding.amazonechocontrol.internal.jsons.JsonNetworkDetails;
import org.openhab.binding.amazonechocontrol.internal.jsons.JsonNotificationRequest;
import org.openhab.binding.amazonechocontrol.internal.jsons.JsonNotificationResponse;
import org.openhab.binding.amazonechocontrol.internal.jsons.JsonNotificationSound;
Expand Down Expand Up @@ -925,7 +926,42 @@ public WakeWord[] getWakeWords() {
return new WakeWord[0];
}

private List<String> getSmarthomeDeviceListX() throws IOException, URISyntaxException {
try {
String json = makeRequestAndReturnString(alexaServer + "/api/phoenix");
logger.debug("getSmartHomeDevices result: {}", json);

JsonNetworkDetails networkDetails = parseJson(json, JsonNetworkDetails.class);
Object jsonObject = gson.fromJson(networkDetails.networkDetail, Object.class);
List<String> result = new ArrayList<>();
searchSmartHomeDevicesRecursive(jsonObject, result);
return result;
} catch (Exception e) {
logger.warn("getSmartHomeDevices fails: {}", e.getMessage());
throw e;
}
}

private void searchSmartHomeDevicesRecursive(@Nullable Object jsonNode, List<String> result) {
if (jsonNode instanceof Map) {
@SuppressWarnings("rawtypes")
Map map = (Map) jsonNode;
if (map.containsKey("entityId") && map.containsKey("friendlyName") && map.containsKey("actions")) {
// device node found, create type element and add it to the results
JsonElement element = gson.toJsonTree(jsonNode);
result.add(element.toString());
} else {
for (Object key : map.keySet()) {
Object value = map.get(key);
searchSmartHomeDevicesRecursive(value, result);
}
}
}
}

public List<SmartHomeDevice> getSmarthomeDeviceList() throws IOException, URISyntaxException {
List<String> test = getSmarthomeDeviceListX();

JsonObject json = new JsonParser().parse(getSmarthomeDeviceListJson()).getAsJsonObject();
JsonObject smartHomeDevices = json.get("networkDetail").getAsJsonObject().get("locationDetails")
.getAsJsonObject().get("locationDetails").getAsJsonObject().get("Default_Location").getAsJsonObject()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2010-2019 Contributors to the openHAB 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.openhab.binding.amazonechocontrol.internal.jsons;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

/**
* The {@link JsonNetworkDetails} encapsulate the GSON data of a network query
*
* @author Michael Geramb - Initial contribution
*/
@NonNullByDefault
public class JsonNetworkDetails {
public @Nullable String networkDetail;
}

0 comments on commit 73796fb

Please sign in to comment.