Add button platform to Teslemetry (#117227)
* Add buttons * Add buttons * Fix docstrings * Rebase entry.runtime_data * Revert testing change * Fix tests * format json * Type callable * Remove refresh * Update icons.json * Update strings.json * Update homeassistant/components/teslemetry/button.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * import Awaitable --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
04101b044b
commit
af8542ebe1
6 changed files with 502 additions and 0 deletions
53
tests/components/teslemetry/test_button.py
Normal file
53
tests/components/teslemetry/test_button.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
"""Test the Teslemetry button platform."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import assert_entities, setup_platform
|
||||
from .const import COMMAND_OK
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_button(
|
||||
hass: HomeAssistant,
|
||||
snapshot: SnapshotAssertion,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Tests that the button entities are correct."""
|
||||
|
||||
entry = await setup_platform(hass, [Platform.BUTTON])
|
||||
assert_entities(hass, entry.entry_id, entity_registry, snapshot)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("name", "func"),
|
||||
[
|
||||
("flash_lights", "flash_lights"),
|
||||
("honk_horn", "honk_horn"),
|
||||
("keyless_driving", "remote_start_drive"),
|
||||
("play_fart", "remote_boombox"),
|
||||
("homelink", "trigger_homelink"),
|
||||
],
|
||||
)
|
||||
async def test_press(hass: HomeAssistant, name: str, func: str) -> None:
|
||||
"""Test pressing the API buttons."""
|
||||
await setup_platform(hass, [Platform.BUTTON])
|
||||
|
||||
with patch(
|
||||
f"homeassistant.components.teslemetry.VehicleSpecific.{func}",
|
||||
return_value=COMMAND_OK,
|
||||
) as command:
|
||||
await hass.services.async_call(
|
||||
BUTTON_DOMAIN,
|
||||
SERVICE_PRESS,
|
||||
{ATTR_ENTITY_ID: [f"button.test_{name}"]},
|
||||
blocking=True,
|
||||
)
|
||||
command.assert_called_once()
|
Loading…
Add table
Add a link
Reference in a new issue