Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[amazonechocontrol] Add support for announcement on echo show and echo spot and some other small features #5590

Merged
merged 29 commits into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,7 @@ protected void doGet(@Nullable HttpServletRequest req, @Nullable HttpServletResp
Device device = account.findDeviceJson(serialNumber);
if (device != null) {
Thing thing = account.findThingBySerialNumber(device.serialNumber);
if (thing != null) {
handleIds(resp, connection, device, thing);
}
handleIds(resp, connection, device, thing);
return;
}
}
Expand Down Expand Up @@ -374,6 +372,12 @@ private void handleDefaultPageResult(HttpServletResponse resp, String message, C
html.append(" | <a href='" + servletUrl + "/newdevice' >");
html.append(StringEscapeUtils.escapeHtml("Logout and create new device id"));
html.append("</a>");
// customer id
html.append("<br>Customer Id: ");
html.append(StringEscapeUtils.escapeHtml(connection.getCustomerId()));
// customer name
html.append("<br>Customer Name: ");
html.append(StringEscapeUtils.escapeHtml(connection.getCustomerName()));
// device name
html.append("<br>App name: ");
html.append(StringEscapeUtils.escapeHtml(connection.getDeviceName()));
Expand All @@ -393,7 +397,7 @@ private void handleDefaultPageResult(HttpServletResponse resp, String message, C

// device list
html.append(
"<table><tr><th align='left'>Device</th><th align='left'>Serial Number</th><th align='left'>State</th><th align='left'>Thing</th><th align='left'>Family</th><th align='left'>Type</th></tr>");
"<table><tr><th align='left'>Device</th><th align='left'>Serial Number</th><th align='left'>State</th><th align='left'>Thing</th><th align='left'>Family</th><th align='left'>Type</th><th align='left'>Customer Id</th></tr>");
for (Device device : this.account.getLastKnownDevices()) {

html.append("<tr><td>");
Expand All @@ -409,14 +413,18 @@ private void handleDefaultPageResult(HttpServletResponse resp, String message, C
+ URLEncoder.encode(device.serialNumber, "UTF8") + "'>"
+ StringEscapeUtils.escapeHtml(accountHandler.getLabel()) + "</a>");
} else {
html.append("Not defined");
html.append("<a href='" + servletUrl + "/ids/?serialNumber="
+ URLEncoder.encode(device.serialNumber, "UTF8") + "'>"
+ StringEscapeUtils.escapeHtml("Not defined") + "</a>");
}
html.append("</td><td>");
html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.deviceFamily)));
html.append("</td><td>");
html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.deviceType)));
html.append("</td><td>");
html.append("</td></tr>");
html.append(StringEscapeUtils.escapeHtml(nullReplacement(device.deviceOwnerCustomerId)));
html.append("</td>");
html.append("</tr>");
}
html.append("</table>");
createPageEndAndSent(resp, html);
Expand Down Expand Up @@ -467,18 +475,36 @@ private void createPageEndAndSent(HttpServletResponse resp, StringBuilder html)
}
}

private void handleIds(HttpServletResponse resp, Connection connection, Device device, Thing thing)
private void handleIds(HttpServletResponse resp, Connection connection, Device device, @Nullable Thing thing)
throws IOException, URISyntaxException {
StringBuilder html = createPageStart("Channel Options - " + thing.getLabel());

StringBuilder html;
if (thing != null) {
html = createPageStart("Channel Options - " + thing.getLabel());
} else {
html = createPageStart("Device Information - No thing defined");
}
renderBluetoothMacChannel(connection, device, html);
renderAmazonMusicPlaylistIdChannel(connection, device, html);
renderPlayAlarmSoundChannel(connection, device, html);
renderMusicProviderIdChannel(connection, html);

renderCapabilities(connection, device, html);
createPageEndAndSent(resp, html);
}

private void renderCapabilities(Connection connection, Device device, StringBuilder html) {
html.append("<h2>Capabilities</h2>");
html.append("<table><tr><th align='left'>Name</th></tr>");
String[] capabilities = device.capabilities;
if (capabilities != null) {
for (String capability : capabilities) {
html.append("<tr><td>");
html.append(StringEscapeUtils.escapeHtml(capability));
html.append("</td></tr>");
}
}
html.append("</table>");
}

private void renderMusicProviderIdChannel(Connection connection, StringBuilder html) {
html.append("<h2>" + StringEscapeUtils.escapeHtml("Channel " + CHANNEL_MUSIC_PROVIDER_ID) + "</h2>");
html.append("<table><tr><th align='left'>Name</th><th align='left'>Value</th></tr>");
Expand Down Expand Up @@ -603,7 +629,7 @@ void handleProxyRequest(Connection connection, HttpServletResponse resp, String
headers.put("Referer", referer);
}

urlConnection = connection.makeRequest(verb, url, postData, json, false, headers);
urlConnection = connection.makeRequest(verb, url, postData, json, false, headers, false);
if (urlConnection.getResponseCode() == 302) {
{
String location = urlConnection.getHeaderField("location");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,4 @@ protected void doGet(@Nullable HttpServletRequest req, @Nullable HttpServletResp
logger.warn("return html failed with uri syntax error {}", e);
}
}

}
Loading