mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-16 18:24:36 +00:00
Updated harmony hub disconnect handling
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>com.bwssystems.HABridge</groupId>
|
<groupId>com.bwssystems.HABridge</groupId>
|
||||||
<artifactId>ha-bridge</artifactId>
|
<artifactId>ha-bridge</artifactId>
|
||||||
<version>5.2.2RC2</version>
|
<version>5.2.2RC3</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HA Bridge</name>
|
<name>HA Bridge</name>
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public class HarmonyHandler {
|
|||||||
listOfActivities = harmonyClient.getConfig().getActivities();
|
listOfActivities = harmonyClient.getConfig().getActivities();
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
handleExceptionError(e);
|
handleExceptionError(e);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return listOfActivities;
|
return listOfActivities;
|
||||||
@@ -59,6 +60,7 @@ public class HarmonyHandler {
|
|||||||
listOfDevices = harmonyClient.getConfig().getDevices();
|
listOfDevices = harmonyClient.getConfig().getDevices();
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
handleExceptionError(e);
|
handleExceptionError(e);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return listOfDevices;
|
return listOfDevices;
|
||||||
}
|
}
|
||||||
@@ -73,6 +75,7 @@ public class HarmonyHandler {
|
|||||||
aConfig = harmonyClient.getConfig();
|
aConfig = harmonyClient.getConfig();
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
handleExceptionError(e);
|
handleExceptionError(e);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return aConfig;
|
return aConfig;
|
||||||
}
|
}
|
||||||
@@ -87,6 +90,7 @@ public class HarmonyHandler {
|
|||||||
anActivity = harmonyClient.getCurrentActivity();
|
anActivity = harmonyClient.getCurrentActivity();
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
handleExceptionError(e);
|
handleExceptionError(e);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return anActivity;
|
return anActivity;
|
||||||
}
|
}
|
||||||
@@ -112,16 +116,14 @@ public class HarmonyHandler {
|
|||||||
harmonyClient.startActivityByName(anActivity.getName());
|
harmonyClient.startActivityByName(anActivity.getName());
|
||||||
} catch (IllegalArgumentException ei) {
|
} catch (IllegalArgumentException ei) {
|
||||||
log.error("Error in finding activity: " + anActivity.getName() + " for a hub: " + anActivity.getHub());
|
log.error("Error in finding activity: " + anActivity.getName() + " for a hub: " + anActivity.getHub());
|
||||||
return false;
|
|
||||||
} catch (RuntimeException e1) {
|
} catch (RuntimeException e1) {
|
||||||
handleExceptionError(e1);
|
return handleExceptionError(e1);
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e1) {
|
} catch (RuntimeException e1) {
|
||||||
handleExceptionError(e1);
|
return handleExceptionError(e1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.error("Error in finding activity: " + anActivity.getName() + " for a hub: " + anActivity.getHub());
|
log.error("Error in finding activity: " + anActivity.getName() + " for a hub: " + anActivity.getHub());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -147,40 +149,45 @@ public class HarmonyHandler {
|
|||||||
harmonyClient.pressButton(aDeviceButton.getDevice(), aDeviceButton.getButton());
|
harmonyClient.pressButton(aDeviceButton.getDevice(), aDeviceButton.getButton());
|
||||||
} catch (IllegalArgumentException ei) {
|
} catch (IllegalArgumentException ei) {
|
||||||
log.error("Error in finding device: " + aDeviceButton.getDevice() +" and a button: " + aDeviceButton.getButton() + " for a hub: " + aDeviceButton.getHub());
|
log.error("Error in finding device: " + aDeviceButton.getDevice() +" and a button: " + aDeviceButton.getButton() + " for a hub: " + aDeviceButton.getHub());
|
||||||
return false;
|
|
||||||
} catch (RuntimeException e1) {
|
} catch (RuntimeException e1) {
|
||||||
handleExceptionError(e1);
|
return handleExceptionError(e1);
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e1) {
|
} catch (RuntimeException e1) {
|
||||||
handleExceptionError(e1);
|
return handleExceptionError(e1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.error("Error in finding device: " + aDeviceButton.getDevice() +" and a button: " + aDeviceButton.getButton() + " for a hub: " + aDeviceButton.getHub());
|
log.error("Error in finding device: " + aDeviceButton.getDevice() +" and a button: " + aDeviceButton.getButton() + " for a hub: " + aDeviceButton.getHub());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean handleExceptionError(Exception e) {
|
||||||
|
if(e.getMessage().equalsIgnoreCase("Failed communicating with Harmony Hub")) {
|
||||||
|
log.warn("Issue in communcicating with Harmony Hub, retrying connect....");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleExceptionError(Exception e) {
|
|
||||||
if(e.getMessage().equalsIgnoreCase("Failed communicating with Harmony Hub")) {
|
|
||||||
log.warn("Issue in communcicating with Harmony Hub, retrying connect....");
|
|
||||||
try {
|
|
||||||
harmonyClient.disconnect();
|
|
||||||
} catch(Exception e1) {
|
|
||||||
log.warn("Hub disconnect failed, continuing....");
|
|
||||||
}
|
|
||||||
harmonyClient.connect(myNameAndIP.getIp());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
log.debug("Harmony api shutdown requested.");
|
log.debug("Harmony api shutdown requested.");
|
||||||
if(devMode)
|
if(devMode)
|
||||||
return;
|
return;
|
||||||
|
try {
|
||||||
harmonyClient.disconnect();
|
harmonyClient.disconnect();
|
||||||
|
} catch(Exception e)
|
||||||
|
{
|
||||||
|
// noop
|
||||||
|
}
|
||||||
harmonyClient = null;
|
harmonyClient = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the myNameAndIP
|
||||||
|
*/
|
||||||
|
public NamedIP getMyNameAndIP() {
|
||||||
|
return myNameAndIP;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import net.whistlingfish.harmony.config.Activity;
|
|||||||
import net.whistlingfish.harmony.config.Device;
|
import net.whistlingfish.harmony.config.Device;
|
||||||
|
|
||||||
public class HarmonyHome implements Home {
|
public class HarmonyHome implements Home {
|
||||||
private static final Logger log = LoggerFactory.getLogger(HarmonyHome.class);
|
private static final Logger log = LoggerFactory.getLogger(HarmonyHome.class);
|
||||||
private Map<String, HarmonyServer> hubs;
|
private Map<String, HarmonyServer> hubs;
|
||||||
private Boolean isDevMode;
|
private Boolean isDevMode;
|
||||||
private Boolean validHarmony;
|
private Boolean validHarmony;
|
||||||
@@ -43,91 +43,118 @@ public class HarmonyHome implements Home {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeHome() {
|
public void closeHome() {
|
||||||
if(!validHarmony)
|
if (!validHarmony)
|
||||||
return;
|
return;
|
||||||
log.debug("Closing Home.");
|
log.debug("Closing Home.");
|
||||||
if(closed) {
|
if (closed) {
|
||||||
log.debug("Home is already closed....");
|
log.debug("Home is already closed....");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(isDevMode || hubs == null)
|
if (isDevMode || hubs == null)
|
||||||
return;
|
return;
|
||||||
Iterator<String> keys = hubs.keySet().iterator();
|
Iterator<String> keys = hubs.keySet().iterator();
|
||||||
while(keys.hasNext()) {
|
while (keys.hasNext()) {
|
||||||
String key = keys.next();
|
String key = keys.next();
|
||||||
hubs.get(key).getMyHarmony().shutdown();
|
hubs.get(key).getMyHarmony().shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
hubs = null;
|
hubs = null;
|
||||||
closed = true;
|
closed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HarmonyHandler getHarmonyHandler(String aName) {
|
public HarmonyHandler getHarmonyHandler(String aName) {
|
||||||
if(!validHarmony)
|
if (!validHarmony)
|
||||||
return null;
|
return null;
|
||||||
HarmonyHandler aHandler = null;
|
HarmonyHandler aHandler = null;
|
||||||
if(aName == null || aName.equals("")) {
|
if (aName == null || aName.equals("")) {
|
||||||
aName = "default";
|
aName = "default";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hubs.get(aName) == null) {
|
if (hubs.get(aName) == null) {
|
||||||
Set<String> keys = hubs.keySet();
|
Set<String> keys = hubs.keySet();
|
||||||
if(!keys.isEmpty()) {
|
if (!keys.isEmpty()) {
|
||||||
aHandler = hubs.get(keys.toArray()[0]).getMyHarmony();
|
aHandler = hubs.get(keys.toArray()[0]).getMyHarmony();
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
aHandler = null;
|
aHandler = null;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
aHandler = hubs.get(aName).getMyHarmony();
|
aHandler = hubs.get(aName).getMyHarmony();
|
||||||
return aHandler;
|
return aHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HarmonyActivity> getActivities() {
|
public List<HarmonyActivity> getActivities() {
|
||||||
Iterator<String> keys = hubs.keySet().iterator();
|
Iterator<String> keys = hubs.keySet().iterator();
|
||||||
ArrayList<HarmonyActivity> activityList = new ArrayList<HarmonyActivity>();
|
ArrayList<HarmonyActivity> activityList = new ArrayList<HarmonyActivity>();
|
||||||
if(!validHarmony)
|
if (!validHarmony)
|
||||||
return null;
|
return null;
|
||||||
while(keys.hasNext()) {
|
while (keys.hasNext()) {
|
||||||
String key = keys.next();
|
String key = keys.next();
|
||||||
Iterator<Activity> activities = hubs.get(key).getMyHarmony().getActivities().iterator();
|
Iterator<Activity> activities = hubs.get(key).getMyHarmony().getActivities().iterator();
|
||||||
while(activities.hasNext()) {
|
if (activities == null) {
|
||||||
|
resetHub(hubs.get(key).getMyHarmony());
|
||||||
|
activities = hubs.get(key).getMyHarmony().getActivities().iterator();
|
||||||
|
if (activities == null) {
|
||||||
|
log.error("Could not get communication restored with hub: " + key + ", please restart...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (activities != null) {
|
||||||
|
while (activities.hasNext()) {
|
||||||
|
HarmonyActivity anActivity = new HarmonyActivity();
|
||||||
|
anActivity.setActivity(activities.next());
|
||||||
|
anActivity.setHub(key);
|
||||||
|
activityList.add(anActivity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return activityList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<HarmonyActivity> getCurrentActivities() {
|
||||||
|
Iterator<String> keys = hubs.keySet().iterator();
|
||||||
|
ArrayList<HarmonyActivity> activityList = new ArrayList<HarmonyActivity>();
|
||||||
|
if (!validHarmony)
|
||||||
|
return null;
|
||||||
|
while (keys.hasNext()) {
|
||||||
|
String key = keys.next();
|
||||||
|
Activity theActivity = hubs.get(key).getMyHarmony().getCurrentActivity();
|
||||||
|
if (theActivity == null) {
|
||||||
|
resetHub(hubs.get(key).getMyHarmony());
|
||||||
|
theActivity = hubs.get(key).getMyHarmony().getCurrentActivity();
|
||||||
|
if (theActivity == null) {
|
||||||
|
log.error("Could not get communication restored with hub: " + key + ", please restart...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (theActivity != null) {
|
||||||
HarmonyActivity anActivity = new HarmonyActivity();
|
HarmonyActivity anActivity = new HarmonyActivity();
|
||||||
anActivity.setActivity(activities.next());
|
anActivity.setActivity(theActivity);
|
||||||
anActivity.setHub(key);
|
anActivity.setHub(key);
|
||||||
activityList.add(anActivity);
|
activityList.add(anActivity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return activityList;
|
return activityList;
|
||||||
}
|
}
|
||||||
public List<HarmonyActivity> getCurrentActivities() {
|
|
||||||
Iterator<String> keys = hubs.keySet().iterator();
|
|
||||||
ArrayList<HarmonyActivity> activityList = new ArrayList<HarmonyActivity>();
|
|
||||||
if(!validHarmony)
|
|
||||||
return null;
|
|
||||||
while(keys.hasNext()) {
|
|
||||||
String key = keys.next();
|
|
||||||
Activity theActivity = hubs.get(key).getMyHarmony().getCurrentActivity();
|
|
||||||
HarmonyActivity anActivity = new HarmonyActivity();
|
|
||||||
anActivity.setActivity(theActivity);
|
|
||||||
anActivity.setHub(key);
|
|
||||||
activityList.add(anActivity);
|
|
||||||
}
|
|
||||||
return activityList;
|
|
||||||
}
|
|
||||||
public List<HarmonyDevice> getDevices() {
|
public List<HarmonyDevice> getDevices() {
|
||||||
Iterator<String> keys = hubs.keySet().iterator();
|
Iterator<String> keys = hubs.keySet().iterator();
|
||||||
ArrayList<HarmonyDevice> deviceList = new ArrayList<HarmonyDevice>();
|
ArrayList<HarmonyDevice> deviceList = new ArrayList<HarmonyDevice>();
|
||||||
if(!validHarmony)
|
if (!validHarmony)
|
||||||
return null;
|
return null;
|
||||||
while(keys.hasNext()) {
|
while (keys.hasNext()) {
|
||||||
String key = keys.next();
|
String key = keys.next();
|
||||||
Iterator<Device> devices = hubs.get(key).getMyHarmony().getDevices().iterator();
|
Iterator<Device> devices = hubs.get(key).getMyHarmony().getDevices().iterator();
|
||||||
while(devices.hasNext()) {
|
if (devices == null) {
|
||||||
HarmonyDevice aDevice = new HarmonyDevice();
|
resetHub(hubs.get(key).getMyHarmony());
|
||||||
aDevice.setDevice(devices.next());
|
devices = hubs.get(key).getMyHarmony().getDevices().iterator();
|
||||||
aDevice.setHub(key);
|
if (devices == null) {
|
||||||
deviceList.add(aDevice);
|
log.error("Could not get communication restored with hub: " + key + ", please restart...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (devices != null) {
|
||||||
|
while (devices.hasNext()) {
|
||||||
|
HarmonyDevice aDevice = new HarmonyDevice();
|
||||||
|
aDevice.setDevice(devices.next());
|
||||||
|
aDevice.setHub(key);
|
||||||
|
deviceList.add(aDevice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return deviceList;
|
return deviceList;
|
||||||
@@ -135,23 +162,22 @@ public class HarmonyHome implements Home {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
|
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
|
||||||
Integer targetBri,Integer targetBriInc, ColorData colorData, DeviceDescriptor device, String body) {
|
Integer targetBri, Integer targetBriInc, ColorData colorData, DeviceDescriptor device, String body) {
|
||||||
String responseString = null;
|
String responseString = null;
|
||||||
log.debug("executing HUE api request to change " + anItem.getType() + " to Harmony: " + device.getName());
|
log.debug("executing HUE api request to change " + anItem.getType() + " to Harmony: " + device.getName());
|
||||||
if(!validHarmony) {
|
if (!validHarmony) {
|
||||||
log.warn("Should not get here, no harmony configured");
|
log.warn("Should not get here, no harmony configured");
|
||||||
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
|
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
|
||||||
+ "\",\"description\": \"Should not get here, no harmony configured\", \"parameter\": \"/lights/"
|
+ "\",\"description\": \"Should not get here, no harmony configured\", \"parameter\": \"/lights/"
|
||||||
+ lightId + "state\"}}]";
|
+ lightId + "state\"}}]";
|
||||||
} else {
|
} else {
|
||||||
if(anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.typeIndex]))
|
if (anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.typeIndex])) {
|
||||||
{
|
|
||||||
RunActivity anActivity = null;
|
RunActivity anActivity = null;
|
||||||
if(anItem.getItem().isJsonObject())
|
if (anItem.getItem().isJsonObject())
|
||||||
anActivity = aGsonHandler.fromJson(anItem.getItem(), RunActivity.class);
|
anActivity = aGsonHandler.fromJson(anItem.getItem(), RunActivity.class);
|
||||||
else
|
else
|
||||||
anActivity = aGsonHandler.fromJson(anItem.getItem().getAsString(), RunActivity.class);
|
anActivity = aGsonHandler.fromJson(anItem.getItem().getAsString(), RunActivity.class);
|
||||||
if(anActivity.getHub() == null || anActivity.getHub().isEmpty())
|
if (anActivity.getHub() == null || anActivity.getHub().isEmpty())
|
||||||
anActivity.setHub(device.getTargetDevice());
|
anActivity.setHub(device.getTargetDevice());
|
||||||
HarmonyHandler myHarmony = getHarmonyHandler(anActivity.getHub());
|
HarmonyHandler myHarmony = getHarmonyHandler(anActivity.getHub());
|
||||||
if (myHarmony == null) {
|
if (myHarmony == null) {
|
||||||
@@ -160,11 +186,23 @@ public class HarmonyHome implements Home {
|
|||||||
+ "\",\"description\": \"Should not get here, no harmony hub available\", \"parameter\": \"/lights/"
|
+ "\",\"description\": \"Should not get here, no harmony hub available\", \"parameter\": \"/lights/"
|
||||||
+ lightId + "state\"}}]";
|
+ lightId + "state\"}}]";
|
||||||
} else {
|
} else {
|
||||||
myHarmony.startActivity(anActivity);
|
if (!myHarmony.startActivity(anActivity)) {
|
||||||
|
if (resetHub(myHarmony)) {
|
||||||
|
myHarmony = getHarmonyHandler(anActivity.getHub());
|
||||||
|
if (!myHarmony.startActivity(anActivity)) {
|
||||||
|
log.error("Could not get communication restored with hub: " + anActivity.getHub()
|
||||||
|
+ ", please restart...");
|
||||||
|
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
|
||||||
|
+ "\",\"description\": \"Could not communicate with harmony\", \"parameter\": \"/lights/"
|
||||||
|
+ lightId + "state\"}}]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if(anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex])) {
|
} else if (anItem.getType().trim()
|
||||||
|
.equalsIgnoreCase(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex])) {
|
||||||
String url = null;
|
String url = null;
|
||||||
if(anItem.getItem().isJsonObject() || anItem.getItem().isJsonArray()) {
|
if (anItem.getItem().isJsonObject() || anItem.getItem().isJsonArray()) {
|
||||||
url = aGsonHandler.toJson(anItem.getItem());
|
url = aGsonHandler.toJson(anItem.getItem());
|
||||||
} else
|
} else
|
||||||
url = anItem.getItem().getAsString();
|
url = anItem.getItem().getAsString();
|
||||||
@@ -172,35 +210,50 @@ public class HarmonyHome implements Home {
|
|||||||
if (url.substring(0, 1).equalsIgnoreCase("{")) {
|
if (url.substring(0, 1).equalsIgnoreCase("{")) {
|
||||||
url = "[" + url + "]";
|
url = "[" + url + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
url = BrightnessDecode.calculateReplaceIntensityValue(url, intensity, targetBri, targetBriInc, false);
|
url = BrightnessDecode.calculateReplaceIntensityValue(url, intensity, targetBri, targetBriInc, false);
|
||||||
ButtonPress[] deviceButtons = aGsonHandler.fromJson(url, ButtonPress[].class);
|
ButtonPress[] deviceButtons = aGsonHandler.fromJson(url, ButtonPress[].class);
|
||||||
Integer theCount = 1;
|
Integer theCount = 1;
|
||||||
for(int z = 0; z < deviceButtons.length; z++) {
|
for (int z = 0; z < deviceButtons.length; z++) {
|
||||||
if(deviceButtons[z].getCount() != null && deviceButtons[z].getCount() > 0)
|
if (deviceButtons[z].getCount() != null && deviceButtons[z].getCount() > 0)
|
||||||
theCount = deviceButtons[z].getCount();
|
theCount = deviceButtons[z].getCount();
|
||||||
for(int y = 0; y < theCount; y++) {
|
for (int y = 0; y < theCount; y++) {
|
||||||
if( y > 0 || z > 0) {
|
if (y > 0 || z > 0) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(aMultiUtil.getTheDelay());
|
Thread.sleep(aMultiUtil.getTheDelay());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// ignore
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (anItem.getDelay() != null && anItem.getDelay() > 0)
|
||||||
|
aMultiUtil.setTheDelay(anItem.getDelay());
|
||||||
|
else
|
||||||
|
aMultiUtil.setTheDelay(aMultiUtil.getDelayDefault());
|
||||||
|
log.debug("pressing button: " + deviceButtons[z].getDevice() + " - "
|
||||||
|
+ deviceButtons[z].getButton() + " with pressTime of: "
|
||||||
|
+ deviceButtons[z].getPressTime() + " - iteration: " + String.valueOf(z) + " - count: "
|
||||||
|
+ String.valueOf(y));
|
||||||
|
if (deviceButtons[z].getHub() == null || deviceButtons[z].getHub().isEmpty())
|
||||||
|
deviceButtons[z].setHub(device.getTargetDevice());
|
||||||
|
HarmonyHandler myHarmony = getHarmonyHandler(deviceButtons[z].getHub());
|
||||||
|
if (myHarmony == null)
|
||||||
|
log.warn("Button Press - Should not get here, no harmony hub available");
|
||||||
|
else{
|
||||||
|
if (myHarmony.pressButton(deviceButtons[z])) {
|
||||||
|
if (resetHub(myHarmony)) {
|
||||||
|
myHarmony = getHarmonyHandler(deviceButtons[z].getHub());
|
||||||
|
if (!myHarmony.pressButton(deviceButtons[z])) {
|
||||||
|
log.error("Could not get communication restored with hub: " + deviceButtons[z].getHub()
|
||||||
|
+ ", please restart...");
|
||||||
|
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
|
||||||
|
+ "\",\"description\": \"Could not communicate with harmony\", \"parameter\": \"/lights/"
|
||||||
|
+ lightId + "state\"}}]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (anItem.getDelay() != null && anItem.getDelay() > 0)
|
}
|
||||||
aMultiUtil.setTheDelay(anItem.getDelay());
|
}
|
||||||
else
|
}
|
||||||
aMultiUtil.setTheDelay(aMultiUtil.getDelayDefault());
|
|
||||||
log.debug("pressing button: " + deviceButtons[z].getDevice() + " - " + deviceButtons[z].getButton() + " with pressTime of: " + deviceButtons[z].getPressTime() + " - iteration: " + String.valueOf(z) + " - count: " + String.valueOf(y));
|
|
||||||
if(deviceButtons[z].getHub() == null || deviceButtons[z].getHub().isEmpty())
|
|
||||||
deviceButtons[z].setHub(device.getTargetDevice());
|
|
||||||
HarmonyHandler myHarmony = getHarmonyHandler(deviceButtons[z].getHub());
|
|
||||||
if (myHarmony == null)
|
|
||||||
log.warn("Button Press - Should not get here, no harmony hub available");
|
|
||||||
else
|
|
||||||
myHarmony.pressButton(deviceButtons[z]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return responseString;
|
return responseString;
|
||||||
@@ -208,15 +261,14 @@ public class HarmonyHome implements Home {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Home createHome(BridgeSettings bridgeSettings) {
|
public Home createHome(BridgeSettings bridgeSettings) {
|
||||||
isDevMode = Boolean.parseBoolean(System.getProperty("dev.mode", "false"));
|
isDevMode = Boolean.parseBoolean(System.getProperty("dev.mode", "false"));
|
||||||
validHarmony = bridgeSettings.getBridgeSettingsDescriptor().isValidHarmony();
|
validHarmony = bridgeSettings.getBridgeSettingsDescriptor().isValidHarmony();
|
||||||
log.info("Harmony Home created." + (validHarmony ? "" : " No Harmony devices configured.") + (isDevMode ? " DevMode is set." : ""));
|
log.info("Harmony Home created." + (validHarmony ? "" : " No Harmony devices configured.")
|
||||||
if(validHarmony || isDevMode) {
|
+ (isDevMode ? " DevMode is set." : ""));
|
||||||
|
if (validHarmony || isDevMode) {
|
||||||
hubs = new HashMap<String, HarmonyServer>();
|
hubs = new HashMap<String, HarmonyServer>();
|
||||||
aGsonHandler =
|
aGsonHandler = new GsonBuilder().create();
|
||||||
new GsonBuilder()
|
if (isDevMode) {
|
||||||
.create();
|
|
||||||
if(isDevMode) {
|
|
||||||
NamedIP devModeIp = new NamedIP();
|
NamedIP devModeIp = new NamedIP();
|
||||||
devModeIp.setIp("10.10.10.10");
|
devModeIp.setIp("10.10.10.10");
|
||||||
devModeIp.setName("devMode");
|
devModeIp.setName("devMode");
|
||||||
@@ -226,19 +278,21 @@ public class HarmonyHome implements Home {
|
|||||||
thedevList.setDevices(theList);
|
thedevList.setDevices(theList);
|
||||||
bridgeSettings.getBridgeSettingsDescriptor().setHarmonyAddress(thedevList);
|
bridgeSettings.getBridgeSettingsDescriptor().setHarmonyAddress(thedevList);
|
||||||
}
|
}
|
||||||
Iterator<NamedIP> theList = bridgeSettings.getBridgeSettingsDescriptor().getHarmonyAddress().getDevices().iterator();
|
Iterator<NamedIP> theList = bridgeSettings.getBridgeSettingsDescriptor().getHarmonyAddress().getDevices()
|
||||||
while(theList.hasNext() && validHarmony) {
|
.iterator();
|
||||||
|
while (theList.hasNext() && validHarmony) {
|
||||||
NamedIP aHub = theList.next();
|
NamedIP aHub = theList.next();
|
||||||
boolean loopControl = true;
|
boolean loopControl = true;
|
||||||
int retryCount = 0;
|
int retryCount = 0;
|
||||||
while(loopControl) {
|
while (loopControl) {
|
||||||
try {
|
try {
|
||||||
hubs.put(aHub.getName(), HarmonyServer.setup(bridgeSettings.getBridgeSettingsDescriptor(), isDevMode, aHub));
|
hubs.put(aHub.getName(), HarmonyServer.setup(isDevMode, aHub));
|
||||||
loopControl = false;
|
loopControl = false;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if(retryCount > 3) {
|
if (retryCount > 3) {
|
||||||
log.error("Cannot get harmony client (" + aHub.getName() + ") setup, Exiting with message: " + e.getMessage(), e);
|
log.error("Cannot get harmony client (" + aHub.getName() + ") setup, Exiting with message: "
|
||||||
loopControl = false;
|
+ e.getMessage(), e);
|
||||||
|
loopControl = false;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
@@ -246,25 +300,44 @@ public class HarmonyHome implements Home {
|
|||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
retryCount++;
|
retryCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(hubs.isEmpty())
|
if (hubs.isEmpty())
|
||||||
validHarmony = false;
|
validHarmony = false;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean resetHub(HarmonyHandler aHarmony) {
|
||||||
|
boolean resetSuccess = false;
|
||||||
|
isDevMode = Boolean.parseBoolean(System.getProperty("dev.mode", "false"));
|
||||||
|
NamedIP resetIp = aHarmony.getMyNameAndIP();
|
||||||
|
log.info("Resetting harmony hub due to communication errror: " + resetIp.getName());
|
||||||
|
if (!isDevMode) {
|
||||||
|
try {
|
||||||
|
hubs.remove(resetIp.getName());
|
||||||
|
aHarmony.shutdown();
|
||||||
|
hubs.put(resetIp.getName(), HarmonyServer.setup(isDevMode, resetIp));
|
||||||
|
resetSuccess = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Cannot reset harmony client (" + resetIp.getName() + "), Exiting with message: "
|
||||||
|
+ e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resetSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getItems(String type) {
|
public Object getItems(String type) {
|
||||||
if(validHarmony) {
|
if (validHarmony) {
|
||||||
if(type.equalsIgnoreCase(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.typeIndex]))
|
if (type.equalsIgnoreCase(DeviceMapTypes.HARMONY_ACTIVITY[DeviceMapTypes.typeIndex]))
|
||||||
return getActivities();
|
return getActivities();
|
||||||
if(type.equalsIgnoreCase(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex]))
|
if (type.equalsIgnoreCase(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex]))
|
||||||
return getDevices();
|
return getDevices();
|
||||||
if(type.equalsIgnoreCase("current_activity"))
|
if (type.equalsIgnoreCase("current_activity"))
|
||||||
return getCurrentActivities();
|
return getCurrentActivities();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -272,7 +345,7 @@ public class HarmonyHome implements Home {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import org.apache.http.client.methods.HttpGet;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
|
||||||
import com.bwssystems.HABridge.NamedIP;
|
import com.bwssystems.HABridge.NamedIP;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
@@ -50,11 +49,10 @@ public class HarmonyServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static HarmonyServer setup(
|
public static HarmonyServer setup(
|
||||||
BridgeSettingsDescriptor bridgeSettings,
|
|
||||||
Boolean harmonyDevMode,
|
Boolean harmonyDevMode,
|
||||||
NamedIP theHarmonyAddress
|
NamedIP theHarmonyAddress
|
||||||
) throws Exception {
|
) throws Exception {
|
||||||
if (!bridgeSettings.isValidHarmony() && harmonyDevMode) {
|
if (harmonyDevMode) {
|
||||||
return new HarmonyServer(theHarmonyAddress);
|
return new HarmonyServer(theHarmonyAddress);
|
||||||
}
|
}
|
||||||
Injector injector = null;
|
Injector injector = null;
|
||||||
@@ -65,11 +63,11 @@ public class HarmonyServer {
|
|||||||
if (!harmonyDevMode) {
|
if (!harmonyDevMode) {
|
||||||
injector.injectMembers(mainObject);
|
injector.injectMembers(mainObject);
|
||||||
}
|
}
|
||||||
mainObject.execute(bridgeSettings, harmonyDevMode);
|
mainObject.execute(harmonyDevMode);
|
||||||
return mainObject;
|
return mainObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(BridgeSettingsDescriptor mySettings, Boolean harmonyDevMode) throws Exception {
|
private void execute(Boolean harmonyDevMode) throws Exception {
|
||||||
Boolean noopCalls = Boolean.parseBoolean(System.getProperty("noop.calls", "false"));
|
Boolean noopCalls = Boolean.parseBoolean(System.getProperty("noop.calls", "false"));
|
||||||
isDevMode = harmonyDevMode;
|
isDevMode = harmonyDevMode;
|
||||||
String modeString = "";
|
String modeString = "";
|
||||||
|
|||||||
Reference in New Issue
Block a user