Added support for multiple eco cube devices
This commit is contained in:
parent
c26c769108
commit
9d41856854
2 changed files with 17 additions and 12 deletions
|
|
@ -40,10 +40,11 @@ import zutil.parser.json.JSONWriter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
@ -92,7 +93,9 @@ public class EcoSenseCloudAPIClient {
|
||||||
cognitoClient.close();
|
cognitoClient.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EcoSenseDevice getDevices() {
|
public List<EcoSenseDevice> getDevices() {
|
||||||
|
List<EcoSenseDevice> devices = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (ObjectUtil.isEmpty(idToken)) {
|
if (ObjectUtil.isEmpty(idToken)) {
|
||||||
authenticate();
|
authenticate();
|
||||||
|
|
@ -153,7 +156,7 @@ public class EcoSenseCloudAPIClient {
|
||||||
logger.log(Level.WARNING, "Was unable to parse timestamp from EcoSense API.", e);
|
logger.log(Level.WARNING, "Was unable to parse timestamp from EcoSense API.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ecoSenseDevice;
|
devices.add(ecoSenseDevice);
|
||||||
}
|
}
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
@ -162,7 +165,7 @@ public class EcoSenseCloudAPIClient {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EcoSenseDevice {
|
public class EcoSenseDevice {
|
||||||
|
|
|
||||||
|
|
@ -77,19 +77,21 @@ public class EcoSenseController implements HalSensorController, Runnable, HalDae
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
if (!ObjectUtil.isEmpty(ecoSenseClient)) {
|
if (!ObjectUtil.isEmpty(ecoSenseClient)) {
|
||||||
EcoSenseCloudAPIClient.EcoSenseDevice apiResponse = ecoSenseClient.getDevices();
|
List<EcoSenseCloudAPIClient.EcoSenseDevice> apiResponse = ecoSenseClient.getDevices();
|
||||||
if (apiResponse == null) {
|
if (apiResponse.isEmpty()) {
|
||||||
logger.warning("Received empty response from EcoSense API.");
|
logger.info("Received no devices from EcoSense API.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
EccoCubeRadonSensorConfig radonSensor = new EccoCubeRadonSensorConfig();
|
for (EcoSenseCloudAPIClient.EcoSenseDevice device : apiResponse) {
|
||||||
radonSensor.setSerialNumber(apiResponse.serialNumber);
|
EccoCubeRadonSensorConfig radonSensor = new EccoCubeRadonSensorConfig();
|
||||||
|
radonSensor.setSerialNumber(device.serialNumber);
|
||||||
|
|
||||||
RadonSensorData radonSensorData = new RadonSensorData(apiResponse.radonLevel, apiResponse.lastRadonUpdateTime);
|
RadonSensorData radonSensorData = new RadonSensorData(device.radonLevel, device.lastRadonUpdateTime);
|
||||||
|
|
||||||
if (deviceReportListener != null) {
|
if (deviceReportListener != null) {
|
||||||
deviceReportListener.reportReceived(radonSensor, radonSensorData);
|
deviceReportListener.reportReceived(radonSensor, radonSensorData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue