Skip to content

Commit 5a59747

Browse files
authored
Merge pull request #141 from bwssytems/hal-integration
Hal integration and other enhancement and fixes
2 parents 51ce10c + 53ec096 commit 5a59747

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3795
-1546
lines changed

README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Then locate the jar and start the server with:
2121
ATTENTION: This requires JDK 1.8 to run
2222

2323
```
24-
java -jar ha-bridge-2.0.6.jar
24+
java -jar ha-bridge-2.5.0.jar
2525
```
2626
### Automation on Linux systems
2727
To have this configured and running automatically there are a few resources to use. One is using Docker and a docker container has been built for this and can be gotten here: https://github.com/aptalca/docker-ha-bridge
@@ -35,19 +35,19 @@ After=network.target
3535
3636
[Service]
3737
Type=simple
38-
ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/amazon-echo/data/habridge.config /home/pi/amazon-echo/ha-bridge-2.0.6.jar
38+
ExecStart=/usr/bin/java -jar -Dconfig.file=/home/pi/amazon-echo/data/habridge.config /home/pi/amazon-echo/ha-bridge-2.5.0.jar
3939
4040
[Install]
4141
WantedBy=multi-user.target
4242
```
4343

4444
Basic script setup to run the bridge on a pi.
4545

46-
Create the directory and make sure that ha-bridge-2.0.6.jar is in your /home/pi/habridge directory.
46+
Create the directory and make sure that ha-bridge-2.5.0.jar is in your /home/pi/habridge directory.
4747
```
4848
pi@raspberrypi:~ $ mkdir habridge
4949
pi@raspberrypi:~ $ cd habridge
50-
pi@raspberrypi:~/habridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v2.0.6/ha-bridge-2.0.6.jar
50+
pi@raspberrypi:~/habridge $ wget https://github.com/bwssytems/ha-bridge/releases/download/v2.0.6/ha-bridge-2.5.0.jar
5151
```
5252
Edit the shell script for starting:
5353
```
@@ -57,7 +57,7 @@ Then cut and past this, modify any locations that are not correct
5757
```
5858
cd /home/pi/habridge
5959
rm /home/pi/habridge/habridge-log.txt
60-
nohup java -jar /home/pi/habridge/ha-bridge-2.0.6.jar > /home/pi/habridge/habridge-log.txt 2>&1 &
60+
nohup java -jar /home/pi/habridge/ha-bridge-2.5.0.jar > /home/pi/habridge/habridge-log.txt 2>&1 &
6161
chmod 777 /home/pi/habridge/habridge-log.txt
6262
```
6363
Exit and save the file with ctrl-X and follow the prompts and then execute on the command line:
@@ -109,7 +109,7 @@ The server defaults to running on port 8080. To override what the default is, sp
109109
#### UPNP Response Port
110110
The upnp response port that will be used. The default is 50000.
111111
#### Vera Names and IP Addresses
112-
Provide IP Addresses of your Veras that you want to utilize with the bridge. Also, give a meaningful name to each one so it is easy to decipher in the helper tab. When these names and IP's are given, the bridge will be able to control the devices or scenes by the call it receives and send it to the target Vera and devce/scene you configure.
112+
Provide IP Addresses of your Veras that you want to utilize with the bridge. Also, give a meaningful name to each one so it is easy to decipher in the helper tab. When these names and IP's are given, the bridge will be able to control the devices or scenes by the call it receives and send it to the target Vera and device/scene you configure.
113113
#### Harmony Names and IP Addresses
114114
Provide IP Addresses of your Harmony Hubs that you want to utilize with the bridge. Also, give a meaningful name to each one so it is easy to decipher in the helper tab. When these names and IP's are given, the bridge will be able to control the activity or buttons by the call it receives and send it to the target Harmony Hub and activity/button you configure.
115115
#### Harmony Username
@@ -120,6 +120,10 @@ The password for the user name of the MyHarmony.com account for the Harmony Hub.
120120
Provide IP Addresses of your Hue Bridges that you want to proxy through the bridge. Also, give a meaningful name to each one so it is easy to decipher in the helper tab. When these names and IP's are given, the bridge will passthru the call it receives to the target Hue and device you configure.
121121

122122
Don't forget - You will need to push the link button when you got to the Hue Tab the first time ater the process comes up. (The user name is not persistent when the process comes up.)
123+
#### HAL Names and IP Addresses
124+
Provide IP Addresses of your HAL Systems that you want to utilize with the bridge. Also, give a meaningful name to each one so it is easy to decipher in the helper tab. When these names and IP's are given, the bridge will be able to control the devices or scenes by the call it receives and send it to the target HAL and device/scene you configure.
125+
#### HAL Token
126+
The token you generate or give to a HAL and must be the same for all HAL's you have identified. This needs to be given if you are using the HAL features.
123127
#### Nest Username
124128
The user name of the home.nest.com account for the Nest user. This needs to be given if you are using the Nest features. There is no need to give any ip address or host information as this contacts your cloud account.
125129
#### Nest Password

pom.xml

+2-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.bwssystems.HABridge</groupId>
77
<artifactId>ha-bridge</artifactId>
8-
<version>2.0.7</version>
8+
<version>3.0.0</version>
99
<packaging>jar</packaging>
1010

1111
<name>HA Bridge</name>
@@ -89,18 +89,8 @@
8989
<dependency>
9090
<groupId>com.google.code.gson</groupId>
9191
<artifactId>gson</artifactId>
92-
<version>2.2.4</version>
92+
<version>2.6.2</version>
9393
</dependency>
94-
<dependency>
95-
<groupId>com.fasterxml.jackson.core</groupId>
96-
<artifactId>jackson-databind</artifactId>
97-
<version>2.6.0</version>
98-
</dependency>
99-
<dependency>
100-
<groupId>com.cedarsoftware</groupId>
101-
<artifactId>json-io</artifactId>
102-
<version>4.1.6</version>
103-
</dependency>
10494
<dependency>
10595
<groupId>net.java.dev.eval</groupId>
10696
<artifactId>eval</artifactId>

src/main/java/com/bwssystems/HABridge/BridgeSettings.java

+18-28
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.gson.Gson;
2121

2222
public class BridgeSettings extends BackupHandler {
23+
private static final Logger log = LoggerFactory.getLogger(BridgeSettings.class);
2324
private BridgeSettingsDescriptor theBridgeSettings;
2425
private BridgeControlDescriptor bridgeControl;
2526

@@ -35,7 +36,6 @@ public BridgeSettingsDescriptor getBridgeSettingsDescriptor() {
3536
return theBridgeSettings;
3637
}
3738
public void buildSettings() {
38-
Logger log = LoggerFactory.getLogger(BridgeSettings.class);
3939
InetAddress address = null;
4040
String addressString = null;
4141
String theVeraAddress = null;
@@ -146,15 +146,22 @@ public void buildSettings() {
146146
theBridgeSettings.setUpnpDeviceDb(Configuration.DEVICE_DB_DIRECTORY);
147147

148148
if(theBridgeSettings.getNumberoflogmessages() == null)
149-
theBridgeSettings.setNumberoflogmessages(Configuration.NUMBER_OF_LOG_MESSAGES);
149+
theBridgeSettings.setNumberoflogmessages(new Integer(Configuration.NUMBER_OF_LOG_MESSAGES));
150+
151+
if(theBridgeSettings.getNumberoflogmessages() <= 0)
152+
theBridgeSettings.setNumberoflogmessages(new Integer(Configuration.NUMBER_OF_LOG_MESSAGES));
153+
154+
if(theBridgeSettings.getButtonsleep() == null)
155+
theBridgeSettings.setButtonsleep(Integer.parseInt(Configuration.DEFAULT_BUTTON_SLEEP));
150156

151-
if(theBridgeSettings.getButtonsleep() <= 0)
157+
if(theBridgeSettings.getButtonsleep() < 0)
152158
theBridgeSettings.setButtonsleep(Integer.parseInt(Configuration.DEFAULT_BUTTON_SLEEP));
153159

154160
theBridgeSettings.setVeraconfigured(theBridgeSettings.isValidVera());
155161
theBridgeSettings.setHarmonyconfigured(theBridgeSettings.isValidHarmony());
156162
theBridgeSettings.setNestConfigured(theBridgeSettings.isValidNest());
157163
theBridgeSettings.setHueconfigured(theBridgeSettings.isValidHue());
164+
theBridgeSettings.setHalconfigured(theBridgeSettings.isValidHal());
158165
if(serverPortOverride != null)
159166
theBridgeSettings.setServerPort(serverPortOverride);
160167
setupParams(Paths.get(theBridgeSettings.getConfigfile()), ".cfgbk", "habridge.config-");
@@ -171,31 +178,17 @@ private void _loadConfig() {
171178

172179
private void _loadConfig(Path aPath) {
173180
String jsonContent = configReader(aPath);
174-
BridgeSettingsDescriptor aBridgeSettings = new Gson().fromJson(jsonContent, BridgeSettingsDescriptor.class);
175-
theBridgeSettings.setButtonsleep(aBridgeSettings.getButtonsleep());
176-
theBridgeSettings.setUpnpConfigAddress(aBridgeSettings.getUpnpConfigAddress());
177-
theBridgeSettings.setServerPort(aBridgeSettings.getServerPort());
178-
theBridgeSettings.setUpnpResponsePort(aBridgeSettings.getUpnpResponsePort());
179-
theBridgeSettings.setUpnpDeviceDb(aBridgeSettings.getUpnpDeviceDb());
180-
theBridgeSettings.setVeraAddress(aBridgeSettings.getVeraAddress());
181-
theBridgeSettings.setHarmonyAddress(aBridgeSettings.getHarmonyAddress());
182-
theBridgeSettings.setHarmonyUser(aBridgeSettings.getHarmonyUser());
183-
theBridgeSettings.setHarmonyPwd(aBridgeSettings.getHarmonyPwd());
184-
theBridgeSettings.setUpnpStrict(aBridgeSettings.isUpnpStrict());
185-
theBridgeSettings.setTraceupnp(aBridgeSettings.isTraceupnp());
186-
theBridgeSettings.setNestuser(aBridgeSettings.getNestuser());
187-
theBridgeSettings.setNestpwd(aBridgeSettings.getNestpwd());
188-
theBridgeSettings.setVeraconfigured(aBridgeSettings.isValidVera());
189-
theBridgeSettings.setHarmonyconfigured(aBridgeSettings.isValidHarmony());
190-
theBridgeSettings.setNestConfigured(aBridgeSettings.isValidNest());
191-
theBridgeSettings.setNumberoflogmessages(aBridgeSettings.getNumberoflogmessages());
192-
theBridgeSettings.setFarenheit(aBridgeSettings.isFarenheit());
193-
theBridgeSettings.setHueaddress(aBridgeSettings.getHueaddress());
194-
theBridgeSettings.setHueconfigured(aBridgeSettings.isValidHue());
181+
try {
182+
theBridgeSettings = new Gson().fromJson(jsonContent, BridgeSettingsDescriptor.class);
183+
} catch (Exception e) {
184+
log.warn("Issue loading values from file: " + aPath.toUri().toString() + ", Gson convert failed.");
185+
theBridgeSettings = new BridgeSettingsDescriptor();
186+
theBridgeSettings.setConfigfile(aPath.toString());
187+
}
188+
195189
}
196190

197191
public void save(BridgeSettingsDescriptor newBridgeSettings) {
198-
Logger log = LoggerFactory.getLogger(BridgeSettings.class);
199192
log.debug("Save HA Bridge settings.");
200193
Path configPath = Paths.get(theBridgeSettings.getConfigfile());
201194
JsonTransformer aRenderer = new JsonTransformer();
@@ -206,7 +199,6 @@ public void save(BridgeSettingsDescriptor newBridgeSettings) {
206199

207200

208201
private void configWriter(String content, Path filePath) {
209-
Logger log = LoggerFactory.getLogger(BridgeSettings.class);
210202
if(Files.exists(filePath) && !Files.isWritable(filePath)){
211203
log.error("Error file is not writable: " + filePath);
212204
return;
@@ -235,8 +227,6 @@ private void configWriter(String content, Path filePath) {
235227
}
236228

237229
private String configReader(Path filePath) {
238-
Logger log = LoggerFactory.getLogger(BridgeSettings.class);
239-
240230
String content = null;
241231
if(Files.notExists(filePath) || !Files.isReadable(filePath)){
242232
log.warn("Error reading the file: " + filePath + " - Does not exist or is not readable. continuing...");

src/main/java/com/bwssystems/HABridge/BridgeSettingsDescriptor.java

+51
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.bwssystems.HABridge;
22

33
import java.util.List;
4+
import java.util.Map;
5+
6+
import com.bwssystems.HABridge.api.hue.WhitelistEntry;
47

58
public class BridgeSettingsDescriptor {
69
private String upnpconfigaddress;
@@ -24,6 +27,11 @@ public class BridgeSettingsDescriptor {
2427
private Integer numberoflogmessages;
2528
private IpList hueaddress;
2629
private boolean hueconfigured;
30+
private IpList haladdress;
31+
private String haltoken;
32+
private boolean halconfigured;
33+
private Map<String, WhitelistEntry> whitelist;
34+
private boolean settingsChanged;
2735

2836
public BridgeSettingsDescriptor() {
2937
super();
@@ -33,7 +41,10 @@ public BridgeSettingsDescriptor() {
3341
this.veraconfigured = false;
3442
this.harmonyconfigured = false;
3543
this.hueconfigured = false;
44+
this.halconfigured = false;
3645
this.farenheit = true;
46+
this.whitelist = null;
47+
this.settingsChanged = false;
3748
}
3849
public String getUpnpConfigAddress() {
3950
return upnpconfigaddress;
@@ -167,6 +178,36 @@ public boolean isHueconfigured() {
167178
public void setHueconfigured(boolean hueconfigured) {
168179
this.hueconfigured = hueconfigured;
169180
}
181+
public IpList getHaladdress() {
182+
return haladdress;
183+
}
184+
public void setHaladdress(IpList haladdress) {
185+
this.haladdress = haladdress;
186+
}
187+
public String getHaltoken() {
188+
return haltoken;
189+
}
190+
public void setHaltoken(String haltoken) {
191+
this.haltoken = haltoken;
192+
}
193+
public boolean isHalconfigured() {
194+
return halconfigured;
195+
}
196+
public void setHalconfigured(boolean halconfigured) {
197+
this.halconfigured = halconfigured;
198+
}
199+
public Map<String, WhitelistEntry> getWhitelist() {
200+
return whitelist;
201+
}
202+
public void setWhitelist(Map<String, WhitelistEntry> whitelist) {
203+
this.whitelist = whitelist;
204+
}
205+
public boolean isSettingsChanged() {
206+
return settingsChanged;
207+
}
208+
public void setSettingsChanged(boolean settingsChanged) {
209+
this.settingsChanged = settingsChanged;
210+
}
170211
public Boolean isValidVera() {
171212
if(this.getVeraAddress() == null || this.getVeraAddress().getDevices().size() <= 0)
172213
return false;
@@ -202,4 +243,14 @@ public Boolean isValidHue() {
202243
return false;
203244
return true;
204245
}
246+
public Boolean isValidHal() {
247+
if(this.getHaladdress() == null || this.getHaladdress().getDevices().size() <= 0)
248+
return false;
249+
List<NamedIP> devicesList = this.getHaladdress().getDevices();
250+
if(devicesList.get(0).getIp().contains(Configuration.DEFAULT_ADDRESS))
251+
return false;
252+
if(this.getHaltoken() == null || this.getHaltoken().equals(""))
253+
return false;
254+
return true;
255+
}
205256
}

src/main/java/com/bwssystems/HABridge/HABridge.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.bwssystems.HABridge.upnp.UpnpListener;
1111
import com.bwssystems.HABridge.upnp.UpnpSettingsResource;
1212
import com.bwssystems.NestBridge.NestHome;
13+
import com.bwssystems.hal.HalHome;
1314
import com.bwssystems.harmony.HarmonyHome;
1415
import com.bwssystems.hue.HueHome;
1516

@@ -36,6 +37,7 @@ public static void main(String[] args) {
3637
HarmonyHome harmonyHome;
3738
NestHome nestHome;
3839
HueHome hueHome;
40+
HalHome halHome;
3941
HueMulator theHueMulator;
4042
UpnpSettingsResource theSettingResponder;
4143
UpnpListener theUpnpListener;
@@ -66,8 +68,10 @@ public static void main(String[] args) {
6668
nestHome = new NestHome(bridgeSettings.getBridgeSettingsDescriptor());
6769
//setup the hue passtrhu configuration if available
6870
hueHome = new HueHome(bridgeSettings.getBridgeSettingsDescriptor());
71+
//setup the hal configuration if available
72+
halHome = new HalHome(bridgeSettings.getBridgeSettingsDescriptor());
6973
// setup the class to handle the resource setup rest api
70-
theResources = new DeviceResource(bridgeSettings.getBridgeSettingsDescriptor(), harmonyHome, nestHome, hueHome);
74+
theResources = new DeviceResource(bridgeSettings.getBridgeSettingsDescriptor(), harmonyHome, nestHome, hueHome, halHome);
7175
// setup the class to handle the hue emulator rest api
7276
theHueMulator = new HueMulator(bridgeSettings.getBridgeSettingsDescriptor(), theResources.getDeviceRepository(), harmonyHome, nestHome, hueHome);
7377
theHueMulator.setupServer();
@@ -83,7 +87,8 @@ public static void main(String[] args) {
8387
log.info("HA Bridge (v" + theVersion.getVersion() + ") reinitialization requessted....");
8488
else
8589
bridgeSettings.getBridgeControl().setStop(true);
86-
90+
if(bridgeSettings.getBridgeSettingsDescriptor().isSettingsChanged())
91+
bridgeSettings.save(bridgeSettings.getBridgeSettingsDescriptor());
8792
bridgeSettings.getBridgeControl().setReinit(false);
8893
stop();
8994
nestHome.closeTheNest();

src/main/java/com/bwssystems/HABridge/api/hue/DeviceResponse.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class DeviceResponse {
1111
private String name;
1212
private String modelid;
1313
private String manufacturername;
14+
private String luminaireuniqueid;
1415
private String uniqueid;
1516
private String swversion;
1617

@@ -70,7 +71,15 @@ public void setSwversion(String swversion) {
7071
this.swversion = swversion;
7172
}
7273

73-
public static DeviceResponse createResponse(DeviceDescriptor device){
74+
public String getLuminaireuniqueid() {
75+
return luminaireuniqueid;
76+
}
77+
78+
public void setLuminaireuniqueid(String luminaireuniqueid) {
79+
this.luminaireuniqueid = luminaireuniqueid;
80+
}
81+
82+
public static DeviceResponse createResponse(DeviceDescriptor device){
7483
DeviceResponse response = new DeviceResponse();
7584
response.setState(device.getDeviceState());
7685

@@ -80,6 +89,7 @@ public static DeviceResponse createResponse(DeviceDescriptor device){
8089
response.setType("Dimmable light");
8190
response.setModelid("LWB004");
8291
response.setSwversion("66012040");
92+
response.setLuminaireuniqueid(null);
8393

8494
return response;
8595
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.bwssystems.HABridge.api.hue;
2+
3+
public class DeviceTypes {
4+
private Boolean bridge;
5+
private String[] lights;
6+
public Boolean getBridge() {
7+
return bridge;
8+
}
9+
public void setBridge(Boolean bridge) {
10+
this.bridge = bridge;
11+
}
12+
public String[] getLights() {
13+
return lights;
14+
}
15+
public void setLights(String[] lights) {
16+
this.lights = lights;
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.bwssystems.HABridge.api.hue;
2+
3+
public class GroupResponse {
4+
private DeviceState action;
5+
private String[] lights;
6+
private String name;
7+
public DeviceState getAction() {
8+
return action;
9+
}
10+
public void setAction(DeviceState action) {
11+
this.action = action;
12+
}
13+
public String[] getLights() {
14+
return lights;
15+
}
16+
public void setLights(String[] lights) {
17+
this.lights = lights;
18+
}
19+
public String getName() {
20+
return name;
21+
}
22+
public void setName(String name) {
23+
this.name = name;
24+
}
25+
26+
public static GroupResponse createGroupResponse(String[] theLights) {
27+
GroupResponse theResponse = new GroupResponse();
28+
theResponse.setAction(DeviceState.createDeviceState());
29+
theResponse.setName("Lightset 0");
30+
theResponse.setLights(theLights);
31+
return theResponse;
32+
}
33+
}

0 commit comments

Comments
 (0)