Fix Tessie honk button (#106518)

This commit is contained in:
Brett Adams 2023-12-28 18:00:34 +10:00 committed by Bram Kragten
parent 50acf85f48
commit 42ffb51b76
2 changed files with 17 additions and 4 deletions

View file

@ -35,7 +35,7 @@ DESCRIPTIONS: tuple[TessieButtonEntityDescription, ...] = (
TessieButtonEntityDescription( TessieButtonEntityDescription(
key="flash_lights", func=lambda: flash_lights, icon="mdi:flashlight" key="flash_lights", func=lambda: flash_lights, icon="mdi:flashlight"
), ),
TessieButtonEntityDescription(key="honk", func=honk, icon="mdi:bullhorn"), TessieButtonEntityDescription(key="honk", func=lambda: honk, icon="mdi:bullhorn"),
TessieButtonEntityDescription( TessieButtonEntityDescription(
key="trigger_homelink", func=lambda: trigger_homelink, icon="mdi:garage" key="trigger_homelink", func=lambda: trigger_homelink, icon="mdi:garage"
), ),

View file

@ -1,6 +1,8 @@
"""Test the Tessie button platform.""" """Test the Tessie button platform."""
from unittest.mock import patch from unittest.mock import patch
import pytest
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
from homeassistant.const import ATTR_ENTITY_ID from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -8,19 +10,30 @@ from homeassistant.core import HomeAssistant
from .common import setup_platform from .common import setup_platform
async def test_buttons(hass: HomeAssistant) -> None: @pytest.mark.parametrize(
("entity_id", "func"),
[
("button.test_wake", "wake"),
("button.test_flash_lights", "flash_lights"),
("button.test_honk_horn", "honk"),
("button.test_homelink", "trigger_homelink"),
("button.test_keyless_driving", "enable_keyless_driving"),
("button.test_play_fart", "boombox"),
],
)
async def test_buttons(hass: HomeAssistant, entity_id, func) -> None:
"""Tests that the button entities are correct.""" """Tests that the button entities are correct."""
await setup_platform(hass) await setup_platform(hass)
# Test wake button # Test wake button
with patch( with patch(
"homeassistant.components.tessie.button.wake", f"homeassistant.components.tessie.button.{func}",
) as mock_wake: ) as mock_wake:
await hass.services.async_call( await hass.services.async_call(
BUTTON_DOMAIN, BUTTON_DOMAIN,
SERVICE_PRESS, SERVICE_PRESS,
{ATTR_ENTITY_ID: ["button.test_wake"]}, {ATTR_ENTITY_ID: [entity_id]},
blocking=True, blocking=True,
) )
mock_wake.assert_called_once() mock_wake.assert_called_once()