SystemOffsetProfile implements StateProfile { @Override public void onStateUpdateFromHandler(State state) { callback.sendUpdate((State) applyOffset(state, true)); } SystemOffsetProfile(ProfileCallback callback, ProfileContext context); @Override ProfileTypeUID getProfileTypeUID(); @Override void onStateUpdateFromItem(State state); @Override void onCommandFromItem(Command command); @Override void onCommandFromHandler(Command command); @Override void onStateUpdateFromHandler(State state);  }
@Test public void testDecimalTypeOnStateUpdateFromHandler() { ProfileCallback callback = mock(ProfileCallback.class); SystemOffsetProfile offsetProfile = createProfile(callback, "3"); State state = new DecimalType(23); offsetProfile.onStateUpdateFromHandler(state); ArgumentCaptor<State> capture = ArgumentCaptor.forClass(State.class); verify(callback, times(1)).sendUpdate(capture.capture()); State result = capture.getValue(); DecimalType decResult = (DecimalType) result; assertEquals(26, decResult.intValue()); }
@Test public void testQuantityTypeOnStateUpdateFromHandler() { ProfileCallback callback = mock(ProfileCallback.class); SystemOffsetProfile offsetProfile = createProfile(callback, "3°C"); State state = new QuantityType<>("23°C"); offsetProfile.onStateUpdateFromHandler(state); ArgumentCaptor<State> capture = ArgumentCaptor.forClass(State.class); verify(callback, times(1)).sendUpdate(capture.capture()); State result = capture.getValue(); @SuppressWarnings("unchecked") QuantityType<Temperature> decResult = (QuantityType<Temperature>) result; assertEquals(26, decResult.intValue()); assertEquals(SIUnits.CELSIUS, decResult.getUnit()); }
@Test public void testQuantityTypeOnStateUpdateFromHandlerFahrenheitOffset() { ProfileCallback callback = mock(ProfileCallback.class); SystemOffsetProfile offsetProfile = createProfile(callback, "3 °F"); State state = new QuantityType<>("23 °C"); offsetProfile.onStateUpdateFromHandler(state); ArgumentCaptor<State> capture = ArgumentCaptor.forClass(State.class); verify(callback, times(1)).sendUpdate(capture.capture()); State result = capture.getValue(); @SuppressWarnings("unchecked") QuantityType<Temperature> decResult = (QuantityType<Temperature>) result; assertThat(decResult.doubleValue(), is(closeTo(24.6666666666666666666666666666667d, 0.0000000000000001d))); assertEquals(SIUnits.CELSIUS, decResult.getUnit()); }
@Test public void testQuantityTypeOnStateUpdateFromHandlerDecimalOffset() { ProfileCallback callback = mock(ProfileCallback.class); SystemOffsetProfile offsetProfile = createProfile(callback, "3"); State state = new QuantityType<>("23 °C"); offsetProfile.onStateUpdateFromHandler(state); ArgumentCaptor<State> capture = ArgumentCaptor.forClass(State.class); verify(callback, times(1)).sendUpdate(capture.capture()); State result = capture.getValue(); @SuppressWarnings("unchecked") QuantityType<Temperature> decResult = (QuantityType<Temperature>) result; assertEquals(26, decResult.intValue()); assertEquals(SIUnits.CELSIUS, decResult.getUnit()); }