mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Share common EntityTestHelpers in wemo tests (#62455)
This commit is contained in:
parent
c16794968f
commit
7eacabf684
@ -134,3 +134,35 @@ async def test_avaliable_after_update(
|
|||||||
pywemo_registry.callbacks[pywemo_device.name](pywemo_device, "", "")
|
pywemo_registry.callbacks[pywemo_device.name](pywemo_device, "", "")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert hass.states.get(wemo_entity.entity_id).state == STATE_ON
|
assert hass.states.get(wemo_entity.entity_id).state == STATE_ON
|
||||||
|
|
||||||
|
|
||||||
|
class EntityTestHelpers:
|
||||||
|
"""Common state update helpers."""
|
||||||
|
|
||||||
|
async def test_async_update_locked_multiple_updates(
|
||||||
|
self, hass, pywemo_device, wemo_entity
|
||||||
|
):
|
||||||
|
"""Test that two hass async_update state updates do not proceed at the same time."""
|
||||||
|
await test_async_update_locked_multiple_updates(
|
||||||
|
hass, pywemo_device, wemo_entity
|
||||||
|
)
|
||||||
|
|
||||||
|
async def test_async_update_locked_multiple_callbacks(
|
||||||
|
self, hass, pywemo_device, wemo_entity
|
||||||
|
):
|
||||||
|
"""Test that two device callback state updates do not proceed at the same time."""
|
||||||
|
await test_async_update_locked_multiple_callbacks(
|
||||||
|
hass, pywemo_device, wemo_entity
|
||||||
|
)
|
||||||
|
|
||||||
|
async def test_async_update_locked_callback_and_update(
|
||||||
|
self, hass, pywemo_device, wemo_entity
|
||||||
|
):
|
||||||
|
"""Test that a callback and a state update request can't both happen at the same time.
|
||||||
|
|
||||||
|
When a state update is received via a callback from the device at the same time
|
||||||
|
as hass is calling `async_update`, verify that only one of the updates proceeds.
|
||||||
|
"""
|
||||||
|
await test_async_update_locked_callback_and_update(
|
||||||
|
hass, pywemo_device, wemo_entity
|
||||||
|
)
|
||||||
|
@ -13,39 +13,7 @@ from homeassistant.components.wemo.binary_sensor import (
|
|||||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
|
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import entity_test_helpers
|
from .entity_test_helpers import EntityTestHelpers
|
||||||
|
|
||||||
|
|
||||||
class EntityTestHelpers:
|
|
||||||
"""Common state update helpers."""
|
|
||||||
|
|
||||||
async def test_async_update_locked_multiple_updates(
|
|
||||||
self, hass, pywemo_device, wemo_entity
|
|
||||||
):
|
|
||||||
"""Test that two hass async_update state updates do not proceed at the same time."""
|
|
||||||
await entity_test_helpers.test_async_update_locked_multiple_updates(
|
|
||||||
hass, pywemo_device, wemo_entity
|
|
||||||
)
|
|
||||||
|
|
||||||
async def test_async_update_locked_multiple_callbacks(
|
|
||||||
self, hass, pywemo_device, wemo_entity
|
|
||||||
):
|
|
||||||
"""Test that two device callback state updates do not proceed at the same time."""
|
|
||||||
await entity_test_helpers.test_async_update_locked_multiple_callbacks(
|
|
||||||
hass, pywemo_device, wemo_entity
|
|
||||||
)
|
|
||||||
|
|
||||||
async def test_async_update_locked_callback_and_update(
|
|
||||||
self, hass, pywemo_device, wemo_entity
|
|
||||||
):
|
|
||||||
"""Test that a callback and a state update request can't both happen at the same time.
|
|
||||||
|
|
||||||
When a state update is received via a callback from the device at the same time
|
|
||||||
as hass is calling `async_update`, verify that only one of the updates proceeds.
|
|
||||||
"""
|
|
||||||
await entity_test_helpers.test_async_update_locked_callback_and_update(
|
|
||||||
hass, pywemo_device, wemo_entity
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TestMotion(EntityTestHelpers):
|
class TestMotion(EntityTestHelpers):
|
||||||
|
@ -9,7 +9,7 @@ from homeassistant.components.homeassistant import (
|
|||||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE
|
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import entity_test_helpers
|
from .entity_test_helpers import EntityTestHelpers
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -33,7 +33,7 @@ def pywemo_device_fixture(pywemo_device):
|
|||||||
yield pywemo_device
|
yield pywemo_device
|
||||||
|
|
||||||
|
|
||||||
class InsightTestTemplate:
|
class InsightTestTemplate(EntityTestHelpers):
|
||||||
"""Base class for testing WeMo Insight Sensors."""
|
"""Base class for testing WeMo Insight Sensors."""
|
||||||
|
|
||||||
ENTITY_ID_SUFFIX: str
|
ENTITY_ID_SUFFIX: str
|
||||||
@ -46,39 +46,6 @@ class InsightTestTemplate:
|
|||||||
"""Select the appropriate entity for the test."""
|
"""Select the appropriate entity for the test."""
|
||||||
return cls.ENTITY_ID_SUFFIX
|
return cls.ENTITY_ID_SUFFIX
|
||||||
|
|
||||||
# Tests that are in common among wemo platforms. These test methods will be run
|
|
||||||
# in the scope of this test module. They will run using the pywemo_model from
|
|
||||||
# this test module (Insight).
|
|
||||||
async def test_async_update_locked_multiple_updates(
|
|
||||||
self, hass, pywemo_device, wemo_entity
|
|
||||||
):
|
|
||||||
"""Test that two hass async_update state updates do not proceed at the same time."""
|
|
||||||
await entity_test_helpers.test_async_update_locked_multiple_updates(
|
|
||||||
hass,
|
|
||||||
pywemo_device,
|
|
||||||
wemo_entity,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def test_async_update_locked_multiple_callbacks(
|
|
||||||
self, hass, pywemo_device, wemo_entity
|
|
||||||
):
|
|
||||||
"""Test that two device callback state updates do not proceed at the same time."""
|
|
||||||
await entity_test_helpers.test_async_update_locked_multiple_callbacks(
|
|
||||||
hass,
|
|
||||||
pywemo_device,
|
|
||||||
wemo_entity,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def test_async_update_locked_callback_and_update(
|
|
||||||
self, hass, pywemo_device, wemo_entity
|
|
||||||
):
|
|
||||||
"""Test that a callback and a state update request can't both happen at the same time."""
|
|
||||||
await entity_test_helpers.test_async_update_locked_callback_and_update(
|
|
||||||
hass,
|
|
||||||
pywemo_device,
|
|
||||||
wemo_entity,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def test_state_unavailable(self, hass, wemo_entity, pywemo_device):
|
async def test_state_unavailable(self, hass, wemo_entity, pywemo_device):
|
||||||
"""Test that there is no failure if the insight_params is not populated."""
|
"""Test that there is no failure if the insight_params is not populated."""
|
||||||
del pywemo_device.insight_params[self.INSIGHT_PARAM_NAME]
|
del pywemo_device.insight_params[self.INSIGHT_PARAM_NAME]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user