Remove service helper (3) (#16879)
* Update duckdns * Update google_assistant * Update group * Update homematic * Update image_processing * Update input_boolean * Update input_number * Update input_select * Update input_text
This commit is contained in:
parent
672fc61bb2
commit
e2a56721d3
22 changed files with 217 additions and 231 deletions
|
@ -11,7 +11,6 @@ import logging
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_DOMAIN
|
||||
from homeassistant.loader import bind_hass
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
@ -40,15 +39,6 @@ SERVICE_TXT_SCHEMA = vol.Schema({
|
|||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
@asyncio.coroutine
|
||||
def async_set_txt(hass, txt):
|
||||
"""Set the txt record. Pass in None to remove it."""
|
||||
yield from hass.services.async_call(DOMAIN, SERVICE_SET_TXT, {
|
||||
ATTR_TXT: txt
|
||||
}, blocking=True)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup(hass, config):
|
||||
"""Initialize the DuckDNS component."""
|
||||
|
|
|
@ -19,7 +19,6 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
from .const import (
|
||||
DOMAIN, CONF_PROJECT_ID, CONF_CLIENT_ID, CONF_ACCESS_TOKEN,
|
||||
|
@ -63,12 +62,6 @@ CONFIG_SCHEMA = vol.Schema(
|
|||
extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def request_sync(hass):
|
||||
"""Request sync."""
|
||||
hass.services.call(DOMAIN, SERVICE_REQUEST_SYNC)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, yaml_config: Dict[str, Any]):
|
||||
"""Activate Google Actions component."""
|
||||
config = yaml_config.get(DOMAIN, {})
|
||||
|
|
|
@ -133,13 +133,6 @@ def async_reload(hass):
|
|||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_RELOAD))
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_visibility(hass, entity_id=None, visible=True):
|
||||
"""Hide or shows a group."""
|
||||
data = {ATTR_ENTITY_ID: entity_id, ATTR_VISIBLE: visible}
|
||||
hass.services.call(DOMAIN, SERVICE_SET_VISIBILITY, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_group(hass, object_id, name=None, entity_ids=None, visible=None,
|
||||
icon=None, view=None, control=None, add=None):
|
||||
|
|
|
@ -18,7 +18,6 @@ from homeassistant.const import (
|
|||
from homeassistant.helpers import discovery
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
REQUIREMENTS = ['pyhomematic==0.1.49']
|
||||
|
||||
|
@ -245,78 +244,6 @@ SCHEMA_SERVICE_PUT_PARAMSET = vol.Schema({
|
|||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def virtualkey(hass, address, channel, param, interface=None):
|
||||
"""Send virtual keypress to homematic controller."""
|
||||
data = {
|
||||
ATTR_ADDRESS: address,
|
||||
ATTR_CHANNEL: channel,
|
||||
ATTR_PARAM: param,
|
||||
ATTR_INTERFACE: interface,
|
||||
}
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_VIRTUALKEY, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_variable_value(hass, entity_id, value):
|
||||
"""Change value of a Homematic system variable."""
|
||||
data = {
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_VALUE: value,
|
||||
}
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_SET_VARIABLE_VALUE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_device_value(hass, address, channel, param, value, interface=None):
|
||||
"""Call setValue XML-RPC method of supplied interface."""
|
||||
data = {
|
||||
ATTR_ADDRESS: address,
|
||||
ATTR_CHANNEL: channel,
|
||||
ATTR_PARAM: param,
|
||||
ATTR_VALUE: value,
|
||||
ATTR_INTERFACE: interface,
|
||||
}
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_SET_DEVICE_VALUE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def put_paramset(hass, interface, address, paramset_key, paramset):
|
||||
"""Call putParamset XML-RPC method of supplied interface."""
|
||||
data = {
|
||||
ATTR_INTERFACE: interface,
|
||||
ATTR_ADDRESS: address,
|
||||
ATTR_PARAMSET_KEY: paramset_key,
|
||||
ATTR_PARAMSET: paramset,
|
||||
}
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_PUT_PARAMSET, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_install_mode(hass, interface, mode=None, time=None, address=None):
|
||||
"""Call setInstallMode XML-RPC method of supplied interface."""
|
||||
data = {
|
||||
key: value for key, value in (
|
||||
(ATTR_INTERFACE, interface),
|
||||
(ATTR_MODE, mode),
|
||||
(ATTR_TIME, time),
|
||||
(ATTR_ADDRESS, address)
|
||||
) if value
|
||||
}
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_SET_INSTALL_MODE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def reconnect(hass):
|
||||
"""Reconnect to CCU/Homegear."""
|
||||
hass.services.call(DOMAIN, SERVICE_RECONNECT, {})
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up the Homematic component."""
|
||||
from pyhomematic import HMConnection
|
||||
|
|
|
@ -17,7 +17,6 @@ from homeassistant.exceptions import HomeAssistantError
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util.async_ import run_callback_threadsafe
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -67,20 +66,6 @@ SERVICE_SCAN_SCHEMA = vol.Schema({
|
|||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def scan(hass, entity_id=None):
|
||||
"""Force process of all cameras or given entity."""
|
||||
hass.add_job(async_scan, hass, entity_id)
|
||||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_scan(hass, entity_id=None):
|
||||
"""Force process of all cameras or given entity."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_SCAN, data))
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
"""Set up the image processing."""
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL)
|
||||
|
|
|
@ -46,24 +46,6 @@ def is_on(hass, entity_id):
|
|||
return hass.states.is_state(entity_id, STATE_ON)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_on(hass, entity_id):
|
||||
"""Set input_boolean to True."""
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: entity_id})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_off(hass, entity_id):
|
||||
"""Set input_boolean to False."""
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def toggle(hass, entity_id):
|
||||
"""Set input_boolean to False."""
|
||||
hass.services.call(DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: entity_id})
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
"""Set up an input boolean."""
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
|
|
|
@ -15,7 +15,6 @@ from homeassistant.const import (
|
|||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.restore_state import async_get_last_state
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -82,31 +81,6 @@ CONFIG_SCHEMA = vol.Schema({
|
|||
}, required=True, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_value(hass, entity_id, value):
|
||||
"""Set input_number to value."""
|
||||
hass.services.call(DOMAIN, SERVICE_SET_VALUE, {
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_VALUE: value,
|
||||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def increment(hass, entity_id):
|
||||
"""Increment value of entity."""
|
||||
hass.services.call(DOMAIN, SERVICE_INCREMENT, {
|
||||
ATTR_ENTITY_ID: entity_id
|
||||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def decrement(hass, entity_id):
|
||||
"""Decrement value of entity."""
|
||||
hass.services.call(DOMAIN, SERVICE_DECREMENT, {
|
||||
ATTR_ENTITY_ID: entity_id
|
||||
})
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup(hass, config):
|
||||
"""Set up an input slider."""
|
||||
|
|
|
@ -10,7 +10,6 @@ import logging
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_ICON, CONF_NAME
|
||||
from homeassistant.loader import bind_hass
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
|
@ -78,40 +77,6 @@ CONFIG_SCHEMA = vol.Schema({
|
|||
}, required=True, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def select_option(hass, entity_id, option):
|
||||
"""Set value of input_select."""
|
||||
hass.services.call(DOMAIN, SERVICE_SELECT_OPTION, {
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_OPTION: option,
|
||||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def select_next(hass, entity_id):
|
||||
"""Set next value of input_select."""
|
||||
hass.services.call(DOMAIN, SERVICE_SELECT_NEXT, {
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def select_previous(hass, entity_id):
|
||||
"""Set previous value of input_select."""
|
||||
hass.services.call(DOMAIN, SERVICE_SELECT_PREVIOUS, {
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_options(hass, entity_id, options):
|
||||
"""Set options of input_select."""
|
||||
hass.services.call(DOMAIN, SERVICE_SET_OPTIONS, {
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_OPTIONS: options,
|
||||
})
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup(hass, config):
|
||||
"""Set up an input select."""
|
||||
|
|
|
@ -12,7 +12,6 @@ import voluptuous as vol
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, ATTR_UNIT_OF_MEASUREMENT, CONF_ICON, CONF_NAME, CONF_MODE)
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.restore_state import async_get_last_state
|
||||
|
@ -74,15 +73,6 @@ CONFIG_SCHEMA = vol.Schema({
|
|||
}, required=True, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_value(hass, entity_id, value):
|
||||
"""Set input_text to value."""
|
||||
hass.services.call(DOMAIN, SERVICE_SET_VALUE, {
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_VALUE: value,
|
||||
})
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup(hass, config):
|
||||
"""Set up an input text box."""
|
||||
|
|
16
tests/components/group/common.py
Normal file
16
tests/components/group/common.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
"""Collection of helper methods.
|
||||
|
||||
All containing methods are legacy helpers that should not be used by new
|
||||
components. Instead call the service directly.
|
||||
"""
|
||||
from homeassistant.components.group import ATTR_VISIBLE, DOMAIN, \
|
||||
SERVICE_SET_VISIBILITY
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_visibility(hass, entity_id=None, visible=True):
|
||||
"""Hide or shows a group."""
|
||||
data = {ATTR_ENTITY_ID: entity_id, ATTR_VISIBLE: visible}
|
||||
hass.services.call(DOMAIN, SERVICE_SET_VISIBILITY, data)
|
|
@ -12,6 +12,7 @@ from homeassistant.const import (
|
|||
import homeassistant.components.group as group
|
||||
|
||||
from tests.common import get_test_home_assistant, assert_setup_component
|
||||
from tests.components.group import common
|
||||
|
||||
|
||||
class TestComponentsGroup(unittest.TestCase):
|
||||
|
@ -385,13 +386,13 @@ class TestComponentsGroup(unittest.TestCase):
|
|||
group_entity_id = group.ENTITY_ID_FORMAT.format('test_group')
|
||||
|
||||
# Hide the group
|
||||
group.set_visibility(self.hass, group_entity_id, False)
|
||||
common.set_visibility(self.hass, group_entity_id, False)
|
||||
self.hass.block_till_done()
|
||||
group_state = self.hass.states.get(group_entity_id)
|
||||
self.assertTrue(group_state.attributes.get(ATTR_HIDDEN))
|
||||
|
||||
# Show it again
|
||||
group.set_visibility(self.hass, group_entity_id, True)
|
||||
common.set_visibility(self.hass, group_entity_id, True)
|
||||
self.hass.block_till_done()
|
||||
group_state = self.hass.states.get(group_entity_id)
|
||||
self.assertIsNone(group_state.attributes.get(ATTR_HIDDEN))
|
||||
|
|
23
tests/components/image_processing/common.py
Normal file
23
tests/components/image_processing/common.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
"""Collection of helper methods.
|
||||
|
||||
All containing methods are legacy helpers that should not be used by new
|
||||
components. Instead call the service directly.
|
||||
"""
|
||||
from homeassistant.components.image_processing import DOMAIN, SERVICE_SCAN
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
|
||||
@bind_hass
|
||||
def scan(hass, entity_id=None):
|
||||
"""Force process of all cameras or given entity."""
|
||||
hass.add_job(async_scan, hass, entity_id)
|
||||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_scan(hass, entity_id=None):
|
||||
"""Force process of all cameras or given entity."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_SCAN, data))
|
|
@ -10,6 +10,7 @@ import homeassistant.components.image_processing as ip
|
|||
|
||||
from tests.common import (
|
||||
get_test_home_assistant, get_test_instance_port, assert_setup_component)
|
||||
from tests.components.image_processing import common
|
||||
|
||||
|
||||
class TestSetupImageProcessing:
|
||||
|
@ -85,7 +86,7 @@ class TestImageProcessing:
|
|||
"""Grab an image from camera entity."""
|
||||
self.hass.start()
|
||||
|
||||
ip.scan(self.hass, entity_id='image_processing.test')
|
||||
common.scan(self.hass, entity_id='image_processing.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.test')
|
||||
|
@ -100,7 +101,7 @@ class TestImageProcessing:
|
|||
"""Try to get image without exists camera."""
|
||||
self.hass.states.remove('camera.demo_camera')
|
||||
|
||||
ip.scan(self.hass, entity_id='image_processing.test')
|
||||
common.scan(self.hass, entity_id='image_processing.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.test')
|
||||
|
@ -152,7 +153,7 @@ class TestImageProcessingAlpr:
|
|||
"""Set up and scan a picture and test plates from event."""
|
||||
aioclient_mock.get(self.url, content=b'image')
|
||||
|
||||
ip.scan(self.hass, entity_id='image_processing.demo_alpr')
|
||||
common.scan(self.hass, entity_id='image_processing.demo_alpr')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.demo_alpr')
|
||||
|
@ -171,8 +172,8 @@ class TestImageProcessingAlpr:
|
|||
"""Set up and scan a picture and test plates from event."""
|
||||
aioclient_mock.get(self.url, content=b'image')
|
||||
|
||||
ip.scan(self.hass, entity_id='image_processing.demo_alpr')
|
||||
ip.scan(self.hass, entity_id='image_processing.demo_alpr')
|
||||
common.scan(self.hass, entity_id='image_processing.demo_alpr')
|
||||
common.scan(self.hass, entity_id='image_processing.demo_alpr')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.demo_alpr')
|
||||
|
@ -195,7 +196,7 @@ class TestImageProcessingAlpr:
|
|||
"""Set up and scan a picture and test plates from event."""
|
||||
aioclient_mock.get(self.url, content=b'image')
|
||||
|
||||
ip.scan(self.hass, entity_id='image_processing.demo_alpr')
|
||||
common.scan(self.hass, entity_id='image_processing.demo_alpr')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.demo_alpr')
|
||||
|
@ -254,7 +255,7 @@ class TestImageProcessingFace:
|
|||
"""Set up and scan a picture and test faces from event."""
|
||||
aioclient_mock.get(self.url, content=b'image')
|
||||
|
||||
ip.scan(self.hass, entity_id='image_processing.demo_face')
|
||||
common.scan(self.hass, entity_id='image_processing.demo_face')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.demo_face')
|
||||
|
@ -279,7 +280,7 @@ class TestImageProcessingFace:
|
|||
"""Set up and scan a picture and test faces from event."""
|
||||
aioclient_mock.get(self.url, content=b'image')
|
||||
|
||||
ip.scan(self.hass, entity_id='image_processing.demo_face')
|
||||
common.scan(self.hass, entity_id='image_processing.demo_face')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.demo_face')
|
||||
|
|
|
@ -9,6 +9,7 @@ import homeassistant.components.microsoft_face as mf
|
|||
|
||||
from tests.common import (
|
||||
get_test_home_assistant, assert_setup_component, load_fixture, mock_coro)
|
||||
from tests.components.image_processing import common
|
||||
|
||||
|
||||
class TestMicrosoftFaceDetectSetup:
|
||||
|
@ -146,7 +147,7 @@ class TestMicrosoftFaceDetect:
|
|||
params={'returnFaceAttributes': "age,gender"}
|
||||
)
|
||||
|
||||
ip.scan(self.hass, entity_id='image_processing.test_local')
|
||||
common.scan(self.hass, entity_id='image_processing.test_local')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.test_local')
|
||||
|
|
|
@ -9,6 +9,7 @@ import homeassistant.components.microsoft_face as mf
|
|||
|
||||
from tests.common import (
|
||||
get_test_home_assistant, assert_setup_component, load_fixture, mock_coro)
|
||||
from tests.components.image_processing import common
|
||||
|
||||
|
||||
class TestMicrosoftFaceIdentifySetup:
|
||||
|
@ -150,7 +151,7 @@ class TestMicrosoftFaceIdentify:
|
|||
text=load_fixture('microsoft_face_identify.json')
|
||||
)
|
||||
|
||||
ip.scan(self.hass, entity_id='image_processing.test_local')
|
||||
common.scan(self.hass, entity_id='image_processing.test_local')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.test_local')
|
||||
|
|
|
@ -10,6 +10,7 @@ from homeassistant.components.image_processing.openalpr_cloud import (
|
|||
|
||||
from tests.common import (
|
||||
get_test_home_assistant, assert_setup_component, load_fixture, mock_coro)
|
||||
from tests.components.image_processing import common
|
||||
|
||||
|
||||
class TestOpenAlprCloudSetup:
|
||||
|
@ -160,7 +161,7 @@ class TestOpenAlprCloud:
|
|||
with patch('homeassistant.components.camera.async_get_image',
|
||||
return_value=mock_coro(
|
||||
camera.Image('image/jpeg', b'image'))):
|
||||
ip.scan(self.hass, entity_id='image_processing.test_local')
|
||||
common.scan(self.hass, entity_id='image_processing.test_local')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.test_local')
|
||||
|
@ -188,7 +189,7 @@ class TestOpenAlprCloud:
|
|||
with patch('homeassistant.components.camera.async_get_image',
|
||||
return_value=mock_coro(
|
||||
camera.Image('image/jpeg', b'image'))):
|
||||
ip.scan(self.hass, entity_id='image_processing.test_local')
|
||||
common.scan(self.hass, entity_id='image_processing.test_local')
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert len(aioclient_mock.mock_calls) == 1
|
||||
|
@ -204,7 +205,7 @@ class TestOpenAlprCloud:
|
|||
with patch('homeassistant.components.camera.async_get_image',
|
||||
return_value=mock_coro(
|
||||
camera.Image('image/jpeg', b'image'))):
|
||||
ip.scan(self.hass, entity_id='image_processing.test_local')
|
||||
common.scan(self.hass, entity_id='image_processing.test_local')
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert len(aioclient_mock.mock_calls) == 1
|
||||
|
|
|
@ -9,6 +9,7 @@ import homeassistant.components.image_processing as ip
|
|||
|
||||
from tests.common import (
|
||||
get_test_home_assistant, assert_setup_component, load_fixture)
|
||||
from tests.components.image_processing import common
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
|
@ -146,7 +147,7 @@ class TestOpenAlprLocal:
|
|||
"""Set up and scan a picture and test plates from event."""
|
||||
aioclient_mock.get(self.url, content=b'image')
|
||||
|
||||
ip.scan(self.hass, entity_id='image_processing.test_local')
|
||||
common.scan(self.hass, entity_id='image_processing.test_local')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.test_local')
|
||||
|
|
|
@ -4,6 +4,7 @@ from datetime import timedelta
|
|||
|
||||
import pytest
|
||||
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import duckdns
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
@ -14,6 +15,19 @@ DOMAIN = 'bla'
|
|||
TOKEN = 'abcdefgh'
|
||||
|
||||
|
||||
@bind_hass
|
||||
@asyncio.coroutine
|
||||
def async_set_txt(hass, txt):
|
||||
"""Set the txt record. Pass in None to remove it.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
yield from hass.services.async_call(
|
||||
duckdns.DOMAIN, duckdns.SERVICE_SET_TXT, {
|
||||
duckdns.ATTR_TXT: txt
|
||||
}, blocking=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def setup_duckdns(hass, aioclient_mock):
|
||||
"""Fixture that sets up DuckDNS."""
|
||||
|
@ -84,7 +98,7 @@ def test_service_set_txt(hass, aioclient_mock, setup_duckdns):
|
|||
}, text='OK')
|
||||
|
||||
assert aioclient_mock.call_count == 0
|
||||
yield from hass.components.duckdns.async_set_txt('some-txt')
|
||||
yield from async_set_txt(hass, 'some-txt')
|
||||
assert aioclient_mock.call_count == 1
|
||||
|
||||
|
||||
|
@ -102,5 +116,5 @@ def test_service_clear_txt(hass, aioclient_mock, setup_duckdns):
|
|||
}, text='OK')
|
||||
|
||||
assert aioclient_mock.call_count == 0
|
||||
yield from hass.components.duckdns.async_set_txt(None)
|
||||
yield from async_set_txt(hass, None)
|
||||
assert aioclient_mock.call_count == 1
|
||||
|
|
|
@ -7,9 +7,11 @@ import logging
|
|||
from homeassistant.core import CoreState, State, Context
|
||||
from homeassistant.setup import setup_component, async_setup_component
|
||||
from homeassistant.components.input_boolean import (
|
||||
DOMAIN, is_on, toggle, turn_off, turn_on, CONF_INITIAL)
|
||||
is_on, CONF_INITIAL, DOMAIN)
|
||||
from homeassistant.const import (
|
||||
STATE_ON, STATE_OFF, ATTR_ICON, ATTR_FRIENDLY_NAME)
|
||||
STATE_ON, STATE_OFF, ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME, ATTR_ICON,
|
||||
SERVICE_TOGGLE, SERVICE_TURN_OFF, SERVICE_TURN_ON)
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
from tests.common import (
|
||||
get_test_home_assistant, mock_component, mock_restore_cache)
|
||||
|
@ -17,6 +19,33 @@ from tests.common import (
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def toggle(hass, entity_id):
|
||||
"""Set input_boolean to False.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: entity_id})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_on(hass, entity_id):
|
||||
"""Set input_boolean to True.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: entity_id})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_off(hass, entity_id):
|
||||
"""Set input_boolean to False.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id})
|
||||
|
||||
|
||||
class TestInputBoolean(unittest.TestCase):
|
||||
"""Test the input boolean module."""
|
||||
|
||||
|
|
|
@ -4,13 +4,50 @@ import asyncio
|
|||
import unittest
|
||||
|
||||
from homeassistant.core import CoreState, State, Context
|
||||
from homeassistant.setup import setup_component, async_setup_component
|
||||
from homeassistant.components.input_number import (
|
||||
DOMAIN, set_value, increment, decrement)
|
||||
ATTR_VALUE, DOMAIN, SERVICE_DECREMENT, SERVICE_INCREMENT,
|
||||
SERVICE_SET_VALUE)
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.setup import setup_component, async_setup_component
|
||||
|
||||
from tests.common import get_test_home_assistant, mock_restore_cache
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_value(hass, entity_id, value):
|
||||
"""Set input_number to value.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(DOMAIN, SERVICE_SET_VALUE, {
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_VALUE: value,
|
||||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def increment(hass, entity_id):
|
||||
"""Increment value of entity.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(DOMAIN, SERVICE_INCREMENT, {
|
||||
ATTR_ENTITY_ID: entity_id
|
||||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def decrement(hass, entity_id):
|
||||
"""Decrement value of entity.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(DOMAIN, SERVICE_DECREMENT, {
|
||||
ATTR_ENTITY_ID: entity_id
|
||||
})
|
||||
|
||||
|
||||
class TestInputNumber(unittest.TestCase):
|
||||
"""Test the input number component."""
|
||||
|
||||
|
|
|
@ -3,15 +3,62 @@
|
|||
import asyncio
|
||||
import unittest
|
||||
|
||||
from tests.common import get_test_home_assistant, mock_restore_cache
|
||||
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.components.input_select import (
|
||||
ATTR_OPTION, ATTR_OPTIONS, DOMAIN, SERVICE_SET_OPTIONS,
|
||||
SERVICE_SELECT_NEXT, SERVICE_SELECT_OPTION, SERVICE_SELECT_PREVIOUS)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME, ATTR_ICON)
|
||||
from homeassistant.core import State, Context
|
||||
from homeassistant.setup import setup_component, async_setup_component
|
||||
from homeassistant.components.input_select import (
|
||||
ATTR_OPTIONS, DOMAIN, SERVICE_SET_OPTIONS,
|
||||
select_option, select_next, select_previous)
|
||||
from homeassistant.const import (
|
||||
ATTR_ICON, ATTR_FRIENDLY_NAME)
|
||||
|
||||
from tests.common import get_test_home_assistant, mock_restore_cache
|
||||
|
||||
|
||||
@bind_hass
|
||||
def select_option(hass, entity_id, option):
|
||||
"""Set value of input_select.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(DOMAIN, SERVICE_SELECT_OPTION, {
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_OPTION: option,
|
||||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def select_next(hass, entity_id):
|
||||
"""Set next value of input_select.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(DOMAIN, SERVICE_SELECT_NEXT, {
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def select_previous(hass, entity_id):
|
||||
"""Set previous value of input_select.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(DOMAIN, SERVICE_SELECT_PREVIOUS, {
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_options(hass, entity_id, options):
|
||||
"""Set options of input_select.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(DOMAIN, SERVICE_SET_OPTIONS, {
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_OPTIONS: options,
|
||||
})
|
||||
|
||||
|
||||
class TestInputSelect(unittest.TestCase):
|
||||
|
|
|
@ -3,13 +3,28 @@
|
|||
import asyncio
|
||||
import unittest
|
||||
|
||||
from homeassistant.components.input_text import (
|
||||
ATTR_VALUE, DOMAIN, SERVICE_SET_VALUE)
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import CoreState, State, Context
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.setup import setup_component, async_setup_component
|
||||
from homeassistant.components.input_text import (DOMAIN, set_value)
|
||||
|
||||
from tests.common import get_test_home_assistant, mock_restore_cache
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_value(hass, entity_id, value):
|
||||
"""Set input_text to value.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(DOMAIN, SERVICE_SET_VALUE, {
|
||||
ATTR_ENTITY_ID: entity_id,
|
||||
ATTR_VALUE: value,
|
||||
})
|
||||
|
||||
|
||||
class TestInputText(unittest.TestCase):
|
||||
"""Test the input slider component."""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue