async def test_setup_entry_fails(hass):
    """Test setup entry fails if deCONZ is not available."""
    entry = Mock()
    entry.data = {
        deconz.config_flow.CONF_HOST: ENTRY1_HOST,
        deconz.config_flow.CONF_PORT: ENTRY1_PORT,
        deconz.config_flow.CONF_API_KEY: ENTRY1_API_KEY,
    }
    with patch("pydeconz.DeconzSession.initialize", side_effect=Exception):
        await deconz.async_setup_entry(hass, entry)
async def test_setup_entry_no_available_bridge(hass):
    """Test setup entry fails if deCONZ is not available."""
    entry = Mock()
    entry.data = {
        deconz.config_flow.CONF_HOST: ENTRY1_HOST,
        deconz.config_flow.CONF_PORT: ENTRY1_PORT,
        deconz.config_flow.CONF_API_KEY: ENTRY1_API_KEY,
    }
    with patch("pydeconz.DeconzSession.initialize",
               side_effect=asyncio.TimeoutError), pytest.raises(
                   ConfigEntryNotReady):
        await deconz.async_setup_entry(hass, entry)
Exemple #3
0
async def test_shutdown():
    """Successful shutdown."""
    hass = Mock()
    entry = Mock()
    entry.data = ENTRY_CONFIG

    axis_device = axis.device.AxisNetworkDevice(hass, entry)
    axis_device.api = Mock()

    axis_device.shutdown(None)

    assert len(axis_device.api.stop.mock_calls) == 1
Exemple #4
0
async def test_hap_setup_connection_error():
    """Test a failed accesspoint setup."""
    hass = Mock()
    entry = Mock()
    entry.data = {HMIPC_HAPID: "ABC123", HMIPC_AUTHTOKEN: "123", HMIPC_NAME: "hmip"}
    hap = HomematicipHAP(hass, entry)
    with patch.object(hap, "get_hap", side_effect=HmipcConnectionError), pytest.raises(
        ConfigEntryNotReady
    ):
        await hap.async_setup()

    assert not hass.async_add_job.mock_calls
    assert not hass.config_entries.flow.async_init.mock_calls
Exemple #5
0
async def test_new_event_sends_signal(hass):
    """Make sure that new event send signal."""
    entry = Mock()
    entry.data = ENTRY_CONFIG

    axis_device = axis.device.AxisNetworkDevice(hass, entry)

    with patch.object(axis.device,
                      "async_dispatcher_send") as mock_dispatch_send:
        axis_device.async_event_callback(action="add", event_id="event")
        await hass.async_block_till_done()

    assert len(mock_dispatch_send.mock_calls) == 1
    assert len(mock_dispatch_send.mock_calls[0]) == 3
Exemple #6
0
 def _factory(device_id,
              event_type="DEVICE_EVENT",
              capability='',
              attribute='Updated',
              value='Value',
              data=None):
     event = Mock()
     event.event_type = event_type
     event.device_id = device_id
     event.component_id = 'main'
     event.capability = capability
     event.attribute = attribute
     event.value = value
     event.data = data
     event.location_id = str(uuid4())
     return event
Exemple #7
0
 def _factory(
     device_id,
     event_type="DEVICE_EVENT",
     capability="",
     attribute="Updated",
     value="Value",
     data=None,
 ):
     event = Mock()
     event.event_type = event_type
     event.device_id = device_id
     event.component_id = "main"
     event.capability = capability
     event.attribute = attribute
     event.value = value
     event.data = data
     event.location_id = str(uuid4())
     return event
Exemple #8
0
async def test_hap_setup_works():
    """Test a successful setup of a accesspoint."""
    hass = Mock()
    entry = Mock()
    home = Mock()
    entry.data = {HMIPC_HAPID: "ABC123", HMIPC_AUTHTOKEN: "123", HMIPC_NAME: "hmip"}
    hap = HomematicipHAP(hass, entry)
    with patch.object(hap, "get_hap", return_value=home):
        assert await hap.async_setup()

    assert hap.home is home
    assert len(hass.config_entries.async_forward_entry_setup.mock_calls) == 8
    assert hass.config_entries.async_forward_entry_setup.mock_calls[0][1] == (
        entry,
        "alarm_control_panel",
    )
    assert hass.config_entries.async_forward_entry_setup.mock_calls[1][1] == (
        entry,
        "binary_sensor",
    )
Exemple #9
0
async def test_smartapp_update_saves_token(hass, smartthings_mock, location,
                                           device_factory):
    """Test update saves token."""
    # Arrange
    entry = Mock()
    entry.data = {'installed_app_id': str(uuid4()), 'app_id': str(uuid4())}
    entry.domain = DOMAIN

    setattr(hass.config_entries, '_entries', [entry])
    app = Mock()
    app.app_id = entry.data['app_id']
    request = Mock()
    request.installed_app_id = entry.data['installed_app_id']
    request.auth_token = str(uuid4())
    request.refresh_token = str(uuid4())
    request.location_id = location.location_id

    # Act
    await smartapp.smartapp_update(hass, request, None, app)
    # Assert
    assert entry.data[CONF_REFRESH_TOKEN] == request.refresh_token
Exemple #10
0
async def test_hap_reset_unloads_entry_if_setup():
    """Test calling reset while the entry has been setup."""
    hass = Mock()
    entry = Mock()
    home = Mock()
    home.disable_events = mock_coro_func()
    entry.data = {
        hmipc.HMIPC_HAPID: "ABC123",
        hmipc.HMIPC_AUTHTOKEN: "123",
        hmipc.HMIPC_NAME: "hmip",
    }
    hap = hmipc.HomematicipHAP(hass, entry)
    with patch.object(hap, "get_hap", return_value=mock_coro(home)):
        assert await hap.async_setup()

    assert hap.home is home
    assert not hass.services.async_register.mock_calls
    assert len(hass.config_entries.async_forward_entry_setup.mock_calls) == 8

    hass.config_entries.async_forward_entry_unload.return_value = mock_coro(
        True)
    await hap.async_reset()

    assert len(hass.config_entries.async_forward_entry_unload.mock_calls) == 8