Adhere to scan_interval in platforms when setup via config entry (#14969)
This commit is contained in:
parent
d6d685a483
commit
1128104281
3 changed files with 11 additions and 3 deletions
|
@ -108,7 +108,8 @@ class EntityComponent(object):
|
||||||
raise ValueError('Config entry has already been setup!')
|
raise ValueError('Config entry has already been setup!')
|
||||||
|
|
||||||
self._platforms[key] = self._async_init_entity_platform(
|
self._platforms[key] = self._async_init_entity_platform(
|
||||||
platform_type, platform
|
platform_type, platform,
|
||||||
|
scan_interval=getattr(platform, 'SCAN_INTERVAL', None),
|
||||||
)
|
)
|
||||||
|
|
||||||
return await self._platforms[key].async_setup_entry(config_entry)
|
return await self._platforms[key].async_setup_entry(config_entry)
|
||||||
|
|
|
@ -373,13 +373,16 @@ class MockPlatform(object):
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
def __init__(self, setup_platform=None, dependencies=None,
|
def __init__(self, setup_platform=None, dependencies=None,
|
||||||
platform_schema=None, async_setup_platform=None,
|
platform_schema=None, async_setup_platform=None,
|
||||||
async_setup_entry=None):
|
async_setup_entry=None, scan_interval=None):
|
||||||
"""Initialize the platform."""
|
"""Initialize the platform."""
|
||||||
self.DEPENDENCIES = dependencies or []
|
self.DEPENDENCIES = dependencies or []
|
||||||
|
|
||||||
if platform_schema is not None:
|
if platform_schema is not None:
|
||||||
self.PLATFORM_SCHEMA = platform_schema
|
self.PLATFORM_SCHEMA = platform_schema
|
||||||
|
|
||||||
|
if scan_interval is not None:
|
||||||
|
self.SCAN_INTERVAL = scan_interval
|
||||||
|
|
||||||
if setup_platform is not None:
|
if setup_platform is not None:
|
||||||
# We run this in executor, wrap it in function
|
# We run this in executor, wrap it in function
|
||||||
self.setup_platform = lambda *args: setup_platform(*args)
|
self.setup_platform = lambda *args: setup_platform(*args)
|
||||||
|
|
|
@ -346,7 +346,8 @@ async def test_setup_entry(hass):
|
||||||
mock_setup_entry = Mock(return_value=mock_coro(True))
|
mock_setup_entry = Mock(return_value=mock_coro(True))
|
||||||
loader.set_component(
|
loader.set_component(
|
||||||
hass, 'test_domain.entry_domain',
|
hass, 'test_domain.entry_domain',
|
||||||
MockPlatform(async_setup_entry=mock_setup_entry))
|
MockPlatform(async_setup_entry=mock_setup_entry,
|
||||||
|
scan_interval=timedelta(seconds=5)))
|
||||||
|
|
||||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||||
entry = MockConfigEntry(domain='entry_domain')
|
entry = MockConfigEntry(domain='entry_domain')
|
||||||
|
@ -357,6 +358,9 @@ async def test_setup_entry(hass):
|
||||||
assert p_hass is hass
|
assert p_hass is hass
|
||||||
assert p_entry is entry
|
assert p_entry is entry
|
||||||
|
|
||||||
|
assert component._platforms[entry.entry_id].scan_interval == \
|
||||||
|
timedelta(seconds=5)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_entry_platform_not_exist(hass):
|
async def test_setup_entry_platform_not_exist(hass):
|
||||||
"""Test setup entry fails if platform doesnt exist."""
|
"""Test setup entry fails if platform doesnt exist."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue