hass-core/tests/components/bang_olufsen/conftest.py
Markus Jacobsen 1d7e0e7fe4
Add bang_olufsen integration (#93462)
* Add bangolufsen integration

* add untested files to .coveragerc

* Simplify integration to media_player platform

* Remove missing files from .coveragerc

* Add beolink_set_relative_volume custom service
Tweaks

* Remove custom services
Remove grouping as it was dependent on custom services

* Update API to 3.2.1.150.0
Reduce and optimize code with feedback from joostlek
Tweaks

* Updated testing

* Remove unused options schema

* Fix bugfix setting wrong state

* Fix wrong initial state

* Bump API

* Fix Beosound Level not reconnecting properly

* Remove unused constant

* Fix wrong variable checked to determine source

* Update integration with feedback from emontnemery

* Update integration with feedback from emontnemery

* Remove unused code

* Move API client into dataclass
Fix not all config_flow exceptions caught
Tweaks

* Add Bang & Olufsen brand

* Revert "Add Bang & Olufsen brand"

This reverts commit 57b2722078.

* Remove volume options from setup
Simplify device checks
rename integration to bang_olufsen
update tests to pass
Update API

* Remove _device from base
Add _device to websocket

* Move SW version device update to websocket
Sort websocket variables

* Add WebSocket connection test

* Remove unused constants

* Remove confirmation form
Make discovered devices get added to Home Assistant immediately
Fix device not being available on mdns discovery
Change config flow aborts to forms with error

* Update tests for new config_flow
Add missing api_exception test

* Restrict manual and discovered IP addresses to IPv4

* Re-add confirmation step for zeroconf discovery
Improve error messages
Move exception mapping dict to module level

* Enable remote control WebSocket listener

* Update tests
2024-01-24 12:00:51 +01:00

70 lines
1.6 KiB
Python

"""Test fixtures for bang_olufsen."""
from unittest.mock import AsyncMock, patch
from mozart_api.models import BeolinkPeer
import pytest
from homeassistant.components.bang_olufsen.const import DOMAIN
from .const import (
TEST_DATA_CREATE_ENTRY,
TEST_FRIENDLY_NAME,
TEST_JID_1,
TEST_NAME,
TEST_SERIAL_NUMBER,
)
from tests.common import MockConfigEntry
class MockMozartClient:
"""Class for mocking MozartClient objects and methods."""
async def __aenter__(self):
"""Mock async context entry."""
async def __aexit__(self, exc_type, exc, tb):
"""Mock async context exit."""
# API call results
get_beolink_self_result = BeolinkPeer(
friendly_name=TEST_FRIENDLY_NAME, jid=TEST_JID_1
)
# API endpoints
get_beolink_self = AsyncMock()
get_beolink_self.return_value = get_beolink_self_result
@pytest.fixture
def mock_config_entry():
"""Mock config entry."""
return MockConfigEntry(
domain=DOMAIN,
unique_id=TEST_SERIAL_NUMBER,
data=TEST_DATA_CREATE_ENTRY,
title=TEST_NAME,
)
@pytest.fixture
def mock_client():
"""Mock MozartClient."""
client = MockMozartClient()
with patch("mozart_api.mozart_client.MozartClient", return_value=client):
yield client
# Reset mocked API call counts and side effects
client.get_beolink_self.reset_mock(side_effect=True)
@pytest.fixture
def mock_setup_entry():
"""Mock successful setup entry."""
with patch(
"homeassistant.components.bang_olufsen.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry