Adhere to scan_interval in platforms when setup via config entry (#14969)

This commit is contained in:
Paulus Schoutsen 2018-06-15 10:59:13 -04:00 committed by Pascal Vizeli
parent d6d685a483
commit 1128104281
3 changed files with 11 additions and 3 deletions

View file

@ -108,7 +108,8 @@ class EntityComponent(object):
raise ValueError('Config entry has already been setup!')
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)

View file

@ -373,13 +373,16 @@ class MockPlatform(object):
# pylint: disable=invalid-name
def __init__(self, setup_platform=None, dependencies=None,
platform_schema=None, async_setup_platform=None,
async_setup_entry=None):
async_setup_entry=None, scan_interval=None):
"""Initialize the platform."""
self.DEPENDENCIES = dependencies or []
if platform_schema is not None:
self.PLATFORM_SCHEMA = platform_schema
if scan_interval is not None:
self.SCAN_INTERVAL = scan_interval
if setup_platform is not None:
# We run this in executor, wrap it in function
self.setup_platform = lambda *args: setup_platform(*args)

View file

@ -346,7 +346,8 @@ async def test_setup_entry(hass):
mock_setup_entry = Mock(return_value=mock_coro(True))
loader.set_component(
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)
entry = MockConfigEntry(domain='entry_domain')
@ -357,6 +358,9 @@ async def test_setup_entry(hass):
assert p_hass is hass
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):
"""Test setup entry fails if platform doesnt exist."""