Remove service helper (8) (#17055)
* Updated keyboard * Updated microsoft_face * Updated ffmpeg * Updated logger * Updated components/__init__.py
This commit is contained in:
parent
13af61e103
commit
90f71261c5
9 changed files with 193 additions and 167 deletions
|
@ -8,8 +8,12 @@ import yaml
|
|||
import homeassistant.core as ha
|
||||
from homeassistant import config
|
||||
from homeassistant.const import (
|
||||
STATE_ON, STATE_OFF, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE)
|
||||
ATTR_ENTITY_ID, STATE_ON, STATE_OFF, SERVICE_HOMEASSISTANT_RESTART,
|
||||
SERVICE_HOMEASSISTANT_STOP, SERVICE_TURN_ON, SERVICE_TURN_OFF,
|
||||
SERVICE_TOGGLE)
|
||||
import homeassistant.components as comps
|
||||
from homeassistant.components import (
|
||||
SERVICE_CHECK_CONFIG, SERVICE_RELOAD_CORE_CONFIG)
|
||||
import homeassistant.helpers.intent as intent
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity
|
||||
|
@ -20,6 +24,71 @@ from tests.common import (
|
|||
async_mock_service)
|
||||
|
||||
|
||||
def turn_on(hass, entity_id=None, **service_data):
|
||||
"""Turn specified entity on if possible.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
if entity_id is not None:
|
||||
service_data[ATTR_ENTITY_ID] = entity_id
|
||||
|
||||
hass.services.call(ha.DOMAIN, SERVICE_TURN_ON, service_data)
|
||||
|
||||
|
||||
def turn_off(hass, entity_id=None, **service_data):
|
||||
"""Turn specified entity off.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
if entity_id is not None:
|
||||
service_data[ATTR_ENTITY_ID] = entity_id
|
||||
|
||||
hass.services.call(ha.DOMAIN, SERVICE_TURN_OFF, service_data)
|
||||
|
||||
|
||||
def toggle(hass, entity_id=None, **service_data):
|
||||
"""Toggle specified entity.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
if entity_id is not None:
|
||||
service_data[ATTR_ENTITY_ID] = entity_id
|
||||
|
||||
hass.services.call(ha.DOMAIN, SERVICE_TOGGLE, service_data)
|
||||
|
||||
|
||||
def stop(hass):
|
||||
"""Stop Home Assistant.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(ha.DOMAIN, SERVICE_HOMEASSISTANT_STOP)
|
||||
|
||||
|
||||
def restart(hass):
|
||||
"""Stop Home Assistant.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(ha.DOMAIN, SERVICE_HOMEASSISTANT_RESTART)
|
||||
|
||||
|
||||
def check_config(hass):
|
||||
"""Check the config files.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(ha.DOMAIN, SERVICE_CHECK_CONFIG)
|
||||
|
||||
|
||||
def reload_core_config(hass):
|
||||
"""Reload the core config.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(ha.DOMAIN, SERVICE_RELOAD_CORE_CONFIG)
|
||||
|
||||
|
||||
class TestComponentsCore(unittest.TestCase):
|
||||
"""Test homeassistant.components module."""
|
||||
|
||||
|
@ -49,28 +118,28 @@ class TestComponentsCore(unittest.TestCase):
|
|||
def test_turn_on_without_entities(self):
|
||||
"""Test turn_on method without entities."""
|
||||
calls = mock_service(self.hass, 'light', SERVICE_TURN_ON)
|
||||
comps.turn_on(self.hass)
|
||||
turn_on(self.hass)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(calls))
|
||||
|
||||
def test_turn_on(self):
|
||||
"""Test turn_on method."""
|
||||
calls = mock_service(self.hass, 'light', SERVICE_TURN_ON)
|
||||
comps.turn_on(self.hass, 'light.Ceiling')
|
||||
turn_on(self.hass, 'light.Ceiling')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(calls))
|
||||
|
||||
def test_turn_off(self):
|
||||
"""Test turn_off method."""
|
||||
calls = mock_service(self.hass, 'light', SERVICE_TURN_OFF)
|
||||
comps.turn_off(self.hass, 'light.Bowl')
|
||||
turn_off(self.hass, 'light.Bowl')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(calls))
|
||||
|
||||
def test_toggle(self):
|
||||
"""Test toggle method."""
|
||||
calls = mock_service(self.hass, 'light', SERVICE_TOGGLE)
|
||||
comps.toggle(self.hass, 'light.Bowl')
|
||||
toggle(self.hass, 'light.Bowl')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(calls))
|
||||
|
||||
|
@ -102,7 +171,7 @@ class TestComponentsCore(unittest.TestCase):
|
|||
})
|
||||
}
|
||||
with patch_yaml_files(files, True):
|
||||
comps.reload_core_config(self.hass)
|
||||
reload_core_config(self.hass)
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert self.hass.config.latitude == 10
|
||||
|
@ -125,7 +194,7 @@ class TestComponentsCore(unittest.TestCase):
|
|||
config.YAML_CONFIG_FILE: yaml.dump(['invalid', 'config'])
|
||||
}
|
||||
with patch_yaml_files(files, True):
|
||||
comps.reload_core_config(self.hass)
|
||||
reload_core_config(self.hass)
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert mock_error.called
|
||||
|
@ -135,7 +204,7 @@ class TestComponentsCore(unittest.TestCase):
|
|||
return_value=mock_coro())
|
||||
def test_stop_homeassistant(self, mock_stop):
|
||||
"""Test stop service."""
|
||||
comps.stop(self.hass)
|
||||
stop(self.hass)
|
||||
self.hass.block_till_done()
|
||||
assert mock_stop.called
|
||||
|
||||
|
@ -145,7 +214,7 @@ class TestComponentsCore(unittest.TestCase):
|
|||
return_value=mock_coro())
|
||||
def test_restart_homeassistant(self, mock_check, mock_restart):
|
||||
"""Test stop service."""
|
||||
comps.restart(self.hass)
|
||||
restart(self.hass)
|
||||
self.hass.block_till_done()
|
||||
assert mock_restart.called
|
||||
assert mock_check.called
|
||||
|
@ -156,7 +225,7 @@ class TestComponentsCore(unittest.TestCase):
|
|||
side_effect=HomeAssistantError("Test error"))
|
||||
def test_restart_homeassistant_wrong_conf(self, mock_check, mock_restart):
|
||||
"""Test stop service."""
|
||||
comps.restart(self.hass)
|
||||
restart(self.hass)
|
||||
self.hass.block_till_done()
|
||||
assert mock_check.called
|
||||
assert not mock_restart.called
|
||||
|
@ -167,7 +236,7 @@ class TestComponentsCore(unittest.TestCase):
|
|||
return_value=mock_coro())
|
||||
def test_check_config(self, mock_check, mock_stop):
|
||||
"""Test stop service."""
|
||||
comps.check_config(self.hass)
|
||||
check_config(self.hass)
|
||||
self.hass.block_till_done()
|
||||
assert mock_check.called
|
||||
assert not mock_stop.called
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue