mirror of
https://github.com/Voronsky/unifi4j.git
synced 2025-12-13 16:36:35 -05:00
New method to retrieve list of devices
This commit is contained in:
@@ -57,7 +57,6 @@ public class Unifi {
|
|||||||
UnifiResponse ur = mapper.readValue(jsonObject.toString(), UnifiResponse.class);
|
UnifiResponse ur = mapper.readValue(jsonObject.toString(), UnifiResponse.class);
|
||||||
List<Data> data = ur.data();
|
List<Data> data = ur.data();
|
||||||
log.info("List: "+ur);
|
log.info("List: "+ur);
|
||||||
log.info("REEE: "+data);
|
|
||||||
for(Data itr: data){
|
for(Data itr: data){
|
||||||
log.info("RS: "+itr.reportedState().hardware());
|
log.info("RS: "+itr.reportedState().hardware());
|
||||||
hardwares.add(itr.reportedState().hardware().name());
|
hardwares.add(itr.reportedState().hardware().name());
|
||||||
@@ -66,4 +65,23 @@ public class Unifi {
|
|||||||
return hardwares;
|
return hardwares;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Devices> getDevices() throws Exception{
|
||||||
|
List<Devices> devices = new ArrayList<>();
|
||||||
|
ResponseEntity<String> json = this.restClient.get().uri("/devices").retrieve().toEntity(String.class);
|
||||||
|
log.debug("JSON response: "+ json);
|
||||||
|
|
||||||
|
//Convert to Json Node Object to do POJO
|
||||||
|
JsonNode jsonObject = new ObjectMapper().readTree(json.getBody());
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
UnifiResponse ur = mapper.readValue(jsonObject.toString(), UnifiResponse.class);
|
||||||
|
List<Data> data = ur.data();
|
||||||
|
log.info("List: "+ur);
|
||||||
|
// Polynomial O(N^2) , it was a list within a list in the JSON response
|
||||||
|
for (Data dataItr: data){
|
||||||
|
devices.addAll(dataItr.devices());
|
||||||
|
}
|
||||||
|
log.debug("Devices: "+devices);
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user