Search in sources :

Example 1 with DeviceDTO

use of org.openhab.binding.myq.internal.dto.DeviceDTO 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)

Example 2 with DeviceDTO

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

the class MyQGarageDoorHandler method updateState.

protected void updateState() {
    final DeviceDTO localDevice = device;
    if (localDevice != null) {
        String doorState = localDevice.state.doorState;
        updateState("status", new StringType(doorState));
        switch(doorState) {
            case "open":
            case "opening":
            case "closing":
            case "stopped":
            case "transition":
                updateState("switch", OnOffType.ON);
                updateState("rollershutter", UpDownType.UP);
                break;
            case "closed":
                updateState("switch", OnOffType.OFF);
                updateState("rollershutter", UpDownType.DOWN);
                break;
            default:
                updateState("switch", UnDefType.UNDEF);
                updateState("rollershutter", UnDefType.UNDEF);
                break;
        }
        updateState("closeerror", localDevice.state.isUnattendedCloseAllowed ? OnOffType.OFF : OnOffType.ON);
        updateState("openerror", localDevice.state.isUnattendedOpenAllowed ? OnOffType.OFF : OnOffType.ON);
    }
}
Also used : StringType(org.openhab.core.library.types.StringType) DeviceDTO(org.openhab.binding.myq.internal.dto.DeviceDTO)

Example 3 with DeviceDTO

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

the class MyQLampHandler method updateState.

protected void updateState() {
    final DeviceDTO localDevice = device;
    if (localDevice != null) {
        String lampState = localDevice.state.lampState;
        updateState("switch", "on".equals(lampState) ? OnOffType.ON : OnOffType.OFF);
    }
}
Also used : DeviceDTO(org.openhab.binding.myq.internal.dto.DeviceDTO)

Example 4 with DeviceDTO

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

the class MyQGarageDoorHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    if (command instanceof RefreshType) {
        updateState();
        return;
    }
    Bridge bridge = getBridge();
    final DeviceDTO localDevice = device;
    if (bridge != null && localDevice != null) {
        BridgeHandler handler = bridge.getHandler();
        if (handler != null) {
            String cmd = null;
            if (command instanceof OnOffType) {
                cmd = command == OnOffType.ON ? "open" : "close";
            }
            if (command instanceof UpDownType) {
                cmd = command == UpDownType.UP ? "open" : "close";
            }
            if (command instanceof PercentType) {
                cmd = ((PercentType) command).as(UpDownType.class) == UpDownType.UP ? "open" : "close";
            }
            if (command instanceof StringType) {
                cmd = command.toString();
            }
            if (cmd != null) {
                ((MyQAccountHandler) handler).sendDoorAction(localDevice, cmd);
            }
        }
    }
}
Also used : BridgeHandler(org.openhab.core.thing.binding.BridgeHandler) OnOffType(org.openhab.core.library.types.OnOffType) StringType(org.openhab.core.library.types.StringType) UpDownType(org.openhab.core.library.types.UpDownType) DeviceDTO(org.openhab.binding.myq.internal.dto.DeviceDTO) PercentType(org.openhab.core.library.types.PercentType) RefreshType(org.openhab.core.types.RefreshType) Bridge(org.openhab.core.thing.Bridge)

Example 5 with DeviceDTO

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

the class MyQLampHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    if (command instanceof RefreshType) {
        updateState();
        return;
    }
    if (command instanceof OnOffType) {
        Bridge bridge = getBridge();
        final DeviceDTO localDevice = device;
        if (bridge != null && localDevice != null) {
            BridgeHandler handler = bridge.getHandler();
            if (handler != null) {
                ((MyQAccountHandler) handler).sendLampAction(localDevice, command == OnOffType.ON ? "on" : "off");
            }
        }
    }
}
Also used : OnOffType(org.openhab.core.library.types.OnOffType) BridgeHandler(org.openhab.core.thing.binding.BridgeHandler) DeviceDTO(org.openhab.binding.myq.internal.dto.DeviceDTO) RefreshType(org.openhab.core.types.RefreshType) Bridge(org.openhab.core.thing.Bridge)

Aggregations

DeviceDTO (org.openhab.binding.myq.internal.dto.DeviceDTO)6 OnOffType (org.openhab.core.library.types.OnOffType)2 StringType (org.openhab.core.library.types.StringType)2 Bridge (org.openhab.core.thing.Bridge)2 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)2 BridgeHandler (org.openhab.core.thing.binding.BridgeHandler)2 RefreshType (org.openhab.core.types.RefreshType)2 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 DevicesDTO (org.openhab.binding.myq.internal.dto.DevicesDTO)1 MyQAccountHandler (org.openhab.binding.myq.internal.handler.MyQAccountHandler)1 DiscoveryResult (org.openhab.core.config.discovery.DiscoveryResult)1 PercentType (org.openhab.core.library.types.PercentType)1 UpDownType (org.openhab.core.library.types.UpDownType)1 Thing (org.openhab.core.thing.Thing)1 ThingUID (org.openhab.core.thing.ThingUID)1 ThingHandler (org.openhab.core.thing.binding.ThingHandler)1