mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Protect add_job (#4932)
This commit is contained in:
parent
43d18daebd
commit
1d60760e21
@ -184,6 +184,8 @@ class HomeAssistant(object):
|
|||||||
target: target to call.
|
target: target to call.
|
||||||
args: parameters for method to call.
|
args: parameters for method to call.
|
||||||
"""
|
"""
|
||||||
|
if target is None:
|
||||||
|
raise ValueError("Don't call add_job with None.")
|
||||||
self.loop.call_soon_threadsafe(self.async_add_job, target, *args)
|
self.loop.call_soon_threadsafe(self.async_add_job, target, *args)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -6,6 +6,7 @@ from unittest.mock import patch, MagicMock
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
import pytest
|
||||||
|
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.exceptions import InvalidEntityFormatError
|
from homeassistant.exceptions import InvalidEntityFormatError
|
||||||
@ -214,6 +215,11 @@ class TestHomeAssistant(unittest.TestCase):
|
|||||||
assert len(self.hass._pending_tasks) == 0
|
assert len(self.hass._pending_tasks) == 0
|
||||||
assert len(call_count) == 2
|
assert len(call_count) == 2
|
||||||
|
|
||||||
|
def test_add_job_with_none(self):
|
||||||
|
"""Try to add a job with None as function."""
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
self.hass.add_job(None, 'test_arg')
|
||||||
|
|
||||||
|
|
||||||
class TestEvent(unittest.TestCase):
|
class TestEvent(unittest.TestCase):
|
||||||
"""A Test Event class."""
|
"""A Test Event class."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user