use of org.openhab.binding.insteonplm.internal.device.InsteonDevice in project openhab1-addons by openhab.
the class InsteonPLMActiveBinding method removeFeatureListener.
/**
* Finds the device that a particular item was bound to, and removes the
* item as a listener
*
* @param aItem The item (FeatureListener) to remove from all devices
*/
private void removeFeatureListener(String aItem) {
for (Iterator<Entry<InsteonAddress, InsteonDevice>> it = m_devices.entrySet().iterator(); it.hasNext(); ) {
InsteonDevice dev = it.next().getValue();
boolean removedListener = dev.removeFeatureListener(aItem);
if (removedListener) {
logger.trace("removed feature listener {} from dev {}", aItem, dev);
}
if (!dev.hasAnyListeners()) {
Poller.s_instance().stopPolling(dev);
it.remove();
logger.trace("removing unreferenced {}", dev);
if (m_devices.isEmpty()) {
logger.debug("all devices removed!", dev);
}
}
}
}
use of org.openhab.binding.insteonplm.internal.device.InsteonDevice in project openhab1-addons by openhab.
the class InsteonPLMActiveBinding method sendCommand.
/**
* Send command to insteon device
*
* @param c item binding configuration
* @param command The command to be sent
*/
private void sendCommand(InsteonPLMBindingConfig c, Command command) {
InsteonDevice dev = getDevice(c.getAddress());
if (dev == null) {
logger.warn("no device found with insteon address {}", c.getAddress());
return;
}
dev.processCommand(m_driver, c, command);
}
use of org.openhab.binding.insteonplm.internal.device.InsteonDevice in project openhab1-addons by openhab.
the class InsteonPLMActiveBinding method logDeviceStatistics.
private void logDeviceStatistics() {
logger.info(String.format("devices: %3d configured, %3d polling, msgs received: %5d", m_devices.size(), Poller.s_instance().getSizeOfQueue(), m_messagesReceived));
m_messagesReceived = 0;
for (InsteonDevice dev : m_devices.values()) {
if (dev.isModem()) {
continue;
}
if (m_deadDeviceTimeout > 0 && dev.getPollOverDueTime() > m_deadDeviceTimeout) {
logger.info("device {} has not responded to polls for {} sec", dev.toString(), dev.getPollOverDueTime() / 3600);
}
}
}
use of org.openhab.binding.insteonplm.internal.device.InsteonDevice in project openhab1-addons by openhab.
the class InsteonPLMActiveBinding method bindingChanged.
/**
* Inherited from AbstractActiveBinding.
* This method is called by the framework whenever there are changes to
* a binding configuration.
*
* @param provider the binding provider where the binding has changed
* @param itemName the item name for which the binding has changed
*/
@Override
public void bindingChanged(BindingProvider provider, String itemName) {
super.bindingChanged(provider, itemName);
// hack around openHAB bug
m_hasInitialItemConfig = true;
InsteonPLMBindingConfig c = ((InsteonPLMBindingProvider) provider).getInsteonPLMBindingConfig(itemName);
logger.debug("item {} binding changed: {}", String.format("%-30s", itemName), c);
if (c == null) {
// Item has been removed. This condition is also found when *any*
// change to the items file is made: the items are first removed (c == null),
// and then added anew.
removeFeatureListener(itemName);
} else {
InsteonDevice dev = getDevice(c.getAddress());
if (dev == null) {
dev = makeNewDevice(c);
}
addFeatureListener(dev, itemName, c);
}
}
use of org.openhab.binding.insteonplm.internal.device.InsteonDevice in project openhab1-addons by openhab.
the class InsteonPLMActiveBinding method makeNewDevice.
/**
* Creates a new insteon device for a given product key
*
* @param aConfig The binding configuration parameters, needed to make device.
* @return Reference to the new device that has been created
*/
private InsteonDevice makeNewDevice(InsteonPLMBindingConfig aConfig) {
String prodKey = aConfig.getProductKey();
DeviceType dt = DeviceTypeLoader.s_instance().getDeviceType(prodKey);
if (dt == null) {
logger.error("unknown product key: {} for config: {}." + " Add definition to xml file and try again", prodKey, aConfig);
return null;
}
InsteonDevice dev = InsteonDevice.s_makeDevice(dt);
dev.setAddress(aConfig.getAddress());
dev.setDriver(m_driver);
dev.addPort(m_driver.getDefaultPort());
if (!dev.hasValidPollingInterval()) {
dev.setPollInterval(m_devicePollInterval);
}
if (m_driver.isModemDBComplete() && dev.getStatus() != DeviceStatus.POLLING) {
int ndev = checkIfInModemDatabase(dev);
if (dev.hasModemDBEntry()) {
dev.setStatus(DeviceStatus.POLLING);
Poller.s_instance().startPolling(dev, ndev);
}
}
m_devices.put(aConfig.getAddress(), dev);
return (dev);
}
Aggregations