SwitchItem extends GenericItem { @Override public void setState(State state) { if (isAcceptedState(acceptedDataTypes, state)) { super.setState(state); } else { logSetTypeError(state); } } SwitchItem(String name);   SwitchItem(String type, String name); void send(OnOffType command); @Override List<Class<? extends State>> getAcceptedDataTypes(); @Override List<Class<? extends Command>> getAcceptedCommandTypes(); @Override void setState(State state);  }
@Test public void getAsPercentFromSwitch() { SwitchItem item = new SwitchItem("Test"); item.setState(OnOffType.ON); assertEquals(new PercentType(100), item.getStateAs(PercentType.class)); item.setState(OnOffType.OFF); assertEquals(new PercentType(0), item.getStateAs(PercentType.class)); }
@Test public void getAsDecimalFromSwitch() { SwitchItem item = new SwitchItem("Test"); item.setState(OnOffType.ON); assertEquals(new DecimalType(1), item.getStateAs(DecimalType.class)); item.setState(OnOffType.OFF); assertEquals(new DecimalType(0), item.getStateAs(DecimalType.class)); }
@Test public void getAsHSBFromSwitch() { SwitchItem item = new SwitchItem("Test"); item.setState(OnOffType.ON); assertEquals(new HSBType("0,0,100"), item.getStateAs(HSBType.class)); item.setState(OnOffType.OFF); assertEquals(new HSBType("0,0,0"), item.getStateAs(HSBType.class)); }