Remove service helper (4) (#16892)
* Update media_player * Update lock * Update notify * Update remote * Update scene * Update vacuum * Remove timer helpers * Removed unused legacy helpers
This commit is contained in:
1 parent
d0ddc28f96
commit
dd45e99302
23 files changed
+499
-520
No files matched your search
@@ -0,0 +1,45 @@
|
||||
"""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.lock import DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_CODE, ATTR_ENTITY_ID, SERVICE_LOCK, SERVICE_UNLOCK, SERVICE_OPEN)
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
|
||||
@bind_hass
|
||||
def lock(hass, entity_id=None, code=None):
|
||||
"""Lock all or specified locks."""
|
||||
data = {}
|
||||
if code:
|
||||
data[ATTR_CODE] = code
|
||||
if entity_id:
|
||||
data[ATTR_ENTITY_ID] = entity_id
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_LOCK, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def unlock(hass, entity_id=None, code=None):
|
||||
"""Unlock all or specified locks."""
|
||||
data = {}
|
||||
if code:
|
||||
data[ATTR_CODE] = code
|
||||
if entity_id:
|
||||
data[ATTR_ENTITY_ID] = entity_id
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_UNLOCK, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def open_lock(hass, entity_id=None, code=None):
|
||||
"""Open all or specified locks."""
|
||||
data = {}
|
||||
if code:
|
||||
data[ATTR_CODE] = code
|
||||
if entity_id:
|
||||
data[ATTR_ENTITY_ID] = entity_id
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_OPEN, data)
|
||||
@@ -5,6 +5,8 @@ from homeassistant.setup import setup_component
|
||||
from homeassistant.components import lock
|
||||
|
||||
from tests.common import get_test_home_assistant, mock_service
|
||||
from tests.components.lock import common
|
||||
|
||||
FRONT = 'lock.front_door'
|
||||
KITCHEN = 'lock.kitchen_door'
|
||||
OPENABLE_LOCK = 'lock.openable_lock'
|
||||
@@ -36,14 +38,14 @@ class TestLockDemo(unittest.TestCase):
|
||||
|
||||
def test_locking(self):
|
||||
"""Test the locking of a lock."""
|
||||
lock.lock(self.hass, KITCHEN)
|
||||
common.lock(self.hass, KITCHEN)
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertTrue(lock.is_locked(self.hass, KITCHEN))
|
||||
|
||||
def test_unlocking(self):
|
||||
"""Test the unlocking of a lock."""
|
||||
lock.unlock(self.hass, FRONT)
|
||||
common.unlock(self.hass, FRONT)
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertFalse(lock.is_locked(self.hass, FRONT))
|
||||
@@ -51,6 +53,6 @@ class TestLockDemo(unittest.TestCase):
|
||||
def test_opening(self):
|
||||
"""Test the opening of a lock."""
|
||||
calls = mock_service(self.hass, lock.DOMAIN, lock.SERVICE_OPEN)
|
||||
lock.open_lock(self.hass, OPENABLE_LOCK)
|
||||
common.open_lock(self.hass, OPENABLE_LOCK)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(calls))
|
||||
@@ -6,9 +6,11 @@ from homeassistant.const import (
|
||||
STATE_LOCKED, STATE_UNLOCKED, STATE_UNAVAILABLE, ATTR_ASSUMED_STATE)
|
||||
import homeassistant.components.lock as lock
|
||||
from homeassistant.components.mqtt.discovery import async_start
|
||||
|
||||
from tests.common import (
|
||||
mock_mqtt_component, async_fire_mqtt_message, fire_mqtt_message,
|
||||
get_test_home_assistant)
|
||||
from tests.components.lock import common
|
||||
|
||||
|
||||
class TestLockMQTT(unittest.TestCase):
|
||||
@@ -69,7 +71,7 @@ class TestLockMQTT(unittest.TestCase):
|
||||
self.assertEqual(STATE_UNLOCKED, state.state)
|
||||
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
|
||||
lock.lock(self.hass, 'lock.test')
|
||||
common.lock(self.hass, 'lock.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.mock_publish.async_publish.assert_called_once_with(
|
||||
@@ -78,7 +80,7 @@ class TestLockMQTT(unittest.TestCase):
|
||||
state = self.hass.states.get('lock.test')
|
||||
self.assertEqual(STATE_LOCKED, state.state)
|
||||
|
||||
lock.unlock(self.hass, 'lock.test')
|
||||
common.unlock(self.hass, 'lock.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.mock_publish.async_publish.assert_called_once_with(
|
||||
|
||||
Reference in new issue
Block a user