/** * Method returns the state source(s) result(s) (contains state value(s)) of the input alarmState. * * @param alarmState The AlarmState. * @return state source(s) result(s) of the input state. */ private List<RdfNodeObject> alarmStateSources(final AlarmState alarmState) { final List<RdfNodeObject> stateSources = new ArrayList<>(); final String alarmStateVal = alarmState.getValue().toString(); stateSources.add(new RdfNodeObject(new ArrayList<String>() {{add(alarmStateVal);}}, false)); return stateSources; }
public static AlarmState transform(final Double decimalType) throws CouldNotTransformException { AlarmState.Builder alarmState = AlarmState.newBuilder(); try { if (decimalType.intValue() == 0) { alarmState.setValue(State.NO_ALARM); } else if (decimalType.intValue() == 1) { alarmState.setValue(State.ALARM); } return alarmState.build(); } catch (Exception ex) { throw new CouldNotTransformException("Could not transform " + Double.class.getName() + "! " + Double.class.getSimpleName() + "[" + decimalType + "] is unknown!", ex); } }
public static Double transform(final AlarmState alarmState) throws CouldNotTransformException { try { switch (alarmState.getValue()) { case NO_ALARM: return 0d; case ALARM: return 1d; case UNKNOWN: throw new InvalidStateException("Unknown state is invalid!"); default: throw new TypeNotSupportedException(AlarmState.State.class, Double.class); } } catch (CouldNotPerformException ex) { throw new CouldNotTransformException("Could not transform " + AlarmState.State.class.getName() + "!", ex); } } }
@Override public AlarmState getSmokeAlarmState(final UnitType unitType) throws NotAvailableException { AlarmState.State alarmValue = AlarmState.State.NO_ALARM; long timestamp = 0; for (SmokeAlarmStateProviderService service : getServices(unitType)) { if (!((UnitRemote) service).isDataAvailable()) { continue; } if (service.getSmokeAlarmState().getValue() == AlarmState.State.ALARM) { alarmValue = AlarmState.State.ALARM; } timestamp = Math.max(timestamp, service.getSmokeAlarmState().getTimestamp().getTime()); } return TimestampProcessor.updateTimestamp(timestamp, AlarmState.newBuilder().setValue(alarmValue), TimeUnit.MICROSECONDS, logger).build(); } }
/** * Creates a new custom unit simulator. * * @param unitController the unit to simulate. * @param serviceType the service type, e.g SMOKE_ALARM_STATE */ public AlarmStateSimulator(UnitController unitController, ServiceType serviceType) { super(unitController, serviceType); this.simulatedAlarmState = AlarmState.newBuilder(); this.simulatedAlarmState.setValue(AlarmState.State.NO_ALARM); this.counter = 0; }