Search in sources :

Example 11 with Node

use of org.flyte.api.v1.Node in project openhab-addons by openhab.

the class HomieChildMapTests method createNode.

private Node createNode(String id) {
    Node node = new Node(deviceTopic, id, ThingChannelConstants.TEST_HOMIE_THING, callback, spy(new NodeAttributes()));
    doReturn(future).when(node.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
    doReturn(future).when(node.attributes).unsubscribe();
    return node;
}
Also used : Node(org.openhab.binding.mqtt.homie.internal.homie300.Node) NodeAttributes(org.openhab.binding.mqtt.homie.internal.homie300.NodeAttributes)

Example 12 with Node

use of org.flyte.api.v1.Node in project openhab-addons by openhab.

the class HomieThingHandlerTests method createSpyNode.

public Node createSpyNode(String propertyID, Device device) {
    // Create the node
    Node node = spy(device.createNode("node", spy(new NodeAttributes())));
    doReturn(future).when(node.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
    doReturn(future).when(node.attributes).unsubscribe();
    node.attributes.name = "testnode";
    node.attributes.properties = new String[] { "property" };
    doAnswer(this::createSubscriberAnswer).when(node.attributes).createSubscriber(any(), any(), any(), anyBoolean());
    // Intercept creating a property in the next call and inject a spy'ed property.
    doAnswer(i -> createSpyProperty("property", node)).when(node).createProperty(any());
    return node;
}
Also used : Node(org.openhab.binding.mqtt.homie.internal.homie300.Node) NodeAttributes(org.openhab.binding.mqtt.homie.internal.homie300.NodeAttributes)

Example 13 with Node

use of org.flyte.api.v1.Node in project openhab-addons by openhab.

the class HomieThingHandlerTests method handleCommandUpdate.

@SuppressWarnings("null")
@Test
public void handleCommandUpdate() {
    // Create mocked homie device tree with one node and one writable property
    Node node = thingHandler.device.createNode("node", spy(new NodeAttributes()));
    doReturn(future).when(node.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
    doReturn(future).when(node.attributes).unsubscribe();
    node.attributes.name = "testnode";
    Property property = node.createProperty("property", spy(new PropertyAttributes()));
    doReturn(future).when(property.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
    doReturn(future).when(property.attributes).unsubscribe();
    property.attributes.name = "testprop";
    property.attributes.datatype = DataTypeEnum.string_;
    property.attributes.settable = true;
    property.attributesReceived();
    node.properties.put(property.propertyID, property);
    thingHandler.device.nodes.put(node.nodeID, node);
    ChannelState channelState = requireNonNull(property.getChannelState());
    assertNotNull(channelState);
    // Pretend we called start()
    ChannelStateHelper.setConnection(channelState, connection);
    ThingHandlerHelper.setConnection(thingHandler, connection);
    StringType updateValue = new StringType("UPDATE");
    thingHandler.handleCommand(property.channelUID, updateValue);
    assertThat(property.getChannelState().getCache().getChannelState().toString(), is("UPDATE"));
    verify(connection, times(1)).publish(any(), any(), anyInt(), anyBoolean());
    // Check non writable property
    property.attributes.settable = false;
    property.attributesReceived();
    // Assign old value
    Value value = property.getChannelState().getCache();
    Command command = TypeParser.parseCommand(value.getSupportedCommandTypes(), "OLDVALUE");
    if (command != null) {
        property.getChannelState().getCache().update(command);
        // Try to update with new value
        updateValue = new StringType("SOMETHINGNEW");
        thingHandler.handleCommand(property.channelUID, updateValue);
        // Expect old value and no MQTT publish
        assertThat(property.getChannelState().getCache().getChannelState().toString(), is("OLDVALUE"));
        verify(connection, times(1)).publish(any(), any(), anyInt(), anyBoolean());
    }
}
Also used : ChannelState(org.openhab.binding.mqtt.generic.ChannelState) PropertyAttributes(org.openhab.binding.mqtt.homie.internal.homie300.PropertyAttributes) StringType(org.openhab.core.library.types.StringType) Command(org.openhab.core.types.Command) Node(org.openhab.binding.mqtt.homie.internal.homie300.Node) NodeAttributes(org.openhab.binding.mqtt.homie.internal.homie300.NodeAttributes) Value(org.openhab.binding.mqtt.generic.values.Value) Property(org.openhab.binding.mqtt.homie.internal.homie300.Property) Test(org.junit.jupiter.api.Test)

Example 14 with Node

use of org.flyte.api.v1.Node in project openhab-addons by openhab.

the class HomieImplementationTest method parseHomieTree.

@SuppressWarnings("null")
@Test
public void parseHomieTree() throws InterruptedException, ExecutionException, TimeoutException {
    // Create a Homie Device object. Because spied Nodes are required for call verification,
    // the full Device constructor need to be used and a ChildMap object need to be created manually.
    ChildMap<Node> nodeMap = new ChildMap<>();
    Device device = spy(new Device(ThingChannelConstants.testHomieThing, callback, new DeviceAttributes(), nodeMap));
    // Intercept creating a node in initialize()->start() and inject a spy'ed node.
    doAnswer(this::createSpyNode).when(device).createNode(any());
    // initialize the device, subscribe and wait.
    device.initialize(BASE_TOPIC, DEVICE_ID, Collections.emptyList());
    device.subscribe(connection, scheduler, 1500).get();
    assertThat(device.isInitialized(), is(true));
    // Check device attributes
    assertThat(device.attributes.homie, is("3.0"));
    assertThat(device.attributes.name, is("Name"));
    assertThat(device.attributes.state, is(ReadyState.ready));
    assertThat(device.attributes.nodes.length, is(1));
    verify(device, times(4)).attributeChanged(any(), any(), any(), any(), anyBoolean());
    verify(callback).readyStateChanged(eq(ReadyState.ready));
    verify(device).attributesReceived(any(), any(), anyInt());
    // Expect 1 node
    assertThat(device.nodes.size(), is(1));
    // Check node and node attributes
    Node node = device.nodes.get("testnode");
    verify(node).subscribe(any(), any(), anyInt());
    verify(node).attributesReceived(any(), any(), anyInt());
    verify(node.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
    assertThat(node.attributes.type, is("Type"));
    assertThat(node.attributes.name, is("Testnode"));
    // Expect 2 property
    assertThat(node.properties.size(), is(3));
    // Check property and property attributes
    Property property = node.properties.get("temperature");
    assertThat(property.attributes.settable, is(true));
    assertThat(property.attributes.retained, is(true));
    assertThat(property.attributes.name, is("Testprop"));
    assertThat(property.attributes.unit, is("°C"));
    assertThat(property.attributes.datatype, is(DataTypeEnum.float_));
    assertThat(property.attributes.format, is("-100:100"));
    verify(property).attributesReceived();
    assertNotNull(property.getChannelState());
    assertThat(property.getType().getState().getMinimum().intValue(), is(-100));
    assertThat(property.getType().getState().getMaximum().intValue(), is(100));
    // Check property and property attributes
    Property propertyBell = node.properties.get("doorbell");
    verify(propertyBell).attributesReceived();
    assertThat(propertyBell.attributes.settable, is(false));
    assertThat(propertyBell.attributes.retained, is(false));
    assertThat(propertyBell.attributes.name, is("Doorbell"));
    assertThat(propertyBell.attributes.datatype, is(DataTypeEnum.boolean_));
    // The device->node->property tree is ready. Now subscribe to property values.
    device.startChannels(connection, scheduler, 50, handler).get();
    assertThat(propertyBell.getChannelState().isStateful(), is(false));
    assertThat(propertyBell.getChannelState().getCache().getChannelState(), is(UnDefType.UNDEF));
    assertThat(property.getChannelState().getCache().getChannelState(), is(new DecimalType(10)));
    property = node.properties.get("testRetain");
    WaitForTopicValue watcher = new WaitForTopicValue(embeddedConnection, propertyTestTopic + "/set");
    // Watch the topic. Publish a retain=false value to MQTT
    property.getChannelState().publishValue(OnOffType.OFF).get();
    assertThat(watcher.waitForTopicValue(1000), is("false"));
    // Publish a retain=false value to MQTT.
    property.getChannelState().publishValue(OnOffType.ON).get();
    // No value is expected to be retained on this MQTT topic
    waitForAssert(() -> {
        WaitForTopicValue w = new WaitForTopicValue(embeddedConnection, propertyTestTopic + "/set");
        assertNull(w.waitForTopicValue(50));
    }, 500, 100);
}
Also used : ChildMap(org.openhab.binding.mqtt.generic.tools.ChildMap) Device(org.openhab.binding.mqtt.homie.internal.homie300.Device) WaitForTopicValue(org.openhab.binding.mqtt.generic.tools.WaitForTopicValue) Node(org.openhab.binding.mqtt.homie.internal.homie300.Node) DeviceAttributes(org.openhab.binding.mqtt.homie.internal.homie300.DeviceAttributes) DecimalType(org.openhab.core.library.types.DecimalType) Property(org.openhab.binding.mqtt.homie.internal.homie300.Property) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 15 with Node

use of org.flyte.api.v1.Node in project incubator-skywalking by apache.

the class AccessLogAnalyzer method identify.

default Role identify(StreamAccessLogsMessage.Identifier alsIdentifier, Role defaultRole) {
    if (alsIdentifier == null) {
        return defaultRole;
    }
    if (!alsIdentifier.hasNode()) {
        return defaultRole;
    }
    final Node node = alsIdentifier.getNode();
    final String id = node.getId();
    if (id.startsWith("router~")) {
        return Role.PROXY;
    } else if (id.startsWith("sidecar~")) {
        return Role.SIDECAR;
    }
    return defaultRole;
}
Also used : Node(io.envoyproxy.envoy.config.core.v3.Node)

Aggregations

Test (org.junit.jupiter.api.Test)20 Node (org.flyte.api.v1.Node)15 TaskNode (org.flyte.api.v1.TaskNode)11 WorkflowTemplate (org.flyte.api.v1.WorkflowTemplate)11 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)9 Node (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node)9 Node (org.openhab.binding.mqtt.homie.internal.homie300.Node)9 Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)9 List (java.util.List)7 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)7 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)7 NodeAttributes (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.NodeAttributes)6 BranchNode (org.flyte.api.v1.BranchNode)6 WorkflowNode (org.flyte.api.v1.WorkflowNode)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 NodeAttributes (org.openhab.binding.mqtt.homie.internal.homie300.NodeAttributes)6 Map (java.util.Map)5 Property (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Property)5 Node (dataStructure.JunkCourse.ch04.Node)4