mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 08:13:23 +00:00
updatre lifx
This commit is contained in:
4
pom.xml
4
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>4.1.2c</version>
|
<version>4.1.2e</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HA Bridge</name>
|
<name>HA Bridge</name>
|
||||||
@@ -124,7 +124,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.bwssytems</groupId>
|
<groupId>com.github.bwssytems</groupId>
|
||||||
<artifactId>lifx-sdk-java</artifactId>
|
<artifactId>lifx-sdk-java</artifactId>
|
||||||
<version>2.1.1</version>
|
<version>2.1.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -19,15 +19,17 @@ import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
|||||||
import com.github.besherman.lifx.LFXClient;
|
import com.github.besherman.lifx.LFXClient;
|
||||||
import com.github.besherman.lifx.LFXGroup;
|
import com.github.besherman.lifx.LFXGroup;
|
||||||
import com.github.besherman.lifx.LFXGroupCollection;
|
import com.github.besherman.lifx.LFXGroupCollection;
|
||||||
|
import com.github.besherman.lifx.LFXGroupCollectionListener;
|
||||||
import com.github.besherman.lifx.LFXLight;
|
import com.github.besherman.lifx.LFXLight;
|
||||||
import com.github.besherman.lifx.LFXLightCollection;
|
import com.github.besherman.lifx.LFXLightCollection;
|
||||||
|
import com.github.besherman.lifx.LFXLightCollectionListener;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
public class LifxHome implements Home {
|
public class LifxHome implements Home {
|
||||||
private static final Logger log = LoggerFactory.getLogger(LifxHome.class);
|
private static final Logger log = LoggerFactory.getLogger(LifxHome.class);
|
||||||
private Map<String, LifxDevice> lifxMap;
|
private Map<String, LifxDevice> lifxMap;
|
||||||
private LFXClient client = new LFXClient();
|
private LFXClient client;
|
||||||
private Boolean validLifx;
|
private Boolean validLifx;
|
||||||
private Gson aGsonHandler;
|
private Gson aGsonHandler;
|
||||||
|
|
||||||
@@ -45,20 +47,23 @@ public class LifxHome implements Home {
|
|||||||
if(validLifx) {
|
if(validLifx) {
|
||||||
try {
|
try {
|
||||||
log.info("Open Lifx client....");
|
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) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
log.warn("Could not open LIFX, with IO Exception", e);
|
||||||
e.printStackTrace();
|
client = null;
|
||||||
|
return this;
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// TODO Auto-generated catch block
|
log.warn("Could not open LIFX, with Interruprted Exception", e);
|
||||||
e.printStackTrace();
|
client = null;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
aGsonHandler =
|
aGsonHandler =
|
||||||
new GsonBuilder()
|
new GsonBuilder()
|
||||||
.create();
|
.create();
|
||||||
lifxMap = new HashMap<String, LifxDevice>();
|
|
||||||
this.addLifxLights(client.getLights());
|
|
||||||
this.addLifxGroups(client.getGroups());
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -174,4 +179,46 @@ public class LifxHome implements Home {
|
|||||||
return;
|
return;
|
||||||
client.close();
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2374,7 +2374,7 @@ app.controller('LifxController', function ($scope, $location, $http, bridgeServi
|
|||||||
bridgeService.viewHalDevices();
|
bridgeService.viewHalDevices();
|
||||||
},
|
},
|
||||||
function (error) {
|
function (error) {
|
||||||
bridgeService.displayWarn("Error adding HAL devices in bulk.", error)
|
bridgeService.displayWarn("Error adding LIFX devices in bulk.", error)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$scope.bulk = { devices: [] };
|
$scope.bulk = { devices: [] };
|
||||||
|
|||||||
@@ -92,7 +92,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tr
|
<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>{{$index+1}}</td>
|
||||||
<td>{{device.name}}</td>
|
<td>{{device.name}}</td>
|
||||||
<td>{{device.targetDevice}}</td>
|
<td>{{device.targetDevice}}</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user