Search in sources :

Example 1 with X10Interface

use of org.openhab.binding.cm11a.internal.X10Interface in project openhab-addons by openhab.

the class Cm11aBridgeHandler method initialize.

@Override
public void initialize() {
    // Get serial port number from config
    cm11aConfig = getThing().getConfiguration().as(Cm11aConfig.class);
    logger.trace("********* cm11a initialize started *********");
    // Verify the configuration is valid
    if (!validateConfig(this.cm11aConfig)) {
        return;
    }
    // Initialize the X10 interface
    try {
        x10Interface = new X10Interface(cm11aConfig.serialPort, this);
        x10Interface.setDaemon(true);
        x10Interface.start();
        x10Interface.addReceivedDataListener(this);
        logger.info("Initialized CM11A X10 interface on: {}", cm11aConfig.serialPort);
    } catch (NoSuchPortException e) {
        x10Interface = null;
        logger.error("No such port exists on this machine: {}", cm11aConfig.serialPort);
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "No such port exists on this machine: " + cm11aConfig.serialPort);
        return;
    }
    updateStatus(ThingStatus.ONLINE);
}
Also used : X10Interface(org.openhab.binding.cm11a.internal.X10Interface) NoSuchPortException(gnu.io.NoSuchPortException) Cm11aConfig(org.openhab.binding.cm11a.internal.config.Cm11aConfig)

Example 2 with X10Interface

use of org.openhab.binding.cm11a.internal.X10Interface in project openhab-addons by openhab.

the class Cm11aLampHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    logger.debug("**** Cm11aLampHandler handleCommand command = {}, channelUID = {}", command.toString(), channelUID.getAsString());
    x10Function = 0;
    Bridge bridge = getBridge();
    if (bridge == null) {
        logger.debug("Unable to handle command. Bridge is null.");
        return;
    }
    this.channelUID = channelUID;
    Cm11aBridgeHandler cm11aHandler = (Cm11aBridgeHandler) bridge.getHandler();
    if (cm11aHandler != null && cm11aHandler.getThing().getStatus().equals(ThingStatus.ONLINE)) {
        if (OnOffType.ON.equals(command)) {
            desiredState = OnOffType.ON;
        } else if (OnOffType.OFF.equals(command)) {
            desiredState = OnOffType.OFF;
        } else if (command instanceof PercentType) {
            desiredState = (PercentType) command;
        } else if (command instanceof RefreshType) {
            // Refresh is triggered by framework during startup.
            // Force the lamp off by indicating it is currently on and we want it off
            // Start with it off
            desiredState = PercentType.ZERO;
            logger.info("Received REFRESH command for switch {}", houseUnitCode);
        } else {
            logger.error("Ignoring unknown command received for device: {}", houseUnitCode);
        }
        if (!(desiredState instanceof UnDefType)) {
            X10Interface x10Interface = cm11aHandler.getX10Interface();
            x10Interface.scheduleHWUpdate(this);
        }
    } else {
        logger.error("Attempted to change switch {} cm11a is not online", houseUnitCode);
    }
}
Also used : X10Interface(org.openhab.binding.cm11a.internal.X10Interface) UnDefType(org.openhab.core.types.UnDefType) PercentType(org.openhab.core.library.types.PercentType) RefreshType(org.openhab.core.types.RefreshType) Bridge(org.openhab.core.thing.Bridge)

Example 3 with X10Interface

use of org.openhab.binding.cm11a.internal.X10Interface in project openhab-addons by openhab.

the class Cm11aApplianceHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    logger.debug("**** Cm11aApplianceHandler handleCommand command = {}, channelUID = {}", command, channelUID.getAsString());
    x10Function = 0;
    Bridge bridge = getBridge();
    if (bridge == null) {
        logger.debug("Unable to handle command. Bridge is null.");
        return;
    }
    this.channelUID = channelUID;
    Cm11aBridgeHandler cm11aHandler = (Cm11aBridgeHandler) bridge.getHandler();
    if (cm11aHandler != null && cm11aHandler.getThing().getStatus().equals(ThingStatus.ONLINE)) {
        if (command == OnOffType.ON) {
            x10Function = X10Interface.FUNC_ON;
            desiredState = OnOffType.ON;
        } else if (command == OnOffType.OFF) {
            x10Function = X10Interface.FUNC_OFF;
            desiredState = OnOffType.OFF;
        } else if (command instanceof RefreshType) {
            x10Function = X10Interface.FUNC_OFF;
            desiredState = OnOffType.OFF;
            logger.info("Received REFRESH command for switch {}", houseUnitCode);
        }
        if (x10Function > 0) {
            X10Interface x10Interface = cm11aHandler.getX10Interface();
            x10Interface.scheduleHWUpdate(this);
        } else {
            logger.debug("Received invalid command for switch {} command: {}", houseUnitCode, command);
        }
    } else {
        logger.debug("Attempted to change switch to {} for {} because the cm11a is not online", command, houseUnitCode);
    }
}
Also used : X10Interface(org.openhab.binding.cm11a.internal.X10Interface) RefreshType(org.openhab.core.types.RefreshType) Bridge(org.openhab.core.thing.Bridge)

Aggregations

X10Interface (org.openhab.binding.cm11a.internal.X10Interface)3 Bridge (org.openhab.core.thing.Bridge)2 RefreshType (org.openhab.core.types.RefreshType)2 NoSuchPortException (gnu.io.NoSuchPortException)1 Cm11aConfig (org.openhab.binding.cm11a.internal.config.Cm11aConfig)1 PercentType (org.openhab.core.library.types.PercentType)1 UnDefType (org.openhab.core.types.UnDefType)1