Пример #1
0
 def test_area_commands(self, spcwebgw, url_command, command):
     """Test alarm arming/disarming."""
     with mock_aiohttp_client() as aioclient_mock:
         url = "http://localhost/spc/area/1/{}".format(url_command)
         aioclient_mock.put(url, text='{}')
         yield from spcwebgw.send_area_command('1', command)
         assert aioclient_mock.call_count == 1
Пример #2
0
def aioclient_mock():
    """HTTP client mock for areas and zones."""
    areas = """{"status":"success","data":{"area":[{"id":"1","name":"House",
    "mode":"0","last_set_time":"1485759851","last_set_user_id":"1",
    "last_set_user_name":"Pelle","last_unset_time":"1485800564",
    "last_unset_user_id":"1","last_unset_user_name":"Pelle","last_alarm":
    "1478174896"},{"id":"3","name":"Garage","mode":"0","last_set_time":
    "1483705803","last_set_user_id":"9998","last_set_user_name":"Lisa",
    "last_unset_time":"1483705808","last_unset_user_id":"9998",
    "last_unset_user_name":"Lisa"}]}}"""

    zones = """{"status":"success","data":{"zone":[{"id":"1","type":"3",
    "zone_name":"Kitchen smoke","area":"1","area_name":"House","input":"0",
    "logic_input":"0","status":"0","proc_state":"0","inhibit_allowed":"1",
    "isolate_allowed":"1"},{"id":"3","type":"0","zone_name":"Hallway PIR",
    "area":"1","area_name":"House","input":"0","logic_input":"0","status":
    "0","proc_state":"0","inhibit_allowed":"1","isolate_allowed":"1"},
    {"id":"5","type":"1","zone_name":"Front door","area":"1","area_name":
    "House","input":"1","logic_input":"0","status":"0","proc_state":"0",
    "inhibit_allowed":"1","isolate_allowed":"1"}]}}"""

    with mock_aiohttp_client() as mock_session:
        mock_session.get('http://localhost/spc/area', text=areas)
        mock_session.get('http://localhost/spc/zone', text=zones)
        yield mock_session
Пример #3
0
def aioclient_mock():
    """HTTP client mock for areas and zones."""
    areas = """{"status":"success","data":{"area":[{"id":"1","name":"House",
    "mode":"0","last_set_time":"1485759851","last_set_user_id":"1",
    "last_set_user_name":"Pelle","last_unset_time":"1485800564",
    "last_unset_user_id":"1","last_unset_user_name":"Pelle","last_alarm":
    "1478174896"},{"id":"3","name":"Garage","mode":"0","last_set_time":
    "1483705803","last_set_user_id":"9998","last_set_user_name":"Lisa",
    "last_unset_time":"1483705808","last_unset_user_id":"9998",
    "last_unset_user_name":"Lisa"}]}}"""

    zones = """{"status":"success","data":{"zone":[{"id":"1","type":"3",
    "zone_name":"Kitchen smoke","area":"1","area_name":"House","input":"0",
    "logic_input":"0","status":"0","proc_state":"0","inhibit_allowed":"1",
    "isolate_allowed":"1"},{"id":"3","type":"0","zone_name":"Hallway PIR",
    "area":"1","area_name":"House","input":"0","logic_input":"0","status":
    "0","proc_state":"0","inhibit_allowed":"1","isolate_allowed":"1"},
    {"id":"5","type":"1","zone_name":"Front door","area":"1","area_name":
    "House","input":"1","logic_input":"0","status":"0","proc_state":"0",
    "inhibit_allowed":"1","isolate_allowed":"1"}]}}"""

    with mock_aiohttp_client() as mock_session:
        mock_session.get('http://localhost/spc/area', text=areas)
        mock_session.get('http://localhost/spc/zone', text=zones)
        yield mock_session
Пример #4
0
 def test_area_commands(self, spcwebgw, url_command, command):
     """Test alarm arming/disarming."""
     with mock_aiohttp_client() as aioclient_mock:
         url = "http://localhost/spc/area/1/{}".format(url_command)
         aioclient_mock.put(url, text='{}')
         yield from spcwebgw.send_area_command('1', command)
         assert aioclient_mock.call_count == 1
Пример #5
0
async def async_init_integration(
    hass: HomeAssistant,
    skip_setup: bool = False,
) -> MockConfigEntry:
    """Set up the nexia integration in Home Assistant."""

    house_fixture = "nexia/mobile_houses_123456.json"
    session_fixture = "nexia/session_123456.json"
    sign_in_fixture = "nexia/sign_in.json"
    with mock_aiohttp_client() as mock_session, patch(
            "nexia.home.load_or_create_uuid", return_value=uuid.uuid4()):
        nexia = NexiaHome(mock_session)
        mock_session.post(nexia.API_MOBILE_SESSION_URL,
                          text=load_fixture(session_fixture))
        mock_session.get(
            nexia.API_MOBILE_HOUSES_URL.format(house_id=123456),
            text=load_fixture(house_fixture),
        )
        mock_session.post(
            nexia.API_MOBILE_ACCOUNTS_SIGN_IN_URL,
            text=load_fixture(sign_in_fixture),
        )
        entry = MockConfigEntry(domain=DOMAIN,
                                data={
                                    CONF_USERNAME: "******",
                                    CONF_PASSWORD: "******"
                                })
        entry.add_to_hass(hass)

        if not skip_setup:
            await hass.config_entries.async_setup(entry.entry_id)
            await hass.async_block_till_done()

    return entry
Пример #6
0
def aioclient_mock():
    """HTTP client listen and devices."""
    devices = """[
        {"id":"@000001","name":"Switch 1","type":"rel","val":"OFF",
        "time":"1522777506","rssi":"51%"},
        {"id":"@000002","name":"Light 2","type":"rel","val":"ON",
        "time":"1522777507","rssi":"45%"},
        {"id":"@000003","name":"Dim 3","type":"dim","val":"280c00",
        "time":"1522777544","rssi":"62%"}]"""

    with mock_aiohttp_client() as mock_session:
        mock_session.get("http://127.0.0.1:2020/&listen", content=LISTEN)
        mock_session.get("http://127.0.0.1:2020/&device", text=devices)
        yield mock_session
def aioclient_mock():
    """HTTP client listen and devices."""
    devices = """[
        {"id":"@000001","name":"Switch 1","type":"rel","val":"OFF",
        "time":"1522777506","rssi":"51%"},
        {"id":"@000002","name":"Light 2","type":"rel","val":"ON",
        "time":"1522777507","rssi":"45%"},
        {"id":"@000003","name":"Dim 3","type":"dim","val":"280c00",
        "time":"1522777544","rssi":"62%"}]"""

    with mock_aiohttp_client() as mock_session:
        mock_session.get("http://127.0.0.1:2020/&listen", content=LISTEN)
        mock_session.get("http://127.0.0.1:2020/&device", text=devices)
        yield mock_session
Пример #8
0
def aioclient_mock():
    """Fixture to mock aioclient calls."""
    with mock_aiohttp_client() as mock_session:
        yield mock_session
Пример #9
0
def aioclient_mock():
    """Fixture to mock aioclient calls."""
    with mock_aiohttp_client() as mock_session:
        yield mock_session