mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Full test coverage for Vodafone Station button platform (#133281)
This commit is contained in:
parent
b77e42e8f3
commit
5cc8d9e105
@ -29,11 +29,13 @@ DEVICE_DATA_QUERY = {
|
|||||||
mac="xx:xx:xx:xx:xx:xx",
|
mac="xx:xx:xx:xx:xx:xx",
|
||||||
type="laptop",
|
type="laptop",
|
||||||
wifi="2.4G",
|
wifi="2.4G",
|
||||||
)
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SERIAL = "m123456789"
|
||||||
|
|
||||||
SENSOR_DATA_QUERY = {
|
SENSOR_DATA_QUERY = {
|
||||||
"sys_serial_number": "M123456789",
|
"sys_serial_number": SERIAL,
|
||||||
"sys_firmware_version": "XF6_4.0.05.04",
|
"sys_firmware_version": "XF6_4.0.05.04",
|
||||||
"sys_bootloader_version": "0220",
|
"sys_bootloader_version": "0220",
|
||||||
"sys_hardware_version": "RHG3006 v1",
|
"sys_hardware_version": "RHG3006 v1",
|
||||||
|
56
tests/components/vodafone_station/test_button.py
Normal file
56
tests/components/vodafone_station/test_button.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
"""Tests for Vodafone Station button platform."""
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
|
||||||
|
from homeassistant.components.vodafone_station.const import DOMAIN
|
||||||
|
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||||
|
|
||||||
|
from .const import DEVICE_DATA_QUERY, MOCK_USER_DATA, SENSOR_DATA_QUERY, SERIAL
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
async def test_button(hass: HomeAssistant, entity_registry: EntityRegistry) -> None:
|
||||||
|
"""Test device restart button."""
|
||||||
|
|
||||||
|
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_DATA)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch("aiovodafone.api.VodafoneStationSercommApi.login"),
|
||||||
|
patch(
|
||||||
|
"aiovodafone.api.VodafoneStationSercommApi.get_devices_data",
|
||||||
|
return_value=DEVICE_DATA_QUERY,
|
||||||
|
),
|
||||||
|
patch(
|
||||||
|
"aiovodafone.api.VodafoneStationSercommApi.get_sensor_data",
|
||||||
|
return_value=SENSOR_DATA_QUERY,
|
||||||
|
),
|
||||||
|
patch(
|
||||||
|
"aiovodafone.api.VodafoneStationSercommApi.restart_router",
|
||||||
|
) as mock_router_restart,
|
||||||
|
):
|
||||||
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
entity_id = f"button.vodafone_station_{SERIAL}_restart"
|
||||||
|
|
||||||
|
# restart button
|
||||||
|
state = hass.states.get(entity_id)
|
||||||
|
assert state
|
||||||
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
|
entry = entity_registry.async_get(entity_id)
|
||||||
|
assert entry
|
||||||
|
assert entry.unique_id == f"{SERIAL}_reboot"
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
BUTTON_DOMAIN,
|
||||||
|
SERVICE_PRESS,
|
||||||
|
{ATTR_ENTITY_ID: entity_id},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert mock_router_restart.call_count == 1
|
Loading…
x
Reference in New Issue
Block a user