Support longer-than-60-second scan_interval and interval_seconds (#5147)

* Update scan_interval and interval_seconds max to 1 day vs. 60 seconds

* Format fixes

* Add docstring on unittest.

* Added and implemented new async_track_time_interval helper.

* Format fixes, removed unused import.

* Undid whoops on unsub_polling.

* Updated unit tests for scan_interval.

* Added unit test for track_time_interval.

* Allow other forms of time interval input for scan_interval and interval_seconds
This commit is contained in:
Nick Touran 2017-01-05 14:05:16 -08:00 committed by Paulus Schoutsen
parent f88b5a9c5e
commit a36ca62445
6 changed files with 81 additions and 16 deletions

View file

@ -5,12 +5,15 @@ from collections import OrderedDict
import logging
import unittest
from unittest.mock import patch, Mock
from datetime import timedelta
import homeassistant.core as ha
import homeassistant.loader as loader
from homeassistant.components import group
from homeassistant.helpers.entity import Entity, generate_entity_id
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.entity_component import (
EntityComponent, DEFAULT_SCAN_INTERVAL)
from homeassistant.helpers import discovery
import homeassistant.util.dt as dt_util
@ -106,7 +109,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
no_poll_ent.async_update.reset_mock()
poll_ent.async_update.reset_mock()
fire_time_changed(self.hass, dt_util.utcnow().replace(second=0))
fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=20))
self.hass.block_till_done()
assert not no_poll_ent.async_update.called
@ -123,7 +126,10 @@ class TestHelpersEntityComponent(unittest.TestCase):
assert 1 == len(self.hass.states.entity_ids())
ent2.update = lambda *_: component.add_entities([ent1])
fire_time_changed(self.hass, dt_util.utcnow().replace(second=0))
fire_time_changed(
self.hass, dt_util.utcnow() +
timedelta(seconds=DEFAULT_SCAN_INTERVAL)
)
self.hass.block_till_done()
assert 2 == len(self.hass.states.entity_ids())
@ -311,7 +317,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
mock_setup.call_args[0]
@patch('homeassistant.helpers.entity_component.'
'async_track_utc_time_change')
'async_track_time_interval')
def test_set_scan_interval_via_config(self, mock_track):
"""Test the setting of the scan interval via configuration."""
def platform_setup(hass, config, add_devices, discovery_info=None):
@ -331,10 +337,10 @@ class TestHelpersEntityComponent(unittest.TestCase):
})
assert mock_track.called
assert [0, 30] == list(mock_track.call_args[1]['second'])
assert timedelta(seconds=30) == mock_track.call_args[0][2]
@patch('homeassistant.helpers.entity_component.'
'async_track_utc_time_change')
'async_track_time_interval')
def test_set_scan_interval_via_platform(self, mock_track):
"""Test the setting of the scan interval via platform."""
def platform_setup(hass, config, add_devices, discovery_info=None):
@ -355,7 +361,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
})
assert mock_track.called
assert [0, 30] == list(mock_track.call_args[1]['second'])
assert timedelta(seconds=30) == mock_track.call_args[0][2]
def test_set_entity_namespace_via_config(self):
"""Test setting an entity namespace."""