1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Rename MockToggleDevice to MockToggleEntity (#26644)

* Rename MockToggleDevice to MockToggleEntity

* Fix tests
This commit is contained in:
Erik Montnemery
2019-09-15 09:50:17 +02:00
committed by GitHub
parent 57833f5b1e
commit 6a60ebdb30
10 changed files with 200 additions and 198 deletions

View File

@@ -137,39 +137,39 @@ class TestLight(unittest.TestCase):
self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
dev1, dev2, dev3 = platform.DEVICES
ent1, ent2, ent3 = platform.ENTITIES
# Test init
assert light.is_on(self.hass, dev1.entity_id)
assert not light.is_on(self.hass, dev2.entity_id)
assert not light.is_on(self.hass, dev3.entity_id)
assert light.is_on(self.hass, ent1.entity_id)
assert not light.is_on(self.hass, ent2.entity_id)
assert not light.is_on(self.hass, ent3.entity_id)
# Test basic turn_on, turn_off, toggle services
common.turn_off(self.hass, entity_id=dev1.entity_id)
common.turn_on(self.hass, entity_id=dev2.entity_id)
common.turn_off(self.hass, entity_id=ent1.entity_id)
common.turn_on(self.hass, entity_id=ent2.entity_id)
self.hass.block_till_done()
assert not light.is_on(self.hass, dev1.entity_id)
assert light.is_on(self.hass, dev2.entity_id)
assert not light.is_on(self.hass, ent1.entity_id)
assert light.is_on(self.hass, ent2.entity_id)
# turn on all lights
common.turn_on(self.hass)
self.hass.block_till_done()
assert light.is_on(self.hass, dev1.entity_id)
assert light.is_on(self.hass, dev2.entity_id)
assert light.is_on(self.hass, dev3.entity_id)
assert light.is_on(self.hass, ent1.entity_id)
assert light.is_on(self.hass, ent2.entity_id)
assert light.is_on(self.hass, ent3.entity_id)
# turn off all lights
common.turn_off(self.hass)
self.hass.block_till_done()
assert not light.is_on(self.hass, dev1.entity_id)
assert not light.is_on(self.hass, dev2.entity_id)
assert not light.is_on(self.hass, dev3.entity_id)
assert not light.is_on(self.hass, ent1.entity_id)
assert not light.is_on(self.hass, ent2.entity_id)
assert not light.is_on(self.hass, ent3.entity_id)
# turn off all lights by setting brightness to 0
common.turn_on(self.hass)
@@ -180,97 +180,97 @@ class TestLight(unittest.TestCase):
self.hass.block_till_done()
assert not light.is_on(self.hass, dev1.entity_id)
assert not light.is_on(self.hass, dev2.entity_id)
assert not light.is_on(self.hass, dev3.entity_id)
assert not light.is_on(self.hass, ent1.entity_id)
assert not light.is_on(self.hass, ent2.entity_id)
assert not light.is_on(self.hass, ent3.entity_id)
# toggle all lights
common.toggle(self.hass)
self.hass.block_till_done()
assert light.is_on(self.hass, dev1.entity_id)
assert light.is_on(self.hass, dev2.entity_id)
assert light.is_on(self.hass, dev3.entity_id)
assert light.is_on(self.hass, ent1.entity_id)
assert light.is_on(self.hass, ent2.entity_id)
assert light.is_on(self.hass, ent3.entity_id)
# toggle all lights
common.toggle(self.hass)
self.hass.block_till_done()
assert not light.is_on(self.hass, dev1.entity_id)
assert not light.is_on(self.hass, dev2.entity_id)
assert not light.is_on(self.hass, dev3.entity_id)
assert not light.is_on(self.hass, ent1.entity_id)
assert not light.is_on(self.hass, ent2.entity_id)
assert not light.is_on(self.hass, ent3.entity_id)
# Ensure all attributes process correctly
common.turn_on(
self.hass, dev1.entity_id, transition=10, brightness=20, color_name="blue"
self.hass, ent1.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
self.hass, ent2.entity_id, rgb_color=(255, 255, 255), white_value=255
)
common.turn_on(self.hass, dev3.entity_id, xy_color=(0.4, 0.6))
common.turn_on(self.hass, ent3.entity_id, xy_color=(0.4, 0.6))
self.hass.block_till_done()
_, data = dev1.last_call("turn_on")
_, data = ent1.last_call("turn_on")
assert {
light.ATTR_TRANSITION: 10,
light.ATTR_BRIGHTNESS: 20,
light.ATTR_HS_COLOR: (240, 100),
} == data
_, data = dev2.last_call("turn_on")
_, data = ent2.last_call("turn_on")
assert {light.ATTR_HS_COLOR: (0, 0), light.ATTR_WHITE_VALUE: 255} == data
_, data = dev3.last_call("turn_on")
_, data = ent3.last_call("turn_on")
assert {light.ATTR_HS_COLOR: (71.059, 100)} == data
# Ensure attributes are filtered when light is turned off
common.turn_on(
self.hass, dev1.entity_id, transition=10, brightness=0, color_name="blue"
self.hass, ent1.entity_id, transition=10, brightness=0, color_name="blue"
)
common.turn_on(
self.hass,
dev2.entity_id,
ent2.entity_id,
brightness=0,
rgb_color=(255, 255, 255),
white_value=0,
)
common.turn_on(self.hass, dev3.entity_id, brightness=0, xy_color=(0.4, 0.6))
common.turn_on(self.hass, ent3.entity_id, brightness=0, xy_color=(0.4, 0.6))
self.hass.block_till_done()
assert not light.is_on(self.hass, dev1.entity_id)
assert not light.is_on(self.hass, dev2.entity_id)
assert not light.is_on(self.hass, dev3.entity_id)
assert not light.is_on(self.hass, ent1.entity_id)
assert not light.is_on(self.hass, ent2.entity_id)
assert not light.is_on(self.hass, ent3.entity_id)
_, data = dev1.last_call("turn_off")
_, data = ent1.last_call("turn_off")
assert {light.ATTR_TRANSITION: 10} == data
_, data = dev2.last_call("turn_off")
_, data = ent2.last_call("turn_off")
assert {} == data
_, data = dev3.last_call("turn_off")
_, data = ent3.last_call("turn_off")
assert {} == data
# One of the light profiles
prof_name, prof_h, prof_s, prof_bri = "relax", 35.932, 69.412, 144
# Test light profiles
common.turn_on(self.hass, dev1.entity_id, profile=prof_name)
common.turn_on(self.hass, ent1.entity_id, profile=prof_name)
# Specify a profile and a brightness attribute to overwrite it
common.turn_on(self.hass, dev2.entity_id, profile=prof_name, brightness=100)
common.turn_on(self.hass, ent2.entity_id, profile=prof_name, brightness=100)
self.hass.block_till_done()
_, data = dev1.last_call("turn_on")
_, data = ent1.last_call("turn_on")
assert {
light.ATTR_BRIGHTNESS: prof_bri,
light.ATTR_HS_COLOR: (prof_h, prof_s),
} == data
_, data = dev2.last_call("turn_on")
_, data = ent2.last_call("turn_on")
assert {
light.ATTR_BRIGHTNESS: 100,
light.ATTR_HS_COLOR: (prof_h, prof_s),
@@ -278,34 +278,34 @@ class TestLight(unittest.TestCase):
# Test bad data
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])
common.turn_on(self.hass, ent1.entity_id, profile="nonexisting")
common.turn_on(self.hass, ent2.entity_id, xy_color=["bla-di-bla", 5])
common.turn_on(self.hass, ent3.entity_id, rgb_color=[255, None, 2])
self.hass.block_till_done()
_, data = dev1.last_call("turn_on")
_, data = ent1.last_call("turn_on")
assert {} == data
_, data = dev2.last_call("turn_on")
_, data = ent2.last_call("turn_on")
assert {} == data
_, data = dev3.last_call("turn_on")
_, data = ent3.last_call("turn_on")
assert {} == data
# faulty attributes will not trigger a service call
common.turn_on(
self.hass, dev1.entity_id, profile=prof_name, brightness="bright"
self.hass, ent1.entity_id, profile=prof_name, brightness="bright"
)
common.turn_on(self.hass, dev1.entity_id, rgb_color="yellowish")
common.turn_on(self.hass, dev2.entity_id, white_value="high")
common.turn_on(self.hass, ent1.entity_id, rgb_color="yellowish")
common.turn_on(self.hass, ent2.entity_id, white_value="high")
self.hass.block_till_done()
_, data = dev1.last_call("turn_on")
_, data = ent1.last_call("turn_on")
assert {} == data
_, data = dev2.last_call("turn_on")
_, data = ent2.last_call("turn_on")
assert {} == data
def test_broken_light_profiles(self):
@@ -340,24 +340,24 @@ class TestLight(unittest.TestCase):
self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
dev1, _, _ = platform.DEVICES
ent1, _, _ = platform.ENTITIES
common.turn_on(self.hass, dev1.entity_id, profile="test")
common.turn_on(self.hass, ent1.entity_id, profile="test")
self.hass.block_till_done()
_, data = dev1.last_call("turn_on")
_, data = ent1.last_call("turn_on")
assert light.is_on(self.hass, dev1.entity_id)
assert light.is_on(self.hass, ent1.entity_id)
assert {light.ATTR_HS_COLOR: (71.059, 100), light.ATTR_BRIGHTNESS: 100} == data
common.turn_on(self.hass, dev1.entity_id, profile="test_off")
common.turn_on(self.hass, ent1.entity_id, profile="test_off")
self.hass.block_till_done()
_, data = dev1.last_call("turn_off")
_, data = ent1.last_call("turn_off")
assert not light.is_on(self.hass, dev1.entity_id)
assert not light.is_on(self.hass, ent1.entity_id)
assert {} == data
def test_default_profiles_group(self):
@@ -387,10 +387,10 @@ class TestLight(unittest.TestCase):
self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
dev, _, _ = platform.DEVICES
common.turn_on(self.hass, dev.entity_id)
ent, _, _ = platform.ENTITIES
common.turn_on(self.hass, ent.entity_id)
self.hass.block_till_done()
_, data = dev.last_call("turn_on")
_, data = ent.last_call("turn_on")
assert {light.ATTR_HS_COLOR: (71.059, 100), light.ATTR_BRIGHTNESS: 99} == data
def test_default_profiles_light(self):
@@ -424,7 +424,9 @@ class TestLight(unittest.TestCase):
self.hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
)
dev = next(filter(lambda x: x.entity_id == "light.ceiling_2", platform.DEVICES))
dev = next(
filter(lambda x: x.entity_id == "light.ceiling_2", platform.ENTITIES)
)
common.turn_on(self.hass, dev.entity_id)
self.hass.block_till_done()
_, data = dev.last_call("turn_on")