Пример #1
0
def test_init():
    test.add_node_config({
        "listen_all_events":
        True,
        "entries": [
            {
                "module": "toggle"
            },
            {
                "module": "tasmota"
            },
            {
                "device":
                "sonoff-test",
                "caption":
                "SonoffTest",
                "device_type":
                "tasmota",
                "tasmota_id":
                "XXXXXX",
                "events_listen": [
                    "*.output", ".input", ".connected", ".temperature",
                    ".humidity", ".clock"
                ]
            },
        ],
    })
def test_init():
    test.add_node_config({
        "entries": [
            {
                "module": "location_owntracks"
            },
            {
                "caption": "Device",
                "device": "test",
                "owntracks_id": "xxx",
                "events_listen": [".location", ".clock"],
            },
        ]
    })
Пример #3
0
def test_init():
  test.add_node_config({
    "listen_all_events": True,
    "entries": [
      { "module": "scripting" },
      {
        "caption": "Device",
        "device": "test",
        "...": "...",
      },
    ]
  })
      
  # ADVANCED: test a topic is publish during node initialization (before test_run)
  test.assertx('init', assertSubscribe = { 'device/toggle/get': '' }, wait = False)
Пример #4
0
def test_init():
    test.add_node_config({
        "listen_all_events":
        True,
        "entries": [{
            "module":
            "scheduler",
            "config": {
                "scheduler_enabled": True,
            },
            "jobs": [{
                "run_cron": "*/10 * * * *",
                "do": "item1.action(params['value']='1')"
            }],
            'run_interval':
            1,
            'publish': {
                '@/status': {
                    'run_interval': 1,
                }
            },
        }, {
            "item":
            "item1",
            "subscribe": {
                "@/action": {
                    "type": "string",
                    'response': [],
                    "actions": {
                        "action": "js:params['value']",
                    }
                }
            },
            "schedule": [{
                "id": "testsched",
                "run_interval": "1d",
                "do": ".action(params['value']='2')"
            }],
            "schedule_groups": {
                "groupname": [{
                    "run_cron": "0 0 */7 * *",
                    "do": ".action(params['value']='3')"
                }]
            },
        }]
    })

    system.time_set(1577833200)  # 2020-01-01 00:00:00
Пример #5
0
def test_init():
    test.add_node_config({
        "entries": [
            {
                "module": "toggle"
            },
            {
                "module": "shelly"
            },
            {
                "device":
                "shelly-test",
                "device_type":
                "shelly2",
                "shelly_id":
                "XXXXXX",
                "events_listen": [
                    ".output", ".input", ".connected", ".temperature",
                    ".humidity", ".energy", ".clock"
                ],
                "events": {
                    "energy:group": 0
                },  # Disable event grouping for simple testing
            },
            {
                "caption": "Toggle test",
                "item": "toggle-test",
                "entry_topic": "home/toggle-test",
                "toggle_devices": "shelly-test",
            },
            {
                "device":
                "shellydimmer-test",
                "device_type":
                "shellydimmer",
                "shelly_id":
                "YYYYYY",
                "events_listen": [
                    ".output", ".input", ".connected", ".temperature",
                    ".humidity", ".energy", ".clock"
                ],
                "events": {
                    "energy:group": 0
                },  # Disable event grouping for simple testing
            },
        ],
    })
Пример #6
0
def test_init():
  test.add_node_config({
    "entries": [
      { 
        "module": "presence",
        "config": {
          "presence_home_location": { "latitude": 45.123, "longitude": 12.123, "radius": 500 },
          "presence_home_regions": [ "home", "Region" ],
          "presence_location_session_duration": 30,
          "presence_connection_after_disconnect": 0,
        },
        "publish": {
          './presence': {
            'run_interval': 2,
          }
        },
        "events_listen": [".presence-out", ".presence-in", "*.clock"],
      },
      {
        "module": "net_sniffer_scapy",
        "config": {
          "momentary_flood_time": 30,
          "connection_time": 30,
        }
      },
      { "module": "location_owntracks" },

      {
        "caption": "Device1",
        "device": "device1",
        "mac_address": "01:02:03:04:05",
        "owntracks_id": "xxx",
        "presence_detect": "mary",
      },
      {
        "caption": "Device2",
        "device": "device2",
        "mac_address": "0A:0B:0C:0D:0E",
        "presence_detect": "john",
      },
    ]
  }) 
Пример #7
0
def test_init():
  test.add_node_config({
    "entries": [
      {
        "module": "rf_listener",
        "config": {
          "rf_listener_gpio": -1, # To disable GPIO initialization during tests
        },
        "events_listen": ["*.connected", "*.input"],
      },
      {
        "caption": "RF Device #1",
        "device": "test-rf-1",
        "rf_code": "1234567",
      },
      {
        "caption": "RF Device #2",
        "device": "test-rf-2",
        "rf_code": {"1234568": "port1", "1234569": "port2"},
      },
    ],
  })
