Java Code Examples for org.eclipse.smarthome.core.library.types.OnOffType#OFF
The following examples show how to use
org.eclipse.smarthome.core.library.types.OnOffType#OFF .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OwserverConnection.java From smarthome with Eclipse Public License 2.0 | 6 votes |
/** * check sensor presence * * @param path full owfs path to sensor * @return OnOffType, ON=present, OFF=not present * @throws OwException */ public State checkPresence(String path) throws OwException { State returnValue = OnOffType.OFF; try { OwserverPacket requestPacket; requestPacket = new OwserverPacket(OwserverMessageType.PRESENT, path, OwserverControlFlag.UNCACHED); OwserverPacket returnPacket = request(requestPacket); if (returnPacket.getReturnCode() == 0) { returnValue = OnOffType.ON; } } catch (OwException e) { returnValue = OnOffType.OFF; } logger.trace("presence {} : {}", path, returnValue); return returnValue; }
Example 2
Source File: WemoLightHandler.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public void onValueReceived(String variable, String value, String service) { logger.trace("Received pair '{}':'{}' (service '{}') for thing '{}'", new Object[] { variable, value, service, this.getThing().getUID() }); String capabilityId = StringUtils.substringBetween(value, "<CapabilityId>", "</CapabilityId>"); String newValue = StringUtils.substringBetween(value, "<Value>", "</Value>"); switch (capabilityId) { case "10006": OnOffType binaryState = null; binaryState = newValue.equals("0") ? OnOffType.OFF : OnOffType.ON; if (binaryState != null) { updateState(CHANNEL_STATE, binaryState); } break; case "10008": String splitValue[] = newValue.split(":"); if (splitValue[0] != null) { int newBrightnessValue = Integer.valueOf(splitValue[0]); int newBrightness = Math.round(newBrightnessValue * 100 / 255); State newBrightnessState = new PercentType(newBrightness); updateState(CHANNEL_BRIGHTNESS, newBrightnessState); currentBrightness = newBrightness; } break; } }
Example 3
Source File: GenericItemProvider2Test.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void testGroupItemChangesBaseItem() { GenericItemProvider gip = new GenericItemProvider(); GroupItem g1 = new GroupItem("testGroup", new SwitchItem("test"), new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF)); GroupItem g2 = new GroupItem("testGroup", new NumberItem("test"), new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF)); assertTrue(gip.hasItemChanged(g1, g2)); }
Example 4
Source File: OnOffValue.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public void update(Command command) throws IllegalArgumentException { if (command instanceof OnOffType) { state = (OnOffType) command; } else { final String updatedValue = command.toString(); if (onString.equals(updatedValue)) { state = OnOffType.ON; } else if (offString.equals(updatedValue)) { state = OnOffType.OFF; } else { state = OnOffType.valueOf(updatedValue); } } }
Example 5
Source File: DigitalIoConfig.java From smarthome with Eclipse Public License 2.0 | 5 votes |
public State convertState(Boolean rawValue) { if (ioLogic == DigitalIoLogic.NORMAL) { return rawValue ? OnOffType.ON : OnOffType.OFF; } else { return rawValue ? OnOffType.OFF : OnOffType.ON; } }
Example 6
Source File: TradfriWirelessDeviceData.java From smarthome with Eclipse Public License 2.0 | 5 votes |
public OnOffType getBatteryLow() { if (generalInfo.get(DEVICE_BATTERY_LEVEL) != null) { return generalInfo.get(DEVICE_BATTERY_LEVEL).getAsInt() <= 10 ? OnOffType.ON : OnOffType.OFF; } else { return null; } }
Example 7
Source File: WemoHandlerOSGiTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void assertThatThingHandlesOnOffCommandCorrectly() throws MalformedURLException, URISyntaxException, ValidationException { Command command = OnOffType.OFF; WemoHttpCall mockCaller = Mockito.spy(new WemoHttpCall()); Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE, mockCaller); waitForAssert(() -> { assertThat(thing.getStatus(), is(ThingStatus.ONLINE)); }); // The device is registered as UPnP Device after the initialization, this will ensure that the polling job will // not start addUpnpDevice(SERVICE_ID, SERVICE_NUMBER, MODEL_NAME); WemoHandler handler = (WemoHandler) thing.getHandler(); assertNotNull(handler); ChannelUID channelUID = new ChannelUID(thing.getUID(), DEFAULT_TEST_CHANNEL); handler.handleCommand(channelUID, command); ArgumentCaptor<String> captur = ArgumentCaptor.forClass(String.class); verify(mockCaller, atLeastOnce()).executeCall(any(), any(), captur.capture()); List<String> results = captur.getAllValues(); boolean found = false; for (String result : results) { // Binary state 0 is equivalent to OFF if (result.contains("<BinaryState>0</BinaryState>")) { found = true; break; } } assertTrue(found); }
Example 8
Source File: RawButtonToggleSwitchProfile.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public void onTriggerFromHandler(String event) { if (CommonTriggerEvents.PRESSED.equals(event)) { OnOffType newState = OnOffType.ON.equals(previousState) ? OnOffType.OFF : OnOffType.ON; callback.sendCommand(newState); previousState = newState; } }
Example 9
Source File: ColorItem.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public void setState(State state) { if (isAcceptedState(acceptedDataTypes, state)) { State currentState = this.state; if (currentState instanceof HSBType) { DecimalType hue = ((HSBType) currentState).getHue(); PercentType saturation = ((HSBType) currentState).getSaturation(); // we map ON/OFF values to dark/bright, so that the hue and saturation values are not changed if (state == OnOffType.OFF) { applyState(new HSBType(hue, saturation, PercentType.ZERO)); } else if (state == OnOffType.ON) { applyState(new HSBType(hue, saturation, PercentType.HUNDRED)); } else if (state instanceof PercentType && !(state instanceof HSBType)) { applyState(new HSBType(hue, saturation, (PercentType) state)); } else if (state instanceof DecimalType && !(state instanceof HSBType)) { applyState(new HSBType(hue, saturation, new PercentType(((DecimalType) state).toBigDecimal().multiply(BigDecimal.valueOf(100))))); } else { applyState(state); } } else { // try conversion State convertedState = state.as(HSBType.class); if (convertedState != null) { applyState(convertedState); } else { applyState(state); } } } else { logSetTypeError(state); } }
Example 10
Source File: DialogProcessor.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private void toggleProcessing(boolean value) { if (this.processing == value) { return; } this.processing = value; if (listeningItem != null && ItemUtil.isValidItemName(listeningItem)) { OnOffType command = (value) ? OnOffType.ON : OnOffType.OFF; eventPublisher.post(ItemEventFactory.createCommandEvent(listeningItem, command)); } }
Example 11
Source File: ManagedItemProviderOSGiTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("null") @Test public void assertGroupFunctionsAreStoredAndRetrievedAsWell() { assertThat(itemProvider.getAll().size(), is(0)); GroupFunction function1 = new And(OnOffType.ON, OnOffType.OFF); GroupFunction function2 = new Sum(); GroupItem item1 = new GroupItem("GroupItem1", new SwitchItem("Switch"), function1); GroupItem item2 = new GroupItem("GroupItem2", new NumberItem("Number"), function2); assertThat(item1.getName(), is("GroupItem1")); assertEquals(item1.getFunction().getClass(), And.class); assertThat(item1.getFunction().getParameters(), is(new State[] { OnOffType.ON, OnOffType.OFF })); assertThat(item2.name, is("GroupItem2")); assertEquals(item2.getFunction().getClass(), Sum.class); assertThat(item2.getFunction().getParameters(), is(new State[0])); itemProvider.add(item1); itemProvider.add(item2); Collection<Item> items = itemProvider.getAll(); assertThat(items.size(), is(2)); GroupItem result1 = (GroupItem) itemProvider.remove("GroupItem1"); GroupItem result2 = (GroupItem) itemProvider.remove("GroupItem2"); assertThat(result1.getName(), is("GroupItem1")); assertEquals(result1.getFunction().getClass(), And.class); assertThat(result1.function.getParameters(), is(new State[] { OnOffType.ON, OnOffType.OFF })); assertThat(result2.getName(), is("GroupItem2")); assertEquals(result2.getFunction().getClass(), Sum.class); assertThat(result2.function.getParameters(), is(new State[0])); assertThat(itemProvider.getAll().size(), is(0)); }
Example 12
Source File: GroupItemTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void assertThatGroupItemChangesRespectGroupFunctionOR() { events.clear(); GroupItem groupItem = new GroupItem("root", new SwitchItem("mySwitch"), new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF)); groupItem.setItemStateConverter(itemStateConverter); SwitchItem sw1 = new SwitchItem("switch1"); SwitchItem sw2 = new SwitchItem("switch2"); groupItem.addMember(sw1); groupItem.addMember(sw2); groupItem.setEventPublisher(publisher); // State changes -> one change event is fired sw1.setState(OnOffType.ON); waitForAssert(() -> assertThat(events.size(), is(1))); List<Event> changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent) .collect(Collectors.toList()); assertThat(changes.size(), is(1)); GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0); assertTrue(change.getItemName().equals(groupItem.getName())); assertTrue(change.getOldItemState().equals(UnDefType.NULL)); assertTrue(change.getItemState().equals(OnOffType.ON)); assertTrue(groupItem.getState().equals(OnOffType.ON)); }
Example 13
Source File: DefaultChartProvider.java From smarthome with Eclipse Public License 2.0 | 5 votes |
double convertData(State state) { if (state instanceof DecimalType) { return ((DecimalType) state).doubleValue(); } else if (state instanceof OnOffType) { return (state == OnOffType.OFF) ? 0 : 1; } else if (state instanceof OpenClosedType) { return (state == OpenClosedType.CLOSED) ? 0 : 1; } else { logger.debug("Unsupported item type in chart: {}", state.getClass().toString()); return 0; } }
Example 14
Source File: GenericItemProvider2Test.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void testGroupItemChangesBaseItemAndFunction() { GenericItemProvider gip = new GenericItemProvider(); GroupItem g1 = new GroupItem("testGroup", new SwitchItem("test"), new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF)); GroupItem g2 = new GroupItem("testGroup", new NumberItem("number"), new ArithmeticGroupFunction.Sum()); assertTrue(gip.hasItemChanged(g1, g2)); }
Example 15
Source File: GenericItemProvider2Test.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void testGroupItemChangesFunctionParameters() { GenericItemProvider gip = new GenericItemProvider(); GroupItem g1 = new GroupItem("testGroup", new SwitchItem("test"), new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF)); GroupItem g2 = new GroupItem("testGroup", new SwitchItem("test"), new ArithmeticGroupFunction.Or(OnOffType.ON, UnDefType.UNDEF)); assertTrue(gip.hasItemChanged(g1, g2)); }
Example 16
Source File: GenericItemProvider2Test.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void testGroupItemIsSame() { GenericItemProvider gip = new GenericItemProvider(); GroupItem g1 = new GroupItem("testGroup", new SwitchItem("test"), new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF)); GroupItem g2 = new GroupItem("testGroup", new SwitchItem("test"), new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF)); assertFalse(gip.hasItemChanged(g1, g2)); }
Example 17
Source File: GroupItemTest.java From smarthome with Eclipse Public License 2.0 | 4 votes |
@Test public void assertThatGroupItemChangesRespectGroupFunctionAND() { events.clear(); GroupItem groupItem = new GroupItem("root", new SwitchItem("mySwitch"), new ArithmeticGroupFunction.And(OnOffType.ON, OnOffType.OFF)); groupItem.setItemStateConverter(itemStateConverter); SwitchItem sw1 = new SwitchItem("switch1"); SwitchItem sw2 = new SwitchItem("switch2"); groupItem.addMember(sw1); groupItem.addMember(sw2); groupItem.setEventPublisher(publisher); // State changes -> one change event is fired sw1.setState(OnOffType.ON); waitForAssert(() -> assertThat(events.size(), is(1))); List<Event> changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent) .collect(Collectors.toList()); assertThat(changes.size(), is(1)); GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0); assertTrue(change.getItemName().equals(groupItem.getName())); // we expect that the group should now have status "OFF" assertTrue(change.getOldItemState().equals(UnDefType.NULL)); assertTrue(change.getItemState().equals(OnOffType.OFF)); events.clear(); // State changes -> one change event is fired sw2.setState(OnOffType.ON); waitForAssert(() -> assertThat(events.size(), is(1))); changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent).collect(Collectors.toList()); assertThat(changes.size(), is(1)); change = (GroupItemStateChangedEvent) changes.get(0); assertTrue(change.getItemName().equals(groupItem.getName())); // we expect that the group should now have status "ON" assertTrue(change.getOldItemState().equals(OnOffType.OFF)); assertTrue(change.getItemState().equals(OnOffType.ON)); assertTrue(groupItem.getState().equals(OnOffType.ON)); }
Example 18
Source File: GroupItemTest.java From smarthome with Eclipse Public License 2.0 | 4 votes |
@Test public void assertThatGroupItemChangesRespectGroupFunctionORwithUNDEF() throws InterruptedException { events.clear(); GroupItem groupItem = new GroupItem("root", new SwitchItem("mySwitch"), new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF)); groupItem.setItemStateConverter(itemStateConverter); SwitchItem sw1 = new SwitchItem("switch1"); SwitchItem sw2 = new SwitchItem("switch2"); groupItem.addMember(sw1); groupItem.addMember(sw2); groupItem.setEventPublisher(publisher); // State changes -> one change event is fired sw1.setState(OnOffType.ON); waitForAssert(() -> assertThat(events.size(), is(1))); List<Event> changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent) .collect(Collectors.toList()); assertThat(changes.size(), is(1)); GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0); assertTrue(change.getItemName().equals(groupItem.getName())); assertTrue(change.getOldItemState().equals(UnDefType.NULL)); assertTrue(change.getItemState().equals(OnOffType.ON)); events.clear(); sw2.setState(OnOffType.ON); sw2.setState(UnDefType.UNDEF); // wait to see that the event doesn't fire Thread.sleep(WAIT_EVENT_TO_BE_HANDLED); assertThat(events.size(), is(0)); assertTrue(groupItem.getState().equals(OnOffType.ON)); }
Example 19
Source File: OnOffTypeConverter.java From smarthome with Eclipse Public License 2.0 | 4 votes |
@Override protected OnOffType fromBinding(HmDatapoint dp) throws ConverterException { return (((Boolean) dp.getValue()) == Boolean.FALSE) != isInvert(dp) ? OnOffType.OFF : OnOffType.ON; }
Example 20
Source File: WemoLightHandler.java From smarthome with Eclipse Public License 2.0 | 4 votes |
/** * The {@link getDeviceState} is used for polling the actual state of a WeMo Light and updating the according * channel states. */ public void getDeviceState() { logger.debug("Request actual state for LightID '{}'", wemoLightID); try { String soapHeader = "\"urn:Belkin:service:bridge:1#GetDeviceStatus\""; String content = "<?xml version=\"1.0\"?>" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<s:Body>" + "<u:GetDeviceStatus xmlns:u=\"urn:Belkin:service:bridge:1\">" + "<DeviceIDs>" + wemoLightID + "</DeviceIDs>" + "</u:GetDeviceStatus>" + "</s:Body>" + "</s:Envelope>"; String wemoURL = getWemoURL(); if (wemoURL != null) { String wemoCallResponse = wemoHttpCaller.executeCall(wemoURL, soapHeader, content); if (wemoCallResponse != null) { wemoCallResponse = StringEscapeUtils.unescapeXml(wemoCallResponse); String response = StringUtils.substringBetween(wemoCallResponse, "<CapabilityValue>", "</CapabilityValue>"); logger.trace("wemoNewLightState = {}", response); String[] splitResponse = response.split(","); if (splitResponse[0] != null) { OnOffType binaryState = null; binaryState = splitResponse[0].equals("0") ? OnOffType.OFF : OnOffType.ON; if (binaryState != null) { updateState(CHANNEL_STATE, binaryState); } } if (splitResponse[1] != null) { String splitBrightness[] = splitResponse[1].split(":"); if (splitBrightness[0] != null) { int newBrightnessValue = Integer.valueOf(splitBrightness[0]); int newBrightness = Math.round(newBrightnessValue * 100 / 255); logger.trace("newBrightness = {}", newBrightness); State newBrightnessState = new PercentType(newBrightness); updateState(CHANNEL_BRIGHTNESS, newBrightnessState); currentBrightness = newBrightness; } } } } } catch (Exception e) { throw new IllegalStateException("Could not retrieve new Wemo light state", e); } }