Beispiel #1
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     PercentType pc = (PercentType) cmd;
     double ramptime = getRampTime(conf, 0);
     int level = pc.intValue();
     if (level > 0) { // make light on message with given level
       level = getMaxLightLevel(conf, level);
       byte cmd2 = encode(ramptime, level);
       Msg m = dev.makeStandardMessage((byte) 0x0f, getOnCmd(), (byte) cmd2);
       dev.enqueueMessage(m, m_feature);
       logger.info(
           "{}: sent msg to set {} to {} with {} second ramp time.",
           nm(),
           dev.getAddress(),
           level,
           ramptime);
     } else { // switch off
       Msg m = dev.makeStandardMessage((byte) 0x0f, getOffCmd(), (byte) 0x00);
       dev.enqueueMessage(m, m_feature);
       logger.info(
           "{}: sent msg to set {} to zero by switching off with {} ramp time.",
           nm(),
           dev.getAddress(),
           ramptime);
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Beispiel #2
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   String cmdParam = conf.getParameter("cmd");
   if (cmdParam == null) {
     logger.error("{} ignoring cmd {} because no cmd= is configured!", nm(), cmd);
     return;
   }
   try {
     if (cmd == OnOffType.ON) {
       if (cmdParam.equals("reset")) {
         Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x80, (byte) 0x00);
         dev.enqueueMessage(m, m_feature);
         logger.info("{}: sent reset msg to power meter {}", nm(), dev.getAddress());
         m_feature.publish(OnOffType.OFF, StateChangeType.ALWAYS, "cmd", "reset");
       } else if (cmdParam.equals("update")) {
         Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x82, (byte) 0x00);
         dev.enqueueMessage(m, m_feature);
         logger.info("{}: sent update msg to power meter {}", nm(), dev.getAddress());
         m_feature.publish(OnOffType.OFF, StateChangeType.ALWAYS, "cmd", "update");
       } else {
         logger.error(
             "{}: ignoring unknown cmd {} for power meter {}", nm(), cmdParam, dev.getAddress());
       }
     } else if (cmd == OnOffType.OFF) {
       logger.info("{}: ignoring off request for power meter {}", nm(), dev.getAddress());
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Beispiel #3
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     int button = this.getIntParameter("button", -1);
     if (cmd == OnOffType.ON) {
       Msg m =
           dev.makeExtendedMessage(
               (byte) 0x1f,
               (byte) 0x2e,
               (byte) 0x00,
               new byte[] {(byte) button, (byte) 0x09, (byte) 0x01});
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to switch {} on", nm(), dev.getAddress());
     } else if (cmd == OnOffType.OFF) {
       Msg m =
           dev.makeExtendedMessage(
               (byte) 0x1f,
               (byte) 0x2e,
               (byte) 0x00,
               new byte[] {(byte) button, (byte) 0x09, (byte) 0x00});
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to switch {} off", nm(), dev.getAddress());
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Beispiel #4
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     if (cmd == OnOffType.ON) {
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x11, (byte) 0xff);
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to switch {} on", nm(), dev.getAddress());
     } else if (cmd == OnOffType.OFF) {
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x13, (byte) 0x00);
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to switch {} off", nm(), dev.getAddress());
     }
     // This used to be configurable, but was made static to make
     // the architecture of the binding cleaner.
     int delay = 2000;
     delay = Math.max(1000, delay);
     delay = Math.min(10000, delay);
     Timer timer = new Timer();
     timer.schedule(
         new TimerTask() {
           @Override
           public void run() {
             Msg m = m_feature.makePollMsg();
             InsteonDevice dev = m_feature.getDevice();
             if (m != null) dev.enqueueMessage(m, m_feature);
           }
         },
         delay);
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error: ", nm(), e);
   }
 }
Beispiel #5
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     byte houseCode = dev.getX10HouseCode();
     byte houseUnitCode = (byte) (houseCode << 4 | dev.getX10UnitCode());
     if (cmd == IncreaseDecreaseType.INCREASE || cmd == IncreaseDecreaseType.DECREASE) {
       byte houseCommandCode =
           (byte)
               (houseCode << 4
                   | (cmd == IncreaseDecreaseType.INCREASE
                       ? X10.Command.BRIGHT.code()
                       : X10.Command.DIM.code()));
       Msg munit = dev.makeX10Message(houseUnitCode, (byte) 0x00); // send unit code
       dev.enqueueMessage(munit, m_feature);
       Msg mcmd = dev.makeX10Message(houseCommandCode, (byte) 0x80); // send command code
       dev.enqueueMessage(mcmd, m_feature);
       String bd = cmd == IncreaseDecreaseType.INCREASE ? "BRIGHTEN" : "DIM";
       logger.info("{}: sent msg to switch {} {}", nm(), dev.getAddress(), bd);
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Beispiel #6
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     //
     // I did not have hardware that would respond to the PRESET_DIM codes.
     // This code path needs testing.
     //
     byte houseCode = dev.getX10HouseCode();
     byte houseUnitCode = (byte) (houseCode << 4 | dev.getX10UnitCode());
     Msg munit = dev.makeX10Message(houseUnitCode, (byte) 0x00); // send unit code
     dev.enqueueMessage(munit, m_feature);
     PercentType pc = (PercentType) cmd;
     logger.debug("{}: changing level of {} to {}", nm(), dev.getAddress(), pc.intValue());
     int level = (pc.intValue() * 32) / 100;
     byte cmdCode =
         (level >= 16) ? X10.Command.PRESET_DIM_2.code() : X10.Command.PRESET_DIM_1.code();
     level = level % 16;
     if (level <= 0) level = 0;
     houseCode = (byte) s_X10CodeForLevel[level];
     cmdCode |= (houseCode << 4);
     Msg mcmd = dev.makeX10Message(cmdCode, (byte) 0x80); // send command code
     dev.enqueueMessage(mcmd, m_feature);
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Beispiel #7
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     if (cmd instanceof DecimalType) {
       int v = ((DecimalType) cmd).intValue();
       int cmd1 = (v != 1) ? 0x17 : 0x18; // start or stop
       int cmd2 = (v == 2) ? 0x01 : 0; // up or down
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) cmd1, (byte) cmd2, s_getGroup(conf));
       dev.enqueueMessage(m, m_feature);
       logger.info(
           "{}: cmd {} sent manual change {} {} to {}",
           nm(),
           v,
           (cmd1 == 0x17) ? "START" : "STOP",
           (cmd2 == 0x01) ? "UP" : "DOWN",
           dev.getAddress());
     } else {
       logger.error("{}: invalid command type: {}", nm(), cmd);
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Beispiel #8
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     if (cmd == IncreaseDecreaseType.INCREASE) {
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x15, (byte) 0x00);
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to brighten {}", nm(), dev.getAddress());
     } else if (cmd == IncreaseDecreaseType.DECREASE) {
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x16, (byte) 0x00);
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to dimm {}", nm(), dev.getAddress());
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Beispiel #9
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     int ext = getIntParameter("ext", 0);
     int direc = 0x00;
     int level = 0x00;
     Msg m = null;
     if (cmd == OnOffType.ON) {
       level = getMaxLightLevel(conf, 0xff);
       direc = 0x11;
       logger.info(
           "{}: sent msg to switch {} to {}",
           nm(),
           dev.getAddress(),
           level == 0xff ? "on" : level);
     } else if (cmd == OnOffType.OFF) {
       direc = 0x13;
       logger.info("{}: sent msg to switch {} off", nm(), dev.getAddress());
     }
     if (ext == 1 || ext == 2) {
       byte[] data =
           new byte[] {
             (byte) getIntParameter("d1", 0),
             (byte) getIntParameter("d2", 0),
             (byte) getIntParameter("d3", 0)
           };
       m = dev.makeExtendedMessage((byte) 0x0f, (byte) direc, (byte) level, data);
       logger.info("{}: was an extended message for device {}", nm(), dev.getAddress());
       if (ext == 1) m.setCRC();
       else if (ext == 2) m.setCRC2();
     } else {
       m = dev.makeStandardMessage((byte) 0x0f, (byte) direc, (byte) level, s_getGroup(conf));
     }
     logger.info("Sending message to {}", dev.getAddress());
     dev.enqueueMessage(m, m_feature);
     // expect to get a direct ack after this!
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Beispiel #10
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     PercentType pc = (PercentType) cmd;
     logger.debug("changing level of {} to {}", dev.getAddress(), pc.intValue());
     int level = (int) Math.ceil((pc.intValue() * 255.0) / 100); // round up
     if (level > 0) { // make light on message with given level
       level = getMaxLightLevel(conf, level);
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x11, (byte) level);
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to set {} to {}", nm(), dev.getAddress(), level);
     } else { // switch off
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x13, (byte) 0x00);
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent msg to set {} to zero by switching off", nm(), dev.getAddress());
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Beispiel #11
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     if (cmd == OnOffType.ON) {
       double ramptime = getRampTime(conf, 0);
       int ramplevel = getRampLevel(conf, 100);
       byte cmd2 = encode(ramptime, ramplevel);
       Msg m = dev.makeStandardMessage((byte) 0x0f, getOnCmd(), (byte) cmd2, s_getGroup(conf));
       dev.enqueueMessage(m, m_feature);
       logger.info(
           "{}: sent ramp on to switch {} time {} level {} cmd1 {}",
           nm(),
           dev.getAddress(),
           ramptime,
           ramplevel,
           getOnCmd());
     } else if (cmd == OnOffType.OFF) {
       double ramptime = getRampTime(conf, 0);
       int ramplevel = getRampLevel(conf, 0 /*ignored*/);
       byte cmd2 = encode(ramptime, ramplevel);
       Msg m = dev.makeStandardMessage((byte) 0x0f, getOffCmd(), (byte) cmd2, s_getGroup(conf));
       dev.enqueueMessage(m, m_feature);
       logger.info(
           "{}: sent ramp off to switch {} time {} cmd1 {}",
           nm(),
           dev.getAddress(),
           ramptime,
           getOffCmd());
     }
     // expect to get a direct ack after this!
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Beispiel #12
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     if (cmd == OnOffType.ON) {
       int level = getMaxLightLevel(conf, 0xff);
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x12, (byte) level, s_getGroup(conf));
       dev.enqueueMessage(m, m_feature);
       logger.info(
           "{}: sent fast on to switch {} level {}",
           nm(),
           dev.getAddress(),
           level == 0xff ? "on" : level);
     } else if (cmd == OnOffType.OFF) {
       Msg m = dev.makeStandardMessage((byte) 0x0f, (byte) 0x14, (byte) 0x00, s_getGroup(conf));
       dev.enqueueMessage(m, m_feature);
       logger.info("{}: sent fast off to switch {}", nm(), dev.getAddress());
     }
     // expect to get a direct ack after this!
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }
Beispiel #13
0
 @Override
 public void handleCommand(InsteonPLMBindingConfig conf, Command cmd, InsteonDevice dev) {
   try {
     byte houseCode = dev.getX10HouseCode();
     byte houseUnitCode = (byte) (houseCode << 4 | dev.getX10UnitCode());
     if (cmd == OnOffType.ON || cmd == OnOffType.OFF) {
       byte houseCommandCode =
           (byte)
               (houseCode << 4
                   | (cmd == OnOffType.ON ? X10.Command.ON.code() : X10.Command.OFF.code()));
       Msg munit = dev.makeX10Message(houseUnitCode, (byte) 0x00); // send unit code
       dev.enqueueMessage(munit, m_feature);
       Msg mcmd = dev.makeX10Message(houseCommandCode, (byte) 0x80); // send command code
       dev.enqueueMessage(mcmd, m_feature);
       String onOff = cmd == OnOffType.ON ? "ON" : "OFF";
       logger.info("{}: sent msg to switch {} {}", nm(), dev.getAddress(), onOff);
     }
   } catch (IOException e) {
     logger.error("{}: command send i/o error: ", nm(), e);
   } catch (FieldException e) {
     logger.error("{}: command send message creation error ", nm(), e);
   }
 }