@Override public void internalReceiveCommand(OpenhabCommand command) throws CouldNotPerformException { //TODO: this is just a hack // Why do all items from knx publish their new values as commands, check if this is configurable in ets if (command.getItem().startsWith("Hager") || command.getItem().startsWith("Gira")) { internalReceiveUpdate(command); } // because the hue feedback channel is because of the polling strategy to slow, we hack the by redirecting the command channel on the feedback channel. if (command.getItem().startsWith("Philips")) { internalReceiveUpdate(command); } // do nothing... } }
@Override public void internalReceiveUpdate(final OpenhabCommand command) throws CouldNotPerformException { try { //Ignore commands that are not for the device manager but for example for the scene registry if (!command.getItemBindingConfig().isEmpty() || command.getItem().startsWith("Location")) { logger.debug("Ignoring item [" + command.getItem() + "] because itemBindingConfig [" + command.getItemBindingConfig() + "] is not empty"); return; } commandExecutor.receiveUpdate(command); } catch (Exception ex) { throw new CouldNotPerformException("Skip item update [" + command.getItem() + " = " + OpenhabCommandTransformer.getCommandData(command) + "]!", ex); } }
private ServiceType getServiceTypeForCommand(OpenhabCommandType.OpenhabCommand command) { return ServiceType.valueOf(StringProcessor.transformToUpperCase(command.getItem().split(ITEM_SEGMENT_DELIMITER)[1])); } }
if (command.getItem().startsWith("Location")) { logger.debug("Received command for location [" + command.getItem() + "] from openhab"); remote = locationRegistry.get(getIdFromOpenHABCommand(command)); } else if (command.getItem().startsWith("Connection")) { logger.debug("Received command for connection [" + command.getItem() + "] from openhab"); remote = connectionRegistry.get(getIdFromOpenHABCommand(command)); } else if (command.getItem().startsWith("UnitGroup")) { logger.debug("Received command for unitgroup [" + command.getItem() + "] from openhab"); remote = unitGroupRegistry.get(getIdFromOpenHABCommand(command)); throw new NotAvailableException("No remote for item [" + command.getItem() + "] found");
public OpenhabCommandMetaData(OpenhabCommand command) throws CouldNotPerformException { this.command = command; try { String[] nameSegment = command.getItem().split(ITEM_SEGMENT_DELIMITER); try { locationId = nameSegment[1].replace(ITEM_SUBSEGMENT_DELIMITER, Scope.COMPONENT_SEPARATOR); } catch (IndexOutOfBoundsException | NullPointerException ex) { throw new CouldNotPerformException("Could not extract location id out of item name!"); } try { this.unitScope = (Scope.COMPONENT_SEPARATOR + locationId + Scope.COMPONENT_SEPARATOR + nameSegment[2] + Scope.COMPONENT_SEPARATOR + nameSegment[3] + Scope.COMPONENT_SEPARATOR).toLowerCase(); } catch (IndexOutOfBoundsException | NullPointerException ex) { throw new CouldNotPerformException("Could not extract unit id out of item name!"); } try { System.out.println("sec["+nameSegment[4]+"] from item["+command.getItem()+"]"); serviceType = ServiceTemplate.ServiceType.valueOf(StringProcessor.transformToUpperCase(nameSegment[4])); } catch (IndexOutOfBoundsException | IllegalArgumentException | NullPointerException ex) { throw new CouldNotPerformException("Could not extract service type out of item name!", ex); } } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not extract meta data out of openhab command because Item[" + command.getItem() + "] not compatible!", ex); } }
public void receiveUpdate(OpenhabCommandType.OpenhabCommand command) throws CouldNotPerformException { LOGGER.info("receiveUpdate [" + command.getItem() + "=" + command.getType() + "]"); OpenhabCommandMetaData metaData = new OpenhabCommandMetaData(command); Object serviceData = OpenhabCommandTransformer.getServiceData(command, metaData.getServiceType()); if (serviceData == null) { return; } final UnitController unitController; try { unitController = unitControllerRegistry.getUnitByScope(metaData.getUnitScope()); } catch (NotAvailableException ex) { if (!unitControllerRegistry.isInitiallySynchronized()) { LOGGER.debug("ItemUpdate[" + command.getItem() + "=" + command.getType() + "] skipped because controller registry was not ready yet!"); return; } throw ex; } unitController.applyDataUpdate(serviceData, metaData.getServiceType()); } }
@Override public void internalReceiveCommand(OpenhabCommandType.OpenhabCommand command) throws CouldNotPerformException { try { if (!command.hasOnOff() || !command.getOnOff().hasState()) { throw new CouldNotPerformException("Command does not have an onOff value required for scenes"); } logger.debug("Received command for scene [" + command.getItem() + "] from openhab"); sceneRegistry.get(getSceneIdFromOpenHABItem(command)).setActivationState(ActivationStateTransformer.transform(command.getOnOff().getState())); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Skip item update [" + command.getItem() + " = " + command.getOnOff() + "]!", ex); } }
@Override public void internalReceiveCommand(OpenhabCommandType.OpenhabCommand command) throws CouldNotPerformException { try { if (!command.hasOnOff() || !command.getOnOff().hasState()) { throw new CouldNotPerformException("Command does not have an onOff value required for apps"); } logger.debug("Received command for app [" + command.getItem() + "] from openhab"); appRegistry.get(getIdFromOpenHABItem(command)).setActivationState(ActivationStateTransformer.transform(command.getOnOff().getState())); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Skip item update [" + command.getItem() + " = " + command.getOnOff() + "]!", ex); } }
private void validateCommand(final OpenhabCommand command) throws InvalidStateException { try { if (!command.hasItem() || command.getItem().isEmpty()) { throw new NotAvailableException("command item"); } if (!command.hasType()) { throw new NotAvailableException("command type"); } } catch (CouldNotPerformException ex) { throw new InvalidStateException("Command invalid!", ex); } }