Add Button entity component platform (#57642)

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Franck Nijhof 2021-11-04 16:50:43 +01:00 committed by GitHub
parent 4c5aca93df
commit d126d88977
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 708 additions and 0 deletions

View file

@ -0,0 +1,47 @@
"""
Provide a mock button platform.
Call init before using it in your tests to ensure clean test data.
"""
import logging
from homeassistant.components.button import ButtonEntity
from tests.common import MockEntity
UNIQUE_BUTTON_1 = "unique_button_1"
ENTITIES = []
_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")
def init(empty=False):
"""Initialize the platform with entities."""
global ENTITIES
ENTITIES = (
[]
if empty
else [
MockButtonEntity(
name="button 1",
unique_id="unique_button_1",
),
]
)
async def async_setup_platform(
hass, config, async_add_entities_callback, discovery_info=None
):
"""Return mock entities."""
async_add_entities_callback(ENTITIES)