Пример #8
0
def test_init():
    test.add_node_config({
        "entries": [
            {
                "module": "rf2mqtt_listener",
                "events_listen": ["*.connected", "*.input"],
            },
            {
                "caption": "RF Device #1",
                "device": "test-rf-1",
                "rf_code": "1234567",
            },
            {
                "caption": "RF Device #2",
                "device": "test-rf-2",
                "rf_code": {
                    "1234568": "port1",
                    "1234569": "port2"
                },
            },
        ],
    })
def test_init():
    test.add_node_config({
        "entries": [
            {
                "module": "net_sniffer_iw",
                "config": {
                    "momentary_flood_time": 30,
                    "connection_time": 5,
                },
                "events_listen": ["*.connected"],
            },
            {
                "caption": "Device1",
                "device": "device1",
                "mac_address": "01:02:03:04:05:06",
            },
            {
                "caption": "Device2",
                "device": "device2",
                "mac_address": "0A:0B:0C:0D:0E:0F",
                "net_connection_momentary": True,
            },
        ]
    })
Пример #10
0
def test_init():
    test.add_node_config({
        #"listen_all_events": True,
        "entries": [
            {
                "module": "toggle"
            },
            {
                "module": "scripting"
            },
            {
                "device": "test-toggle-device",
                "data": {
                    "status": 0
                },
                "publish": {
                    "device/toggle-status": {
                        "type": "object",
                        "events": {
                            "output":
                            "js:({value: payload['value'] == 'on' ? 1 : 0})",
                            "clock": "js:({value: payload['time']})",
                        }
                    }
                },
                "subscribe": {
                    "device/toggle": {
                        "script": ["status = 1 if payload == 'on' else 0"],
                        "response": ["device/toggle-status"],
                        "publish": ["device/toggle-status"],
                        "actions": {
                            "output-set": "js:params['value'] ? 'on' : 'off'"
                        }
                    },
                    "device/toggle/get": {
                        "response": ["device/toggle-status"],
                        "publish": ["device/toggle-status"],
                        "actions": {
                            "output-get": ""
                        }
                    },
                },
            },
            {
                "item": "test-toggle",
                "caption": "Test toggle",
                "toggle_devices": "test-toggle-device",
                "toggle_detached": False,
                "config": {
                    "toggle_defaults": {
                        "timer-to-1": 10,
                    }
                },
                "events_listen": [".output"],
            },
            {
                "device": "test-toggle-device2",
                "data": {
                    "status": 0
                },
                "publish": {
                    "/^device2/toggle-status([0-9]+)$/": {
                        "type": "object",
                        "events": {
                            "output":
                            'js:({value: payload == "ON" ? 1 : 0, port: matches[1] ? matches[1] : "0"})',
                        }
                    }
                },
                'subscribe': {
                    '/^device2/toggle([0-9]*)$/': {
                        'type': ['ON', 'OFF'],
                        'actions': {
                            'output-set': {
                                'topic':
                                'js:"device2/toggle" + ("port" in params && params["port"] != "0" ? params["port"] : "")',
                                'payload': 'js:params["value"] ? "ON" : "OFF"'
                            },
                        }
                    }
                }
            },
            {
                "item": "test-toggle2",
                "caption": "Test toggle 2",
                "toggle_devices": "test-toggle-device2(params['port'] == '9')",
                "events_listen": [".output"],
            },
            {
                "device": "test-toggle-device3",
                "publish": {
                    "device3/toggle-status": {
                        "type": "object",
                        "events": {
                            "output":
                            "js:({value: payload['value'] == 'on' ? 1 : 0})",
                        }
                    }
                },
                "subscribe": {
                    "device3/toggle": {
                        "response": ["device3/toggle-status"],
                        "actions": {
                            "output-set": "js:params['value'] ? 'on' : 'off'"
                        }
                    },
                },
            },
            {
                "item": "test-toggle3",
                "caption": "Test toggle",
                "toggle_devices": "test-toggle-device3",
            },
        ],
    })

    # Check that during the init phase, the device status is requested (because it supports the "output-get" action)
    test.assertx('init', assertSubscribe={'device/toggle/get': ''}, wait=False)
Пример #11
0
def test_init():
    config = {
        "entries": [
            {
                "item": "entry_a",
                "on": {
                    "entry_b.test_event": {
                        "handler": on_test_on_event1,
                    },
                    "entry_b.test_event(params['port'] == '1')": {
                        "handler": on_test_on_event2,
                    },
                    "entry_b.test_do": {
                        "do":
                        "entry_b.test_do_action(js:params['value'] = params['value'] + 1)",
                    },
                    ".test_event(js:params['port'] == 'entry_a')": {
                        "handler": on_test_on_event_implicit,
                    }
                },
                "publish": {
                    "@/event": {
                        "type": None,
                        "events": {
                            "test_event": "js:({ port: 'entry_a' })"
                        }
                    }
                },
                "events_passthrough": "entry_b.test_action_response",
            },
            {
                "caption": "Entry B",
                "device": "entry_b",
                "entry_topic": "entry_b",
                "events_listen": [".test_action_call"],
                "publish": {
                    "@/pub1": {
                        "type": "int",
                        "notify": "{caption} published pub1={payload}",
                        "events": {
                            "test_event": "js:({ port: payload + '1' })",
                        }
                    },
                    "@/pub2": {
                        "type": "int",
                        "payload_transform":
                        "jsf: payload['x'] = payload['x'] + 'transformed'; return payload",
                        "notify": "{caption} published pub2={payload[x]}",
                        "events": {
                            "test_event": "js:({ port: payload['x'] + '1' })",
                        }
                    },
                    "subs/entry_b/response": {
                        "description": "test response su subs/entry_b",
                        "handler": publish,
                        "events": {
                            "test_action_response": "js:({})",
                        }
                    },
                    "subs/entry_b/TEST0X": {
                        "type": "string",
                        "events": {
                            "test_action_call": "js:({value: payload})",
                        }
                    },
                    "subs/entry_b/test_do": {
                        "type": "string",
                        "events": {
                            "test_do": "js:({value: parseInt(payload)})",
                        }
                    }
                },
                "subscribe": {
                    "subs/entry_b": {
                        "type": "string",
                        "handler": on_subscribed_message,
                        "publish": ["subs/entry_b/response"],
                        "actions": {
                            "test_action":
                            "js:'test' + params['value'] + params['val2']",
                            "test_action2": {
                                'init':
                                'js:params["val2"] = "0"',
                                'topic':
                                'js:"subs/entry_b/TEST" + params ["val2"]',
                                'payload':
                                'js:"test" + params["value"] + params["val2"]'
                            },  # This is calling "subs/entry_b/0X", despite it's in "subs/entry_b"
                        }
                    },
                    "@/test_do_result": {
                        "type": "string",
                        "actions": {
                            "test_do_action": "js:params['value']",
                        }
                    },
                    "/^subs/entry_b/TEST(.*)/": {
                        "type": "string",
                        "handler": on_subscribed_message2,
                        "publish": ["subs/entry_b/response"],
                    }
                },
                "on": {
                    # Generated by entry_a via events_passthrough
                    "entry_a.test_action_response": {
                        "handler": on_test_on_events_passthrough,
                    }
                }
            },

            ####################################################################################
            ### TEST event_get cache e event_keys
            {
                "item": "entry_c",
                "events_listen": [".data"],
                "publish": {
                    "./event": {
                        "type": "object",
                        "events": {
                            "data": "js:(payload)"
                        }
                    }
                },
                "subscribe": {
                    "./action": {
                        "type": "object",
                        "actions": {
                            "data-set": "js:params"
                        }
                    }
                }
            },
            {
                "item": "entry_d",
                "events_listen": [".data"],
                "event_keys": ["myport"],
                "publish": {
                    "./event": {
                        "type": "object",
                        "events": {
                            "data": "js:(payload)"
                        }
                    }
                },
                "subscribe": {
                    "./action": {
                        "type": "object",
                        "actions": {
                            "data-set": "js:params"
                        }
                    }
                }
            },

            ####################################################################################
            ### TEST multiple events / event:init / event groups
            {
                "item": "entry_e",
                "events_listen": [".data"],
                "publish": {
                    "./event": {
                        "type": "object",
                        "events": {
                            "data":
                            ["js:(payload)", "js:({'port': '1', 'value': 1})"],
                            "data:init": [{
                                "all": 1
                            }, {
                                "port": "1",
                                "unit": "A"
                            }, {
                                "port": "2",
                                "unit": "B"
                            }],
                        }
                    },
                    "./group": {
                        "type": "object",
                        "events": {
                            "egroup": ["js:(payload)"],
                        }
                    }
                },
                "events": {
                    "egroup:group": 60
                },
                "on": {
                    ".egroup": {
                        "handler": on_test_on_entry_e_group,
                    },
                }
            },
        ]
    }
    if test_history:
        config["entries"].append({"module": "history"})
    test.add_node_config(config)
Пример #12
0
def test_init():
    test.add_node_config({
        "entries": [
            {
                "module": "health",
                "config": {
                    'health-dead-disconnected-timeout': '1s',
                    'health-alive-on-message': True,
                    'health-check_interval-multiplier': 1.5,
                    'health-checker-secs': .1,
                },
                "publish": {
                    "health/status": {
                        "run_interval": 1,
                    }
                }
            },
            {
                "device": "test-device",
                "publish": {
                    "@/lwt": {
                        "type": ["online", "offline"],
                        "events": {
                            "connected": "js:({ value: payload == 'online' })",
                        }
                    },
                    "@/check": {
                        "type": None,
                        "check_interval": "60",
                    },
                    '@/#': {}  # catchall rule
                },
                "subscribe": {
                    "@/sub1": {
                        "response": ["@/sub1-res"]
                    },
                    "@/sub2": {
                        "response": [{
                            "topic": "@/sub2-resa",
                            "count": 2
                        }, "@/sub2-resb"]
                    },
                    "/^device/test-device/sub3(.*)$/": {
                        "response": ["@/sub3{matches[1]}-res"]
                    },
                }
            },
            {
                "item": "test-item",
                "required": ["test-device"],
            },
            {
                "item": "test-item2",
                "config": {
                    "health-dead-message-timeout": "2s",
                },
                "publish": {
                    "@/check": {
                        "type": None,
                    }
                }
            },
        ],
    })