mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 04:50:05 +00:00
Move core service from core to components (#5787)
* Move core servcie from core to components * add new handler for signals/exception * Static persistent id * Move unittest * fix coro/callback * Add more unittest for new services * Address comments * Update __init__.py
This commit is contained in:
committed by
Paulus Schoutsen
parent
08efe2bf6d
commit
3f82ef64a1
@@ -11,11 +11,12 @@ from homeassistant import config
|
||||
from homeassistant.const import (
|
||||
STATE_ON, STATE_OFF, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE)
|
||||
import homeassistant.components as comps
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity
|
||||
from homeassistant.util.async import run_coroutine_threadsafe
|
||||
|
||||
from tests.common import (
|
||||
get_test_home_assistant, mock_service, patch_yaml_files)
|
||||
get_test_home_assistant, mock_service, patch_yaml_files, mock_coro)
|
||||
|
||||
|
||||
class TestComponentsCore(unittest.TestCase):
|
||||
@@ -150,3 +151,44 @@ class TestComponentsCore(unittest.TestCase):
|
||||
|
||||
assert mock_error.called
|
||||
assert mock_process.called is False
|
||||
|
||||
@patch('homeassistant.core.HomeAssistant.async_stop',
|
||||
return_value=mock_coro()())
|
||||
def test_stop_homeassistant(self, mock_stop):
|
||||
"""Test stop service."""
|
||||
comps.stop(self.hass)
|
||||
self.hass.block_till_done()
|
||||
assert mock_stop.called
|
||||
|
||||
@patch('homeassistant.core.HomeAssistant.async_stop',
|
||||
return_value=mock_coro()())
|
||||
@patch('homeassistant.config.async_check_ha_config_file',
|
||||
return_value=mock_coro()())
|
||||
def test_restart_homeassistant(self, mock_check, mock_restart):
|
||||
"""Test stop service."""
|
||||
comps.restart(self.hass)
|
||||
self.hass.block_till_done()
|
||||
assert mock_restart.called
|
||||
assert mock_check.called
|
||||
|
||||
@patch('homeassistant.core.HomeAssistant.async_stop',
|
||||
return_value=mock_coro()())
|
||||
@patch('homeassistant.config.async_check_ha_config_file',
|
||||
side_effect=HomeAssistantError("Test error"))
|
||||
def test_restart_homeassistant_wrong_conf(self, mock_check, mock_restart):
|
||||
"""Test stop service."""
|
||||
comps.restart(self.hass)
|
||||
self.hass.block_till_done()
|
||||
assert mock_check.called
|
||||
assert not mock_restart.called
|
||||
|
||||
@patch('homeassistant.core.HomeAssistant.async_stop',
|
||||
return_value=mock_coro()())
|
||||
@patch('homeassistant.config.async_check_ha_config_file',
|
||||
return_value=mock_coro()())
|
||||
def test_check_config(self, mock_check, mock_stop):
|
||||
"""Test stop service."""
|
||||
comps.check_config(self.hass)
|
||||
self.hass.block_till_done()
|
||||
assert mock_check.called
|
||||
assert not mock_stop.called
|
||||
|
||||
Reference in New Issue
Block a user