Skip to content

Commit

Permalink
Use real devices in button device action tests (#102717)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Oct 24, 2023
1 parent a448763 commit 4bb6787
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions tests/components/button/test_device_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,21 @@ async def test_get_actions_hidden_auxiliary(
assert actions == unordered(expected_actions)


async def test_action(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None:
async def test_action(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test for press action."""
entry = entity_registry.async_get_or_create(DOMAIN, "test", "5678")
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entry = entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
)

assert await async_setup_component(
hass,
Expand All @@ -111,7 +123,7 @@ async def test_action(hass: HomeAssistant, entity_registry: er.EntityRegistry) -
},
"action": {
"domain": DOMAIN,
"device_id": "abcdefgh",
"device_id": device_entry.id,
"entity_id": entry.id,
"type": "press",
},
Expand All @@ -131,10 +143,20 @@ async def test_action(hass: HomeAssistant, entity_registry: er.EntityRegistry) -


async def test_action_legacy(
hass: HomeAssistant, entity_registry: er.EntityRegistry
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test for press action."""
entry = entity_registry.async_get_or_create(DOMAIN, "test", "5678")
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entry = entity_registry.async_get_or_create(
DOMAIN, "test", "5678", device_id=device_entry.id
)

assert await async_setup_component(
hass,
Expand All @@ -148,7 +170,7 @@ async def test_action_legacy(
},
"action": {
"domain": DOMAIN,
"device_id": "abcdefgh",
"device_id": device_entry.id,
"entity_id": entry.entity_id,
"type": "press",
},
Expand Down

0 comments on commit 4bb6787

Please sign in to comment.