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");
private String getIdFromOpenHABCommand(OpenhabCommandType.OpenhabCommand command) { return command.getItemBindingConfig().split(":")[1]; }
switch (command.getType()) { case DECIMAL: switch (serviceType) { case POWER_CONSUMPTION_STATE_SERVICE: msg = PowerConsumptionStateTransformer.transform(command.getDecimal()); break; case MOTION_STATE_SERVICE: msg = MotionStateTransformer.transform(command.getDecimal()); break; case TAMPER_STATE_SERVICE: msg = TamperStateTransformer.transform(command.getDecimal()); break; case BATTERY_STATE_SERVICE: msg = BatteryStateTransformer.transform(command.getDecimal()); break; case TEMPERATURE_ALARM_STATE_SERVICE: case SMOKE_ALARM_STATE_SERVICE: msg = AlarmStateTransformer.transform(command.getDecimal()); break; case SMOKE_STATE_SERVICE: msg = SmokeStateTransformer.transform(command.getDecimal()); break; case TEMPERATURE_STATE_SERVICE: case TARGET_TEMPERATURE_STATE_SERVICE: msg = TemperatureStateTransformer.transform(command.getDecimal()); break; case BRIGHTNESS_STATE_SERVICE: msg = BrightnessStateTransformer.transform(command.getDecimal()); break;
try { OpenhabCommand openhabCommand = (OpenhabCommand) event.getData(); if (!openhabCommand.hasItemBindingConfig() || !openhabCommand.getItemBindingConfig().startsWith(itemFilter)) { return;
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 static Object getCommandData(final OpenhabCommand command) throws CouldNotPerformException { switch (command.getType()) { case DECIMAL: return command.getDecimal(); case HSB: return command.getHsb(); case INCREASEDECREASE: return command.getIncreaseDecrease(); case ONOFF: return command.getOnOff(); case OPENCLOSED: return command.getOpenClosed(); case PERCENT: return command.getPercent(); case STOPMOVE: return command.getStopMove(); case STRING: return command.getText(); case UPDOWN: return command.getUpDown(); default: throw new CouldNotTransformException("No corresponding data found for " + command + "."); } } }
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(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... } }
private ServiceType getServiceTypeForCommand(OpenhabCommandType.OpenhabCommand command) { return ServiceType.valueOf(StringProcessor.transformToUpperCase(command.getItem().split(ITEM_SEGMENT_DELIMITER)[1])); } }
private String getIdFromOpenHABItem(OpenhabCommandType.OpenhabCommand command) { return command.getItemBindingConfig().split(":")[1]; } }
@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 String getSceneIdFromOpenHABItem(OpenhabCommandType.OpenhabCommand command) { return command.getItemBindingConfig().split(":")[1]; } }
@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); } }
@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); } }