Remove service helper (5) (#16917)
* Update switch * Update script * Update light * Fix tests * Fix config/script hook * Async_create_task * Fix flux switch
This commit is contained in:
1 parent
a7248d4574
commit
70b901017f
27 files changed
+385
-316
No files matched your search
@@ -15,6 +15,7 @@ from homeassistant.helpers.intent import IntentHandleError
|
||||
|
||||
from tests.common import (
|
||||
async_mock_service, mock_service, get_test_home_assistant, mock_storage)
|
||||
from tests.components.light import common
|
||||
|
||||
|
||||
class TestLight(unittest.TestCase):
|
||||
@@ -54,7 +55,7 @@ class TestLight(unittest.TestCase):
|
||||
turn_on_calls = mock_service(
|
||||
self.hass, light.DOMAIN, SERVICE_TURN_ON)
|
||||
|
||||
light.turn_on(
|
||||
common.turn_on(
|
||||
self.hass,
|
||||
entity_id='entity_id_val',
|
||||
transition='transition_val',
|
||||
@@ -88,7 +89,7 @@ class TestLight(unittest.TestCase):
|
||||
turn_off_calls = mock_service(
|
||||
self.hass, light.DOMAIN, SERVICE_TURN_OFF)
|
||||
|
||||
light.turn_off(
|
||||
common.turn_off(
|
||||
self.hass, entity_id='entity_id_val', transition='transition_val')
|
||||
|
||||
self.hass.block_till_done()
|
||||
@@ -105,7 +106,7 @@ class TestLight(unittest.TestCase):
|
||||
toggle_calls = mock_service(
|
||||
self.hass, light.DOMAIN, SERVICE_TOGGLE)
|
||||
|
||||
light.toggle(
|
||||
common.toggle(
|
||||
self.hass, entity_id='entity_id_val', transition='transition_val')
|
||||
|
||||
self.hass.block_till_done()
|
||||
@@ -135,8 +136,8 @@ class TestLight(unittest.TestCase):
|
||||
self.assertFalse(light.is_on(self.hass, dev3.entity_id))
|
||||
|
||||
# Test basic turn_on, turn_off, toggle services
|
||||
light.turn_off(self.hass, entity_id=dev1.entity_id)
|
||||
light.turn_on(self.hass, entity_id=dev2.entity_id)
|
||||
common.turn_off(self.hass, entity_id=dev1.entity_id)
|
||||
common.turn_on(self.hass, entity_id=dev2.entity_id)
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
@@ -144,7 +145,7 @@ class TestLight(unittest.TestCase):
|
||||
self.assertTrue(light.is_on(self.hass, dev2.entity_id))
|
||||
|
||||
# turn on all lights
|
||||
light.turn_on(self.hass)
|
||||
common.turn_on(self.hass)
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
@@ -153,7 +154,7 @@ class TestLight(unittest.TestCase):
|
||||
self.assertTrue(light.is_on(self.hass, dev3.entity_id))
|
||||
|
||||
# turn off all lights
|
||||
light.turn_off(self.hass)
|
||||
common.turn_off(self.hass)
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
@@ -162,7 +163,7 @@ class TestLight(unittest.TestCase):
|
||||
self.assertFalse(light.is_on(self.hass, dev3.entity_id))
|
||||
|
||||
# toggle all lights
|
||||
light.toggle(self.hass)
|
||||
common.toggle(self.hass)
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
@@ -171,7 +172,7 @@ class TestLight(unittest.TestCase):
|
||||
self.assertTrue(light.is_on(self.hass, dev3.entity_id))
|
||||
|
||||
# toggle all lights
|
||||
light.toggle(self.hass)
|
||||
common.toggle(self.hass)
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
@@ -180,12 +181,12 @@ class TestLight(unittest.TestCase):
|
||||
self.assertFalse(light.is_on(self.hass, dev3.entity_id))
|
||||
|
||||
# Ensure all attributes process correctly
|
||||
light.turn_on(self.hass, dev1.entity_id,
|
||||
transition=10, brightness=20, color_name='blue')
|
||||
light.turn_on(
|
||||
common.turn_on(self.hass, dev1.entity_id,
|
||||
transition=10, brightness=20, color_name='blue')
|
||||
common.turn_on(
|
||||
self.hass, dev2.entity_id, rgb_color=(255, 255, 255),
|
||||
white_value=255)
|
||||
light.turn_on(self.hass, dev3.entity_id, xy_color=(.4, .6))
|
||||
common.turn_on(self.hass, dev3.entity_id, xy_color=(.4, .6))
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
@@ -211,9 +212,9 @@ class TestLight(unittest.TestCase):
|
||||
prof_name, prof_h, prof_s, prof_bri = 'relax', 35.932, 69.412, 144
|
||||
|
||||
# Test light profiles
|
||||
light.turn_on(self.hass, dev1.entity_id, profile=prof_name)
|
||||
common.turn_on(self.hass, dev1.entity_id, profile=prof_name)
|
||||
# Specify a profile and a brightness attribute to overwrite it
|
||||
light.turn_on(
|
||||
common.turn_on(
|
||||
self.hass, dev2.entity_id,
|
||||
profile=prof_name, brightness=100)
|
||||
|
||||
@@ -232,10 +233,10 @@ class TestLight(unittest.TestCase):
|
||||
}, data)
|
||||
|
||||
# Test bad data
|
||||
light.turn_on(self.hass)
|
||||
light.turn_on(self.hass, dev1.entity_id, profile="nonexisting")
|
||||
light.turn_on(self.hass, dev2.entity_id, xy_color=["bla-di-bla", 5])
|
||||
light.turn_on(self.hass, dev3.entity_id, rgb_color=[255, None, 2])
|
||||
common.turn_on(self.hass)
|
||||
common.turn_on(self.hass, dev1.entity_id, profile="nonexisting")
|
||||
common.turn_on(self.hass, dev2.entity_id, xy_color=["bla-di-bla", 5])
|
||||
common.turn_on(self.hass, dev3.entity_id, rgb_color=[255, None, 2])
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
@@ -249,13 +250,13 @@ class TestLight(unittest.TestCase):
|
||||
self.assertEqual({}, data)
|
||||
|
||||
# faulty attributes will not trigger a service call
|
||||
light.turn_on(
|
||||
common.turn_on(
|
||||
self.hass, dev1.entity_id,
|
||||
profile=prof_name, brightness='bright')
|
||||
light.turn_on(
|
||||
common.turn_on(
|
||||
self.hass, dev1.entity_id,
|
||||
rgb_color='yellowish')
|
||||
light.turn_on(
|
||||
common.turn_on(
|
||||
self.hass, dev2.entity_id,
|
||||
white_value='high')
|
||||
|
||||
@@ -299,7 +300,7 @@ class TestLight(unittest.TestCase):
|
||||
|
||||
dev1, _, _ = platform.DEVICES
|
||||
|
||||
light.turn_on(self.hass, dev1.entity_id, profile='test')
|
||||
common.turn_on(self.hass, dev1.entity_id, profile='test')
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
@@ -340,7 +341,7 @@ class TestLight(unittest.TestCase):
|
||||
))
|
||||
|
||||
dev, _, _ = platform.DEVICES
|
||||
light.turn_on(self.hass, dev.entity_id)
|
||||
common.turn_on(self.hass, dev.entity_id)
|
||||
self.hass.block_till_done()
|
||||
_, data = dev.last_call('turn_on')
|
||||
self.assertEqual({
|
||||
@@ -380,7 +381,7 @@ class TestLight(unittest.TestCase):
|
||||
|
||||
dev = next(filter(lambda x: x.entity_id == 'light.ceiling_2',
|
||||
platform.DEVICES))
|
||||
light.turn_on(self.hass, dev.entity_id)
|
||||
common.turn_on(self.hass, dev.entity_id)
|
||||
self.hass.block_till_done()
|
||||
_, data = dev.last_call('turn_on')
|
||||
self.assertEqual({
|
||||
|
||||
Reference in new issue
Block a user