Search in sources :

Example 1 with AbstractDevice

use of org.openhab.io.imperihome.internal.model.device.AbstractDevice in project openhab-addons by openhab.

the class SetModeAction method perform.

@Override
public void perform(AbstractDevice device, Item item, String value) {
    String modeDeviceName = device.getLinks().get("curmode");
    AbstractDevice modeDevice = deviceRegistry.getDevice(ItemProcessor.getDeviceId(modeDeviceName));
    if (modeDevice == null) {
        logger.error("Couldn't resolve linked CurMode device '{}', make sure the Item has iss tags", modeDeviceName);
        return;
    }
    Item modeItem = modeDevice.getItem();
    ItemCommandEvent event = ItemEventFactory.createCommandEvent(modeItem.getName(), new StringType(value), COMMAND_SOURCE);
    eventPublisher.post(event);
}
Also used : Item(org.openhab.core.items.Item) ItemCommandEvent(org.openhab.core.items.events.ItemCommandEvent) StringType(org.openhab.core.library.types.StringType) AbstractDevice(org.openhab.io.imperihome.internal.model.device.AbstractDevice)

Example 2 with AbstractDevice

use of org.openhab.io.imperihome.internal.model.device.AbstractDevice in project openhab-addons by openhab.

the class DeviceActionHandler method handle.

public void handle(HttpServletRequest req, Matcher urlMatcher) {
    String deviceId, action, value;
    deviceId = URLDecoder.decode(urlMatcher.group(1), StandardCharsets.UTF_8);
    action = URLDecoder.decode(urlMatcher.group(2), StandardCharsets.UTF_8);
    if (urlMatcher.group(3) == null) {
        value = null;
    } else {
        value = URLDecoder.decode(urlMatcher.group(3), StandardCharsets.UTF_8);
    }
    logger.debug("Action request for device {}: [{}] [{}]", deviceId, action, value);
    AbstractDevice device = deviceRegistry.getDevice(deviceId);
    if (device == null) {
        logger.warn("Received action request for unknown device: {}", urlMatcher.group(0));
    } else {
        device.performAction(action, value);
    }
}
Also used : AbstractDevice(org.openhab.io.imperihome.internal.model.device.AbstractDevice)

Example 3 with AbstractDevice

use of org.openhab.io.imperihome.internal.model.device.AbstractDevice in project openhab-addons by openhab.

the class DeviceHistoryHandler method handle.

public HistoryList handle(HttpServletRequest req, Matcher urlMatcher) {
    String deviceId, field;
    long start, end;
    try {
        deviceId = URLDecoder.decode(urlMatcher.group(1), StandardCharsets.UTF_8);
        field = URLDecoder.decode(urlMatcher.group(2), StandardCharsets.UTF_8);
        start = Long.parseLong(urlMatcher.group(3));
        end = Long.parseLong(urlMatcher.group(4));
    } catch (NumberFormatException e) {
        throw new RuntimeException("Could not decode request params", e);
    }
    logger.debug("History request for device {}, field {}: {}-{}", deviceId, field, start, end);
    AbstractDevice device = deviceRegistry.getDevice(deviceId);
    if (device == null) {
        logger.warn("Received history request for unknown device: {}", urlMatcher.group(0));
        return null;
    }
    PersistenceService persistence = persistenceServiceRegistry.getDefault();
    if (persistence == null) {
        logger.warn("Could not retrieve default persistence service; can't serve history request");
        return null;
    }
    if (!(persistence instanceof QueryablePersistenceService)) {
        logger.warn("Default persistence service is not queryable; can't serve history request");
        return null;
    }
    return serveHistory(device, (QueryablePersistenceService) persistence, start, end);
}
Also used : QueryablePersistenceService(org.openhab.core.persistence.QueryablePersistenceService) PersistenceService(org.openhab.core.persistence.PersistenceService) QueryablePersistenceService(org.openhab.core.persistence.QueryablePersistenceService) AbstractDevice(org.openhab.io.imperihome.internal.model.device.AbstractDevice)

Example 4 with AbstractDevice

use of org.openhab.io.imperihome.internal.model.device.AbstractDevice in project openhab-addons by openhab.

the class DevicesListHandler method handle.

public DeviceList handle(HttpServletRequest req) {
    DeviceList response = new DeviceList();
    Collection<AbstractDevice> devices = deviceRegistry.getDevices().values();
    for (AbstractDevice device : devices) {
        device.updateParams();
    }
    response.setDevices(devices);
    logger.debug("Device list response: {}", response);
    return response;
}
Also used : AbstractDevice(org.openhab.io.imperihome.internal.model.device.AbstractDevice) DeviceList(org.openhab.io.imperihome.internal.model.device.DeviceList)

Example 5 with AbstractDevice

use of org.openhab.io.imperihome.internal.model.device.AbstractDevice in project openhab-addons by openhab.

the class DeviceRegistry method clear.

public void clear() {
    for (AbstractDevice device : devices.values()) {
        device.destroy();
    }
    devices.clear();
    if (rooms != null) {
        rooms.clear();
    }
    logger.debug("Device registry cleared");
}
Also used : AbstractDevice(org.openhab.io.imperihome.internal.model.device.AbstractDevice)

Aggregations

AbstractDevice (org.openhab.io.imperihome.internal.model.device.AbstractDevice)10 Item (org.openhab.core.items.Item)2 ItemCommandEvent (org.openhab.core.items.events.ItemCommandEvent)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 StringType (org.openhab.core.library.types.StringType)1 PersistenceService (org.openhab.core.persistence.PersistenceService)1 QueryablePersistenceService (org.openhab.core.persistence.QueryablePersistenceService)1 Room (org.openhab.io.imperihome.internal.model.Room)1 DeviceList (org.openhab.io.imperihome.internal.model.device.DeviceList)1 DeviceType (org.openhab.io.imperihome.internal.model.device.DeviceType)1