Files
core/tests/components/blue_current/test_button.py
Nick Kuiper 4b7650f2d2 Add buttons to Blue current integration (#143964)
* Add buttons to Blue current integration

* Apply feedback

* Changed configEntry to use the BlueCurrentConfigEntry.

The connector is now accessed via the entry instead of hass.data.

* Changed test_buttons_created test to use the snapshot_platform function.

Also removed the entry.unique_id check in the test_charge_point_buttons function because this is not needed anymore, according to https://github.com/home-assistant/core/pull/114000#discussion_r1627201872

* Applied requested changes.

Changes requested by joostlek.

* Moved has_value from BlueCurrentEntity to class level.

This value was still inside the __init__ function, so the value was not overwritten by the ChargePointButton.

---------

Co-authored-by: Floris272 <florispuijk@outlook.com>
2025-05-14 19:37:16 +02:00

52 lines
1.6 KiB
Python

"""The tests for Blue Current buttons."""
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from . import init_integration
from tests.common import MockConfigEntry, snapshot_platform
charge_point_buttons = ["stop_charge_session", "reset", "reboot"]
async def test_buttons_created(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test if all buttons are created."""
await init_integration(hass, config_entry, Platform.BUTTON)
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
@pytest.mark.freeze_time("2023-01-13 12:00:00+00:00")
async def test_charge_point_buttons(
hass: HomeAssistant, config_entry: MockConfigEntry
) -> None:
"""Test the underlying charge point buttons."""
await init_integration(hass, config_entry, Platform.BUTTON)
for button in charge_point_buttons:
state = hass.states.get(f"button.101_{button}")
assert state is not None
assert state.state == STATE_UNKNOWN
await hass.services.async_call(
BUTTON_DOMAIN,
SERVICE_PRESS,
{ATTR_ENTITY_ID: f"button.101_{button}"},
blocking=True,
)
state = hass.states.get(f"button.101_{button}")
assert state
assert state.state == "2023-01-13T12:00:00+00:00"