Exemple #1
0
async def test_alarm_create_delete(opp, config_entry, config, soco,
                                   alarm_clock, alarm_clock_extended,
                                   alarm_event):
    """Test for correct creation and deletion of alarms during runtime."""
    soco.alarmClock = alarm_clock_extended

    await setup_platform(opp, config_entry, config)

    subscription = alarm_clock_extended.subscribe.return_value
    sub_callback = subscription.callback

    sub_callback(event=alarm_event)
    await opp.async_block_till_done()

    entity_registry = async_get_entity_registry(opp)

    assert "switch.sonos_alarm_14" in entity_registry.entities
    assert "switch.sonos_alarm_15" in entity_registry.entities

    alarm_clock_extended.ListAlarms.return_value = alarm_clock.ListAlarms.return_value
    alarm_event.increment_variable("alarm_list_version")

    sub_callback(event=alarm_event)
    await opp.async_block_till_done()

    assert "switch.sonos_alarm_14" in entity_registry.entities
    assert "switch.sonos_alarm_15" not in entity_registry.entities
Exemple #2
0
async def test_setup_partial_config_v31x(opp, mock_remote):
    """Test the setup with a v3.1.x server."""
    config = {"platform": "uvc", "nvr": "foo", "key": "secret"}
    mock_remote.return_value.server_version = (3, 1, 3)

    assert await async_setup_component(opp, "camera", {"camera": config})
    await opp.async_block_till_done()

    assert mock_remote.call_count == 1
    assert mock_remote.call_args == call("foo", 7080, "secret", ssl=False)

    camera_states = opp.states.async_all("camera")

    assert len(camera_states) == 2

    state = opp.states.get("camera.front")

    assert state
    assert state.name == "Front"

    state = opp.states.get("camera.back")

    assert state
    assert state.name == "Back"

    entity_registry = async_get_entity_registry(opp)
    entity_entry = entity_registry.async_get("camera.front")

    assert entity_entry.unique_id == "one"

    entity_entry = entity_registry.async_get("camera.back")

    assert entity_entry.unique_id == "two"
Exemple #3
0
async def test_setup_full_config(opp, mock_remote, camera_info):
    """Test the setup with full configuration."""
    config = {
        "platform": "uvc",
        "nvr": "foo",
        "password": "******",
        "port": 123,
        "key": "secret",
    }

    def mock_get_camera(uuid):
        """Create a mock camera."""
        if uuid == "id3":
            camera_info["model"] = "airCam"

        return camera_info

    mock_remote.return_value.index.return_value.append({
        "uuid": "three",
        "name": "Old AirCam",
        "id": "id3"
    })
    mock_remote.return_value.get_camera.side_effect = mock_get_camera

    assert await async_setup_component(opp, "camera", {"camera": config})
    await opp.async_block_till_done()

    assert mock_remote.call_count == 1
    assert mock_remote.call_args == call("foo", 123, "secret", ssl=False)

    camera_states = opp.states.async_all("camera")

    assert len(camera_states) == 2

    state = opp.states.get("camera.front")

    assert state
    assert state.name == "Front"

    state = opp.states.get("camera.back")

    assert state
    assert state.name == "Back"

    entity_registry = async_get_entity_registry(opp)
    entity_entry = entity_registry.async_get("camera.front")

    assert entity_entry.unique_id == "id1"

    entity_entry = entity_registry.async_get("camera.back")

    assert entity_entry.unique_id == "id2"
Exemple #4
0
 async def set_unique_id(self):
     """Set unique id for projector config entry."""
     _LOGGER.debug("Setting unique_id for projector")
     if self._unique_id:
         return False
     uid = await self._projector.get_serial_number()
     if uid:
         self.opp.config_entries.async_update_entry(self._entry,
                                                    unique_id=uid)
         registry = async_get_entity_registry(self.opp)
         old_entity_id = registry.async_get_entity_id(
             "media_player", DOMAIN, self._entry.entry_id)
         if old_entity_id is not None:
             registry.async_update_entity(old_entity_id, new_unique_id=uid)
         self.opp.async_create_task(
             self.opp.config_entries.async_reload(self._entry.entry_id))
         return True