Skip to content

Commit

Permalink
[amazonechocontrol] add support for smarthome devices (openhab#7969)
Browse files Browse the repository at this point in the history
Fix json parsing
Improve error handling
Remove unused Exception
* Changes for new build system
* Original
* Bugfixed for new version and merge request
* Added license information and author
* Added contributor and readme information
* Uncommented test comment for production use
* Removed the waitForUpdate variable - not used
* Added two configurations params for pulling interval and activating the smart bulbs
* [amazonechocontrol]
Formatting change
Fix for Announcment Channel
* Bugfixed discovery
* Bugfixed wrong entries of the amazon echo devices as lights
* [amazonechocontrol]
Fix for Announcment Channel
* Implemented recursive searching for devices, filtered smart plugs
* Added smart plugs
* Removed unused code, renamed new function and it's references
* Added translation
* Added documentation
* Added capabilities to smart home device
* Added dynamic channel adding
Improve smart home discover and and add options for openHAB smarthome devices
Handle on/off in percentage channel
Smart Home Device Handling
Update Smart Home Device Handling
Move Polling Timer to Account Handler
Remove polling from smart home handler
Alexa guard support
* [amazonechocontrol] Bugfix for login in Australia (openhab#6034)
Fix invalid device state
Bugfix and docu for announcment
Fix duplicate channel registration
Fix updates
Skill device detection
Improve channel handling
Color Name handling
Single device update
Color handling
Handle Security Panel Controller
Color handling
Alexa.AcousticEventSensor added
Code cleanup
Alexa.TemperatureSensor Interface
PowerLevelController, PercentageController
Add readme
Add To Do List
Fix nullable warning in Announcment
Fix nullable warning
Prepare Release Notes
SmartHome update groups
Fix spelling
Fix group initialization
* Removed unused file
* Removed unused file
* Error fixes
* codestyle
* Fix issues, codestyle and refactoring
* address review comment

Co-authored-by: Lkn94 <message@lukasknoeller.de>
Co-authored-by: Michael Geramb <mail@michael-geramb.at>
Co-authored-by: Lukas Knöller <lukask@hobbyblogging.de>
Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
  • Loading branch information
4 people authored and andrewfg committed Aug 31, 2020
1 parent 20fcf50 commit ee8e0f6
Show file tree
Hide file tree
Showing 57 changed files with 4,751 additions and 1,238 deletions.
305 changes: 269 additions & 36 deletions bundles/org.openhab.binding.amazonechocontrol/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2010-2020 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;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.amazonechocontrol.internal.handler.AccountHandler;

/**
* The {@link AccountHandlerConfig} holds the configuration for the {@link AccountHandler}
*
* @author Jan N. Klug - Initial contribution
*/
@NonNullByDefault
public class AccountHandlerConfig {
public int discoverSmartHome = 0;
public int pollingIntervalSmartHomeAlexa = 60;
public int pollingIntervalSmartSkills = 120;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.thing.Thing;
Expand All @@ -55,7 +54,6 @@
import com.google.gson.JsonSyntaxException;

/**
*
* Provides the following functions
* --- Login ---
* Simple http proxy to forward the login dialog from amazon to the user through the binding
Expand All @@ -76,33 +74,27 @@ public class AccountServlet extends HttpServlet {

private final Logger logger = LoggerFactory.getLogger(AccountServlet.class);

final HttpService httpService;
String servletUrlWithoutRoot;
final String servletUrl;
AccountHandler account;
String id;
@Nullable
Connection connectionToInitialize;
final Gson gson;
private final HttpService httpService;
private final String servletUrlWithoutRoot;
private final String servletUrl;
private final AccountHandler account;
private final String id;
private @Nullable Connection connectionToInitialize;
private final Gson gson;

public AccountServlet(HttpService httpService, String id, AccountHandler account, Gson gson) {
this.httpService = httpService;
this.account = account;
this.id = id;
this.gson = gson;

try {
servletUrlWithoutRoot = "amazonechocontrol/" + URLEncoder.encode(id, "UTF8");
} catch (UnsupportedEncodingException e) {
servletUrlWithoutRoot = "";
servletUrl = "";
logger.warn("Register servlet fails", e);
return;
}
servletUrl = "/" + servletUrlWithoutRoot;
try {
servletUrl = "/" + servletUrlWithoutRoot;

httpService.registerServlet(servletUrl, this, null, httpService.createDefaultHttpContext());
} catch (NamespaceException | ServletException e) {
logger.warn("Register servlet fails", e);
} catch (UnsupportedEncodingException | NamespaceException | ServletException e) {
throw new IllegalStateException(e.getMessage());
}
}

Expand Down Expand Up @@ -565,15 +557,15 @@ private void renderAmazonMusicPlaylistIdChannel(Connection connection, Device de
}

if (playLists != null) {
Map<@NonNull String, @Nullable PlayList @Nullable []> playlistMap = playLists.playlists;
Map<String, @Nullable PlayList @Nullable []> playlistMap = playLists.playlists;
if (playlistMap != null && !playlistMap.isEmpty()) {
html.append("<table><tr><th align='left'>Name</th><th align='left'>Value</th></tr>");

for (PlayList[] innerLists : playlistMap.values()) {
{
if (innerLists != null && innerLists.length > 0) {
PlayList playList = innerLists[0];
if (playList.playlistId != null && playList.title != null) {
if (playList != null && playList.playlistId != null && playList.title != null) {
html.append("<tr><td>");
html.append(StringEscapeUtils.escapeHtml(nullReplacement(playList.title)));
html.append("</td><td>");
Expand All @@ -593,24 +585,32 @@ private void renderAmazonMusicPlaylistIdChannel(Connection connection, Device de
private void renderBluetoothMacChannel(Connection connection, Device device, StringBuilder html) {
html.append("<h2>" + StringEscapeUtils.escapeHtml("Channel " + CHANNEL_BLUETOOTH_MAC) + "</h2>");
JsonBluetoothStates bluetoothStates = connection.getBluetoothConnectionStates();
if (bluetoothStates == null) {
return;
}
BluetoothState[] innerStates = bluetoothStates.bluetoothStates;
if (innerStates != null) {
for (BluetoothState state : innerStates) {
if (StringUtils.equals(state.deviceSerialNumber, device.serialNumber)) {
PairedDevice[] pairedDeviceList = state.pairedDeviceList;
if (pairedDeviceList != null && pairedDeviceList.length > 0) {
html.append("<table><tr><th align='left'>Name</th><th align='left'>Value</th></tr>");
for (PairedDevice pairedDevice : pairedDeviceList) {
html.append("<tr><td>");
html.append(StringEscapeUtils.escapeHtml(nullReplacement(pairedDevice.friendlyName)));
html.append("</td><td>");
html.append(StringEscapeUtils.escapeHtml(nullReplacement(pairedDevice.address)));
html.append("</td></tr>");
}
html.append("</table>");
} else {
html.append(StringEscapeUtils.escapeHtml("No bluetooth devices paired"));
if (innerStates == null) {
return;
}
for (BluetoothState state : innerStates) {
if (state == null) {
continue;
}
if ((state.deviceSerialNumber == null && device.serialNumber == null)
|| (state.deviceSerialNumber != null && state.deviceSerialNumber.equals(device.serialNumber))) {
PairedDevice[] pairedDeviceList = state.pairedDeviceList;
if (pairedDeviceList != null && pairedDeviceList.length > 0) {
html.append("<table><tr><th align='left'>Name</th><th align='left'>Value</th></tr>");
for (PairedDevice pairedDevice : pairedDeviceList) {
html.append("<tr><td>");
html.append(StringEscapeUtils.escapeHtml(nullReplacement(pairedDevice.friendlyName)));
html.append("</td><td>");
html.append(StringEscapeUtils.escapeHtml(nullReplacement(pairedDevice.address)));
html.append("</td></tr>");
}
html.append("</table>");
} else {
html.append(StringEscapeUtils.escapeHtml("No bluetooth devices paired"));
}
}
}
Expand Down
Loading

0 comments on commit ee8e0f6

Please sign in to comment.