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;
}
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);
}
}
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);
}
}
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);
}
}
}
}
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");
}
}
}
}
Aggregations