Search in sources :

Example 1 with AccountsDTO

use of org.openhab.binding.myq.internal.dto.AccountsDTO in project openhab-addons by openhab.

the class MyQAccountHandler method getDevices.

private void getDevices() throws InterruptedException, MyQCommunicationException, MyQAuthenticationException {
    AccountsDTO localAccounts = accounts;
    if (localAccounts == null) {
        return;
    }
    List<DeviceDTO> currentDevices = new ArrayList<DeviceDTO>();
    for (AccountDTO account : localAccounts.accounts) {
        ContentResponse response = sendRequest(String.format(DEVICES_URL, account.id), HttpMethod.GET, null, null);
        DevicesDTO devices = parseResultAndUpdateStatus(response, gsonLowerCase, DevicesDTO.class);
        currentDevices.addAll(devices.items);
        devices.items.forEach(device -> {
            ThingTypeUID thingTypeUID = new ThingTypeUID(BINDING_ID, device.deviceFamily);
            if (SUPPORTED_DISCOVERY_THING_TYPES_UIDS.contains(thingTypeUID)) {
                for (Thing thing : getThing().getThings()) {
                    ThingHandler handler = thing.getHandler();
                    if (handler != null && ((MyQDeviceHandler) handler).getSerialNumber().equalsIgnoreCase(device.serialNumber)) {
                        ((MyQDeviceHandler) handler).handleDeviceUpdate(device);
                    }
                }
            }
        });
    }
    devicesCache = currentDevices;
}
Also used : HttpContentResponse(org.eclipse.jetty.client.HttpContentResponse) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) ArrayList(java.util.ArrayList) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) ThingHandler(org.openhab.core.thing.binding.ThingHandler) DeviceDTO(org.openhab.binding.myq.internal.dto.DeviceDTO) AccountDTO(org.openhab.binding.myq.internal.dto.AccountDTO) DevicesDTO(org.openhab.binding.myq.internal.dto.DevicesDTO) AccountsDTO(org.openhab.binding.myq.internal.dto.AccountsDTO) Thing(org.openhab.core.thing.Thing)

Aggregations

ArrayList (java.util.ArrayList)1 HttpContentResponse (org.eclipse.jetty.client.HttpContentResponse)1 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)1 AccountDTO (org.openhab.binding.myq.internal.dto.AccountDTO)1 AccountsDTO (org.openhab.binding.myq.internal.dto.AccountsDTO)1 DeviceDTO (org.openhab.binding.myq.internal.dto.DeviceDTO)1 DevicesDTO (org.openhab.binding.myq.internal.dto.DevicesDTO)1 Thing (org.openhab.core.thing.Thing)1 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)1 ThingHandler (org.openhab.core.thing.binding.ThingHandler)1