mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Create dataclass to mock entry setup in Broadlink tests (#50134)
This commit is contained in:
committed by
GitHub
parent
08af791d4c
commit
fca79237c3
@@ -28,10 +28,10 @@ async def test_remote_setup_works(hass):
|
||||
for device in map(get_device, REMOTE_DEVICES):
|
||||
device_registry = mock_device_registry(hass)
|
||||
entity_registry = mock_registry(hass)
|
||||
mock_api, mock_entry = await device.setup_entry(hass)
|
||||
mock_setup = await device.setup_entry(hass)
|
||||
|
||||
device_entry = device_registry.async_get_device(
|
||||
{(DOMAIN, mock_entry.unique_id)}
|
||||
{(DOMAIN, mock_setup.entry.unique_id)}
|
||||
)
|
||||
entries = async_entries_for_device(entity_registry, device_entry.id)
|
||||
remotes = {entry for entry in entries if entry.domain == REMOTE_DOMAIN}
|
||||
@@ -40,7 +40,7 @@ async def test_remote_setup_works(hass):
|
||||
remote = remotes.pop()
|
||||
assert remote.original_name == f"{device.name} Remote"
|
||||
assert hass.states.get(remote.entity_id).state == STATE_ON
|
||||
assert mock_api.auth.call_count == 1
|
||||
assert mock_setup.api.auth.call_count == 1
|
||||
|
||||
|
||||
async def test_remote_send_command(hass):
|
||||
@@ -48,10 +48,10 @@ async def test_remote_send_command(hass):
|
||||
for device in map(get_device, REMOTE_DEVICES):
|
||||
device_registry = mock_device_registry(hass)
|
||||
entity_registry = mock_registry(hass)
|
||||
mock_api, mock_entry = await device.setup_entry(hass)
|
||||
mock_setup = await device.setup_entry(hass)
|
||||
|
||||
device_entry = device_registry.async_get_device(
|
||||
{(DOMAIN, mock_entry.unique_id)}
|
||||
{(DOMAIN, mock_setup.entry.unique_id)}
|
||||
)
|
||||
entries = async_entries_for_device(entity_registry, device_entry.id)
|
||||
remotes = {entry for entry in entries if entry.domain == REMOTE_DOMAIN}
|
||||
@@ -65,9 +65,9 @@ async def test_remote_send_command(hass):
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert mock_api.send_data.call_count == 1
|
||||
assert mock_api.send_data.call_args == call(b64decode(IR_PACKET))
|
||||
assert mock_api.auth.call_count == 1
|
||||
assert mock_setup.api.send_data.call_count == 1
|
||||
assert mock_setup.api.send_data.call_args == call(b64decode(IR_PACKET))
|
||||
assert mock_setup.api.auth.call_count == 1
|
||||
|
||||
|
||||
async def test_remote_turn_off_turn_on(hass):
|
||||
@@ -75,10 +75,10 @@ async def test_remote_turn_off_turn_on(hass):
|
||||
for device in map(get_device, REMOTE_DEVICES):
|
||||
device_registry = mock_device_registry(hass)
|
||||
entity_registry = mock_registry(hass)
|
||||
mock_api, mock_entry = await device.setup_entry(hass)
|
||||
mock_setup = await device.setup_entry(hass)
|
||||
|
||||
device_entry = device_registry.async_get_device(
|
||||
{(DOMAIN, mock_entry.unique_id)}
|
||||
{(DOMAIN, mock_setup.entry.unique_id)}
|
||||
)
|
||||
entries = async_entries_for_device(entity_registry, device_entry.id)
|
||||
remotes = {entry for entry in entries if entry.domain == REMOTE_DOMAIN}
|
||||
@@ -99,7 +99,7 @@ async def test_remote_turn_off_turn_on(hass):
|
||||
{"entity_id": remote.entity_id, "command": "b64:" + IR_PACKET},
|
||||
blocking=True,
|
||||
)
|
||||
assert mock_api.send_data.call_count == 0
|
||||
assert mock_setup.api.send_data.call_count == 0
|
||||
|
||||
await hass.services.async_call(
|
||||
REMOTE_DOMAIN,
|
||||
@@ -115,6 +115,6 @@ async def test_remote_turn_off_turn_on(hass):
|
||||
{"entity_id": remote.entity_id, "command": "b64:" + IR_PACKET},
|
||||
blocking=True,
|
||||
)
|
||||
assert mock_api.send_data.call_count == 1
|
||||
assert mock_api.send_data.call_args == call(b64decode(IR_PACKET))
|
||||
assert mock_api.auth.call_count == 1
|
||||
assert mock_setup.api.send_data.call_count == 1
|
||||
assert mock_setup.api.send_data.call_args == call(b64decode(IR_PACKET))
|
||||
assert mock_setup.api.auth.call_count == 1
|
||||
|
||||
Reference in New Issue
Block a user