@Override protected void updateDynamicComponents() { try { switch (getProviderService().getContactState().getValue()) { case UNKNOWN: reedSwitchStateLabel.setForeground(Color.DARK_GRAY); reedSwitchStatePanel.setBackground(Color.ORANGE.darker()); break; case CLOSED: reedSwitchStateLabel.setForeground(Color.WHITE); reedSwitchStatePanel.setBackground(Color.BLUE); break; case OPEN: reedSwitchStateLabel.setForeground(Color.WHITE); reedSwitchStatePanel.setBackground(Color.GREEN.darker()); break; default: throw new InvalidStateException("State[" + getProviderService().getContactState().getValue() + "] is unknown."); } reedSwitchStateLabel.setText("Current ReedState = " + StringProcessor.transformUpperCaseToCamelCase(getProviderService().getContactState().getValue().name())); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, logger, LogLevel.ERROR); } } }
public static ContactState transform(OpenClosedHolder.OpenClosed openClosedType) throws CouldNotTransformException { switch (openClosedType) { case CLOSED: return ContactState.newBuilder().setValue(ContactState.State.CLOSED).build(); case OPEN: return ContactState.newBuilder().setValue(ContactState.State.OPEN).build(); default: throw new CouldNotTransformException("Could not transform " + OpenClosedHolder.OpenClosed.class.getName() + "! " + OpenClosedHolder.OpenClosed.class.getSimpleName() + "[" + openClosedType.name() + "] is unknown!"); } }
switch (contactState.getValue()) { case CLOSED: if (doorState == null) { doorState = correspondingDoorState; timestamp = Math.max(timestamp, contactState.getTimestamp().getTime()); } else if (doorState != correspondingDoorState) { try { if (doorState == null) { doorState = DoorState.State.OPEN; timestamp = Math.max(timestamp, contactState.getTimestamp().getTime());
switch (contactState.getValue()) { case CLOSED: if (windowState == null) { windowState = correspondingWindowState; timestamp = Math.max(timestamp, contactState.getTimestamp().getTime()); } else if (windowState != correspondingWindowState) { try { if (windowState == null) { windowState = WindowState.State.OPEN; timestamp = Math.max(timestamp, contactState.getTimestamp().getTime());
public static OpenClosedHolder transform(ContactState contactState) throws CouldNotTransformException { try { switch (contactState.getValue()) { case CLOSED: return OpenClosedHolder.newBuilder().setState(OpenClosedHolder.OpenClosed.CLOSED).build(); case OPEN: return OpenClosedHolder.newBuilder().setState(OpenClosedHolder.OpenClosed.OPEN).build(); case UNKNOWN: throw new InvalidStateException("Unknown state is invalid!"); default: throw new TypeNotSupportedException(contactState, OpenClosedHolder.class); } } catch (CouldNotPerformException ex) { throw new CouldNotTransformException("Could not transform " + ContactState.class.getName() + "!", ex); } } }
@Override public ContactState getContactState(final UnitType unitType) throws NotAvailableException { ContactState.State contactValue = ContactState.State.CLOSED; long timestamp = 0; for (ContactStateProviderService service : getServices(unitType)) { if (!((UnitRemote) service).isDataAvailable()) { continue; } if (service.getContactState().getValue() == ContactState.State.OPEN) { contactValue = ContactState.State.OPEN; } timestamp = Math.max(timestamp, service.getContactState().getTimestamp().getTime()); } return TimestampProcessor.updateTimestamp(timestamp, ContactState.newBuilder().setValue(contactValue), TimeUnit.MICROSECONDS, logger).build(); } }
/** * Method returns the state source(s) result(s) (contains state value(s)) of the input contactState. * * @param contactState The ContactState. * @return state source(s) result(s) of the input state. */ private List<RdfNodeObject> contactStateSources(final ContactState contactState) { final List<RdfNodeObject> stateSources = new ArrayList<>(); final String contactStateVal = contactState.getValue().toString(); stateSources.add(new RdfNodeObject(new ArrayList<String>() {{add(contactStateVal);}}, false)); return stateSources; }