updatre lifx

This commit is contained in:
Admin
2017-02-07 15:50:21 -06:00
parent 0ac8061118
commit dd0032a567
4 changed files with 60 additions and 13 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>4.1.2c</version>
<version>4.1.2e</version>
<packaging>jar</packaging>
<name>HA Bridge</name>
@@ -124,7 +124,7 @@
<dependency>
<groupId>com.github.bwssytems</groupId>
<artifactId>lifx-sdk-java</artifactId>
<version>2.1.1</version>
<version>2.1.5</version>
</dependency>
</dependencies>

View File

@@ -19,15 +19,17 @@ import com.bwssystems.HABridge.hue.MultiCommandUtil;
import com.github.besherman.lifx.LFXClient;
import com.github.besherman.lifx.LFXGroup;
import com.github.besherman.lifx.LFXGroupCollection;
import com.github.besherman.lifx.LFXGroupCollectionListener;
import com.github.besherman.lifx.LFXLight;
import com.github.besherman.lifx.LFXLightCollection;
import com.github.besherman.lifx.LFXLightCollectionListener;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class LifxHome implements Home {
private static final Logger log = LoggerFactory.getLogger(LifxHome.class);
private Map<String, LifxDevice> lifxMap;
private LFXClient client = new LFXClient();
private LFXClient client;
private Boolean validLifx;
private Gson aGsonHandler;
@@ -45,20 +47,23 @@ public class LifxHome implements Home {
if(validLifx) {
try {
log.info("Open Lifx client....");
client.open(true);
lifxMap = new HashMap<String, LifxDevice>();
client = new LFXClient();
client.getLights().addLightCollectionListener(new MyLightListener(lifxMap));
client.getGroups().addGroupCollectionListener(new MyGroupListener(lifxMap));
client.open(false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.warn("Could not open LIFX, with IO Exception", e);
client = null;
return this;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.warn("Could not open LIFX, with Interruprted Exception", e);
client = null;
return this;
}
aGsonHandler =
new GsonBuilder()
.create();
lifxMap = new HashMap<String, LifxDevice>();
this.addLifxLights(client.getLights());
this.addLifxGroups(client.getGroups());
}
return this;
}
@@ -174,4 +179,46 @@ public class LifxHome implements Home {
return;
client.close();
}
private static class MyLightListener implements LFXLightCollectionListener {
private static final Logger log = LoggerFactory.getLogger(MyLightListener.class);
private Map<String, LifxDevice> aLifxMap;
public MyLightListener(Map<String, LifxDevice> theMap) {
aLifxMap = theMap;
}
@Override
public void lightAdded(LFXLight light) {
log.debug("Light added, label: " + light.getLabel() + " and id: " + light.getID());
LifxDevice aNewLifxDevice = new LifxDevice(light, LifxDevice.LIGHT_TYPE);
aLifxMap.put(aNewLifxDevice.toEntry().getName(), aNewLifxDevice);
}
@Override
public void lightRemoved(LFXLight light) {
log.debug("Light removed, label: " + light.getLabel() + " and id: " + light.getID());
aLifxMap.remove(light.getLabel());
}
}
private static class MyGroupListener implements LFXGroupCollectionListener {
private static final Logger log = LoggerFactory.getLogger(MyLightListener.class);
private Map<String, LifxDevice> aLifxMap;
public MyGroupListener(Map<String, LifxDevice> theMap) {
aLifxMap = theMap;
}
@Override
public void groupAdded(LFXGroup group) {
log.debug("Group: " + group.getLabel() + " added: " + group.size());
LifxDevice aNewLifxDevice = new LifxDevice(group, LifxDevice.GROUP_TYPE);
aLifxMap.put(aNewLifxDevice.toEntry().getName(), aNewLifxDevice);
}
@Override
public void groupRemoved(LFXGroup group) {
log.debug("Group: " + group.getLabel() + " removed");
aLifxMap.remove(group.getLabel());
}
}
}

View File

@@ -2374,7 +2374,7 @@ app.controller('LifxController', function ($scope, $location, $http, bridgeServi
bridgeService.viewHalDevices();
},
function (error) {
bridgeService.displayWarn("Error adding HAL devices in bulk.", error)
bridgeService.displayWarn("Error adding LIFX devices in bulk.", error)
}
);
$scope.bulk = { devices: [] };

View File

@@ -92,7 +92,7 @@
</tr>
</thead>
<tr
ng-repeat="device in bridge.devices | configuredLifxMsgs | orderBy:predicate:reverse">
ng-repeat="device in bridge.devices | configuredLifxItems | orderBy:predicate:reverse">
<td>{{$index+1}}</td>
<td>{{device.name}}</td>
<td>{{device.targetDevice}}</td>