Fixing tplink issues with offline devices during setup (#23668)
* Fixing tplink issues with offline devices during setup. * Fixing circleci errors. * Adding code to defer the creation of entities that are not online. * Addressing code review changes and cleaning up a little. * Fixing tests and static analysis. * Adding test to satisfy coverage requirements. * Resolving merge conflicts. * Fixing issue where lights don't appear in the integration page. * Using pyHS100 properties for most sysinfo. Addressing some PR feedback. * Addressing some PR feedback. * Better testing async_add_entities_retry Testing for static dimmers. Making greater use of conf constants. * Fixing all static analysis issues. * Adding non-blocking call for getting discovering devices. * Address PR feedback
This commit is contained in:
1 parent
6f299e7245
commit
bf91a8c1b3
7 files changed
+541
-139
No files matched your search
@@ -0,0 +1,97 @@
|
||||
"""Common code tests."""
|
||||
from datetime import timedelta
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from pyHS100 import SmartDeviceException
|
||||
|
||||
from homeassistant.components.tplink.common import async_add_entities_retry
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
|
||||
async def test_async_add_entities_retry(
|
||||
hass: HomeAssistantType
|
||||
):
|
||||
"""Test interval callback."""
|
||||
async_add_entities_callback = MagicMock()
|
||||
|
||||
# The objects that will be passed to async_add_entities_callback.
|
||||
objects = [
|
||||
"Object 1",
|
||||
"Object 2",
|
||||
"Object 3",
|
||||
"Object 4",
|
||||
]
|
||||
|
||||
# For each call to async_add_entities_callback, the following side effects
|
||||
# will be triggered in order. This set of side effects accuratley simulates
|
||||
# 3 attempts to add all entities while also handling several return types.
|
||||
# To help understand what's going on, a comment exists describing what the
|
||||
# object list looks like throughout the iterations.
|
||||
callback_side_effects = [
|
||||
# OB1, OB2, OB3, OB4
|
||||
False,
|
||||
False,
|
||||
True, # Object 3
|
||||
False,
|
||||
|
||||
# OB1, OB2, OB4
|
||||
True, # Object 1
|
||||
SmartDeviceException("My error"),
|
||||
False,
|
||||
|
||||
# OB2, OB4
|
||||
True, # Object 2
|
||||
True, # Object 4
|
||||
]
|
||||
|
||||
callback = MagicMock(side_effect=callback_side_effects)
|
||||
|
||||
await async_add_entities_retry(
|
||||
hass,
|
||||
async_add_entities_callback,
|
||||
objects,
|
||||
callback,
|
||||
interval=timedelta(milliseconds=100)
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert callback.call_count == len(callback_side_effects)
|
||||
|
||||
|
||||
async def test_async_add_entities_retry_cancel(
|
||||
hass: HomeAssistantType
|
||||
):
|
||||
"""Test interval callback."""
|
||||
async_add_entities_callback = MagicMock()
|
||||
|
||||
callback_side_effects = [
|
||||
False,
|
||||
False,
|
||||
True, # Object 1
|
||||
False,
|
||||
True, # Object 2
|
||||
SmartDeviceException("My error"),
|
||||
False,
|
||||
True, # Object 3
|
||||
True, # Object 4
|
||||
]
|
||||
|
||||
callback = MagicMock(side_effect=callback_side_effects)
|
||||
|
||||
objects = [
|
||||
"Object 1",
|
||||
"Object 2",
|
||||
"Object 3",
|
||||
"Object 4",
|
||||
]
|
||||
cancel = await async_add_entities_retry(
|
||||
hass,
|
||||
async_add_entities_callback,
|
||||
objects,
|
||||
callback,
|
||||
interval=timedelta(milliseconds=100)
|
||||
)
|
||||
cancel()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert callback.call_count == 4
|
||||
Reference in new issue
Block a user