diff --git a/homeassistant/components/python_script.py b/homeassistant/components/python_script.py index 2082d824dca..cfb7098bbdf 100644 --- a/homeassistant/components/python_script.py +++ b/homeassistant/components/python_script.py @@ -92,6 +92,7 @@ def execute(hass, filename, source, data=None): '_print_': StubPrinter, '_getattr_': protected_getattr, '_write_': full_write_guard, + '_getiter_': iter, } logger = logging.getLogger('{}.{}'.format(__name__, filename)) local = { diff --git a/tests/components/test_python_script.py b/tests/components/test_python_script.py index bd62513599e..78142e06cf3 100644 --- a/tests/components/test_python_script.py +++ b/tests/components/test_python_script.py @@ -149,3 +149,18 @@ hass.stop() yield from hass.async_block_till_done() assert "Not allowed to access HomeAssistant.stop" in caplog.text + + +@asyncio.coroutine +def test_iterating(hass): + """Test compile error logs error.""" + source = """ +for i in [1, 2]: + hass.states.set('hello.{}'.format(i), 'world') + """ + + hass.async_add_job(execute, hass, 'test.py', source, {}) + yield from hass.async_block_till_done() + + assert hass.states.is_state('hello.1', 'world') + assert hass.states.is_state('hello.2', 'world')