use of org.openhab.core.items.Item in project openhab1-addons by openhab.
the class MiosBinding method internalReceiveCommand.
/**
* {@inheritDoc}
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
try {
logger.debug("internalReceiveCommand: itemName '{}', command '{}'", itemName, command);
// Lookup the MiOS Unit name and property for this item
String unitName = getMiosUnitName(itemName);
MiosUnitConnector connector = getMiosConnector(unitName);
if (connector == null) {
logger.warn("Received command ({}) for item '{}' but no connector found for MiOS Unit '{}', ignoring", new Object[] { command.toString(), itemName, unitName });
return;
}
if (!connector.isConnected()) {
logger.warn("Received command ({}) for item '{}' but the connection to the MiOS Unit '{}' is down, ignoring", new Object[] { command.toString(), itemName, unitName });
return;
}
for (BindingProvider provider : providers) {
if (provider instanceof MiosBindingProvider) {
MiosBindingProviderImpl miosProvider = (MiosBindingProviderImpl) provider;
MiosBindingConfig config = miosProvider.getMiosBindingConfig(itemName);
if (config != null) {
ItemRegistry reg = miosProvider.getItemRegistry();
if (reg != null) {
Item item = reg.getItem(config.getItemName());
State state = item.getState();
connector.invokeCommand(config, command, state);
} else {
logger.warn("internalReceiveCommand: Missing ItemRegistry for item '{}' command '{}'", itemName, command);
}
} else {
logger.trace("internalReceiveCommand: Missing BindingConfig for item '{}' command '{}'", itemName, command);
}
}
}
} catch (Exception e) {
logger.error("Error handling command", e);
}
}
use of org.openhab.core.items.Item in project openhab1-addons by openhab.
the class BticinoDevice method handleEvent.
public void handleEvent(ProtocolRead p_protocol_read) throws Exception {
// the events on the bus are now received
// map them to events on the openhab bus
logger.debug("Gateway [" + m_gateway_id + "], Bticino WHO [" + p_protocol_read.getProperty("who") + "], WHAT [" + p_protocol_read.getProperty("what") + "], WHERE [" + p_protocol_read.getProperty("where") + "]");
// Get all the configs that are connected to this (who,where), multiple
// possible
List<BticinoBindingConfig> l_binding_configs = m_bticino_binding.getItemForBticinoBindingConfig(p_protocol_read.getProperty("who"), p_protocol_read.getProperty("where"));
// log it when an event has occured that no item is bound to
if (l_binding_configs.isEmpty()) {
logger.debug("Gateway [" + m_gateway_id + "], No Item found for bticino event, WHO [" + p_protocol_read.getProperty("who") + "], WHAT [" + p_protocol_read.getProperty("what") + "], WHERE [" + p_protocol_read.getProperty("where") + "]");
}
// every item associated with this who/where update the status
for (BticinoBindingConfig l_binding_config : l_binding_configs) {
// Get the Item out of the config
Item l_item = l_binding_config.getItem();
if (l_item instanceof SwitchItem) {
// Lights
if (p_protocol_read.getProperty("messageType").equalsIgnoreCase("lighting")) {
logger.debug("Gateway [" + m_gateway_id + "], RECEIVED EVENT FOR SwitchItem [" + l_item.getName() + "], TRANSLATE TO OPENHAB BUS EVENT");
if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Light ON")) {
eventPublisher.postUpdate(l_item.getName(), OnOffType.ON);
} else if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Light OFF")) {
eventPublisher.postUpdate(l_item.getName(), OnOffType.OFF);
}
} else // CENs
if (p_protocol_read.getProperty("messageType").equalsIgnoreCase("CEN Basic and Evolved")) {
// Pushbutton virtual address must match
if (l_binding_config.what.equalsIgnoreCase(p_protocol_read.getProperty("what"))) {
logger.debug("Gateway [" + m_gateway_id + "], RECEIVED EVENT FOR SwitchItem [" + l_item.getName() + "], TRANSLATE TO OPENHAB BUS EVENT");
if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Virtual pressure")) {
// only returns when finished
eventPublisher.sendCommand(l_item.getName(), OnOffType.ON);
} else if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Virtual release after short pressure")) {
// only returns when finished
eventPublisher.sendCommand(l_item.getName(), OnOffType.ON);
} else if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Virtual release after an extended pressure")) {
// only returns when finished
eventPublisher.sendCommand(l_item.getName(), OnOffType.ON);
} else if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Virtual extended pressure")) {
// only returns when finished
eventPublisher.sendCommand(l_item.getName(), OnOffType.ON);
}
}
}
} else if (l_item instanceof RollershutterItem) {
logger.debug("Gateway [" + m_gateway_id + "], RECEIVED EVENT FOR RollershutterItem [" + l_item.getName() + "], TRANSLATE TO OPENHAB BUS EVENT");
if (p_protocol_read.getProperty("messageType").equalsIgnoreCase("automation")) {
if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Automation UP")) {
eventPublisher.postUpdate(l_item.getName(), UpDownType.UP);
} else if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Automation DOWN")) {
eventPublisher.postUpdate(l_item.getName(), UpDownType.DOWN);
}
}
} else if (l_item instanceof NumberItem) {
logger.debug("Gateway [" + m_gateway_id + "], RECEIVED EVENT FOR NumberItem [" + l_item.getName() + "], TRANSLATE TO OPENHAB BUS EVENT");
// THERMOREGULATION
if (p_protocol_read.getProperty("messageType").equalsIgnoreCase("thermoregulation")) {
if (p_protocol_read.getProperty("messageDescription").equalsIgnoreCase("Temperature value")) {
eventPublisher.postUpdate(l_item.getName(), DecimalType.valueOf(p_protocol_read.getProperty("temperature")));
}
}
}
}
}
use of org.openhab.core.items.Item in project openhab1-addons by openhab.
the class AutelisBinding method execute.
/**
* @{inheritDoc}
*/
@Override
protected void execute() {
logger.trace("Connecting to {}" + baseURL);
clearState();
String xmlDoc = fetchStateFromController();
if (xmlDoc == null) {
return;
}
for (AutelisBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
Item item = provider.getItem(itemName);
String config = provider.getAutelisBindingConfigString(itemName);
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
try {
InputSource is = new InputSource(new StringReader(xmlDoc));
String value = xpath.evaluate("response/" + config.replace('.', '/'), is);
State state = toState(item.getClass(), value);
State oldState = stateMap.put(itemName, state);
if (!state.equals(oldState)) {
logger.debug("updating item {} with state {}", itemName, state);
eventPublisher.postUpdate(itemName, state);
}
} catch (XPathExpressionException e) {
logger.warn("could not parse xml", e);
}
}
}
}
use of org.openhab.core.items.Item in project openhab1-addons by openhab.
the class EnoceanBinding method processEEPs.
private void processEEPs(EnoceanBindingProvider enoceanBindingProvider, String itemName) {
EnoceanParameterAddress parameterAddress = enoceanBindingProvider.getParameterAddress(itemName);
EEPId eep = enoceanBindingProvider.getEEP(itemName);
esp3Host.addDeviceProfile(parameterAddress.getEnoceanDeviceId(), eep);
Item item = enoceanBindingProvider.getItem(itemName);
if (profiles.containsKey(parameterAddress.getAsString())) {
Profile profile = profiles.get(parameterAddress.getAsString());
profile.removeItem(item);
}
Class<Profile> customProfileClass = enoceanBindingProvider.getCustomProfile(itemName);
if (customProfileClass != null) {
Constructor<Profile> constructor;
Profile profile;
try {
constructor = customProfileClass.getConstructor(Item.class, EventPublisher.class);
profile = constructor.newInstance(item, eventPublisher);
addProfile(item, parameterAddress, profile);
} catch (Exception e) {
logger.error("Could not create class for profile " + customProfileClass, e);
}
} else if (EEPId.EEP_F6_02_01.equals(eep) || EEPId.EEP_F6_10_00.equals(eep)) {
if (item.getClass().equals(RollershutterItem.class)) {
RollershutterProfile profile = new RollershutterProfile(item, eventPublisher);
addProfile(item, parameterAddress, profile);
}
if (item.getClass().equals(DimmerItem.class)) {
DimmerOnOffProfile profile = new DimmerOnOffProfile(item, eventPublisher);
addProfile(item, parameterAddress, profile);
}
if (item.getClass().equals(SwitchItem.class) && parameterAddress.getParameterId() == null) {
SwitchOnOffProfile profile = new SwitchOnOffProfile(item, eventPublisher);
addProfile(item, parameterAddress, profile);
}
if (item.getClass().equals(StringItem.class) && EEPId.EEP_F6_10_00.equals(eep)) {
WindowHandleProfile profile = new WindowHandleProfile(item, eventPublisher);
addProfile(item, parameterAddress, profile);
}
}
}
Aggregations