mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Use mock_platform for button entity component tests instead of hass.components (#113627)
This commit is contained in:
committed by
GitHub
parent
11c570ea7b
commit
73f11064d7
50
tests/components/button/conftest.py
Normal file
50
tests/components/button/conftest.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""Fixtures for the button entity component tests."""
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.button import DOMAIN, ButtonEntity
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from .const import TEST_DOMAIN
|
||||
|
||||
from tests.common import MockEntity, MockPlatform, mock_platform
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MockButtonEntity(MockEntity, ButtonEntity):
|
||||
"""Mock Button class."""
|
||||
|
||||
def press(self) -> None:
|
||||
"""Press the button."""
|
||||
_LOGGER.info("The button has been pressed")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def setup_platform(hass: HomeAssistant) -> None:
|
||||
"""Set up the button entity platform."""
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up test button platform."""
|
||||
async_add_entities(
|
||||
[
|
||||
MockButtonEntity(
|
||||
name="button 1",
|
||||
unique_id="unique_button_1",
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
mock_platform(
|
||||
hass,
|
||||
f"{TEST_DOMAIN}.{DOMAIN}",
|
||||
MockPlatform(async_setup_platform=async_setup_platform),
|
||||
)
|
||||
Reference in New Issue
Block a user