How to use the fauxmo.plugins.homeassistantplugin.HomeAssistantPlugin function in fauxmo

To help you get started, we’ve selected a few fauxmo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github n8henrie / fauxmo / tests / test_homeassistantplugin.py View on Github external
req = mock.call_args[0][0]
        assert req.full_url == (
            f"http://localhost:8123/api/services/{device.domain}/{signal}"
        )
        assert (
            req.data.decode()
            == f'{{"entity_id": "{device_conf["entity_id"]}"}}'
        )
        assert req.headers == {
            "Authorization": "Bearer abc123",
            "Content-type": "application/json",
        }
        assert int(req.host.rsplit(":")[-1]) == plugin_vars["ha_port"]
        assert req.get_method() == "POST"

        signal = HomeAssistantPlugin.service_map[device.domain.lower()]["off"]
        assert device.off() is True
        req = mock.call_args[0][0]
        assert req.full_url == (
            f"http://localhost:8123/api/services/{device.domain}/{signal}"
        )
        assert (
            req.data.decode()
            == f'{{"entity_id": "{device_conf["entity_id"]}"}}'
        )
        assert req.headers == {
            "Authorization": "Bearer abc123",
            "Content-type": "application/json",
        }
        assert int(req.host.rsplit(":")[-1]) == plugin_vars["ha_port"]
        assert req.get_method() == "POST"
github n8henrie / fauxmo / tests / test_homeassistantplugin.py View on Github external
"""Ensure a reasonable HomeAssistant REST endpoint is called."""
    with open(config_path_str) as f:
        config = json.load(f)

    response = MagicMock(spec=HTTPResponse)
    response.status = 200
    response.read.return_value = b'{"state": "off"}'
    mock.return_value.__enter__.return_value = response

    plugin_vars = {
        k: v
        for k, v in config["PLUGINS"]["HomeAssistantPlugin"].items()
        if k not in {"DEVICES", "path"}
    }
    for device_conf in config["PLUGINS"]["HomeAssistantPlugin"]["DEVICES"]:
        device = HomeAssistantPlugin(**{**plugin_vars, **device_conf})

        signal = HomeAssistantPlugin.service_map[device.domain.lower()]["on"]
        assert device.on() is True
        req = mock.call_args[0][0]
        assert req.full_url == (
            f"http://localhost:8123/api/services/{device.domain}/{signal}"
        )
        assert (
            req.data.decode()
            == f'{{"entity_id": "{device_conf["entity_id"]}"}}'
        )
        assert req.headers == {
            "Authorization": "Bearer abc123",
            "Content-type": "application/json",
        }
        assert int(req.host.rsplit(":")[-1]) == plugin_vars["ha_port"]