Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -4,10 +4,18 @@ 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_ADD_ENTITIES, ATTR_CONTROL, ATTR_ENTITIES, ATTR_OBJECT_ID, ATTR_VIEW,
|
||||
ATTR_VISIBLE, DOMAIN, SERVICE_REMOVE, SERVICE_SET, SERVICE_SET_VISIBILITY)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, ATTR_ICON, ATTR_NAME, SERVICE_RELOAD)
|
||||
ATTR_ADD_ENTITIES,
|
||||
ATTR_CONTROL,
|
||||
ATTR_ENTITIES,
|
||||
ATTR_OBJECT_ID,
|
||||
ATTR_VIEW,
|
||||
ATTR_VISIBLE,
|
||||
DOMAIN,
|
||||
SERVICE_REMOVE,
|
||||
SERVICE_SET,
|
||||
SERVICE_SET_VISIBILITY,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_ICON, ATTR_NAME, SERVICE_RELOAD
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
@@ -26,21 +34,49 @@ def async_reload(hass):
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_group(hass, object_id, name=None, entity_ids=None, visible=None,
|
||||
icon=None, view=None, control=None, add=None):
|
||||
def set_group(
|
||||
hass,
|
||||
object_id,
|
||||
name=None,
|
||||
entity_ids=None,
|
||||
visible=None,
|
||||
icon=None,
|
||||
view=None,
|
||||
control=None,
|
||||
add=None,
|
||||
):
|
||||
"""Create/Update a group."""
|
||||
hass.add_job(
|
||||
async_set_group, hass, object_id, name, entity_ids, visible, icon,
|
||||
view, control, add)
|
||||
async_set_group,
|
||||
hass,
|
||||
object_id,
|
||||
name,
|
||||
entity_ids,
|
||||
visible,
|
||||
icon,
|
||||
view,
|
||||
control,
|
||||
add,
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_set_group(hass, object_id, name=None, entity_ids=None, visible=None,
|
||||
icon=None, view=None, control=None, add=None):
|
||||
def async_set_group(
|
||||
hass,
|
||||
object_id,
|
||||
name=None,
|
||||
entity_ids=None,
|
||||
visible=None,
|
||||
icon=None,
|
||||
view=None,
|
||||
control=None,
|
||||
add=None,
|
||||
):
|
||||
"""Create/Update a group."""
|
||||
data = {
|
||||
key: value for key, value in [
|
||||
key: value
|
||||
for key, value in [
|
||||
(ATTR_OBJECT_ID, object_id),
|
||||
(ATTR_NAME, name),
|
||||
(ATTR_ENTITIES, entity_ids),
|
||||
@@ -49,7 +85,8 @@ def async_set_group(hass, object_id, name=None, entity_ids=None, visible=None,
|
||||
(ATTR_VIEW, view),
|
||||
(ATTR_CONTROL, control),
|
||||
(ATTR_ADD_ENTITIES, add),
|
||||
] if value is not None
|
||||
]
|
||||
if value is not None
|
||||
}
|
||||
|
||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_SET, data))
|
||||
|
||||
@@ -4,34 +4,50 @@ from datetime import timedelta
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
ATTR_CURRENT_POSITION, ATTR_CURRENT_TILT_POSITION, ATTR_POSITION,
|
||||
ATTR_TILT_POSITION, DOMAIN)
|
||||
ATTR_CURRENT_POSITION,
|
||||
ATTR_CURRENT_TILT_POSITION,
|
||||
ATTR_POSITION,
|
||||
ATTR_TILT_POSITION,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.components.group.cover import DEFAULT_NAME
|
||||
from homeassistant.const import (
|
||||
ATTR_ASSUMED_STATE, ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME,
|
||||
ATTR_SUPPORTED_FEATURES, CONF_ENTITIES,
|
||||
SERVICE_CLOSE_COVER, SERVICE_CLOSE_COVER_TILT,
|
||||
SERVICE_TOGGLE, SERVICE_TOGGLE_COVER_TILT,
|
||||
SERVICE_OPEN_COVER, SERVICE_OPEN_COVER_TILT, SERVICE_SET_COVER_POSITION,
|
||||
SERVICE_SET_COVER_TILT_POSITION, SERVICE_STOP_COVER,
|
||||
SERVICE_STOP_COVER_TILT, STATE_OPEN, STATE_CLOSED)
|
||||
ATTR_ASSUMED_STATE,
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_FRIENDLY_NAME,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
CONF_ENTITIES,
|
||||
SERVICE_CLOSE_COVER,
|
||||
SERVICE_CLOSE_COVER_TILT,
|
||||
SERVICE_TOGGLE,
|
||||
SERVICE_TOGGLE_COVER_TILT,
|
||||
SERVICE_OPEN_COVER,
|
||||
SERVICE_OPEN_COVER_TILT,
|
||||
SERVICE_SET_COVER_POSITION,
|
||||
SERVICE_SET_COVER_TILT_POSITION,
|
||||
SERVICE_STOP_COVER,
|
||||
SERVICE_STOP_COVER_TILT,
|
||||
STATE_OPEN,
|
||||
STATE_CLOSED,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.common import assert_setup_component, async_fire_time_changed
|
||||
|
||||
COVER_GROUP = 'cover.cover_group'
|
||||
DEMO_COVER = 'cover.kitchen_window'
|
||||
DEMO_COVER_POS = 'cover.hall_window'
|
||||
DEMO_COVER_TILT = 'cover.living_room_window'
|
||||
DEMO_TILT = 'cover.tilt_demo'
|
||||
COVER_GROUP = "cover.cover_group"
|
||||
DEMO_COVER = "cover.kitchen_window"
|
||||
DEMO_COVER_POS = "cover.hall_window"
|
||||
DEMO_COVER_TILT = "cover.living_room_window"
|
||||
DEMO_TILT = "cover.tilt_demo"
|
||||
|
||||
CONFIG = {
|
||||
DOMAIN: [
|
||||
{'platform': 'demo'},
|
||||
{'platform': 'group',
|
||||
CONF_ENTITIES: [
|
||||
DEMO_COVER, DEMO_COVER_POS, DEMO_COVER_TILT, DEMO_TILT]}
|
||||
{"platform": "demo"},
|
||||
{
|
||||
"platform": "group",
|
||||
CONF_ENTITIES: [DEMO_COVER, DEMO_COVER_POS, DEMO_COVER_TILT, DEMO_TILT],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@@ -45,8 +61,12 @@ async def setup_comp(hass):
|
||||
|
||||
async def test_attributes(hass):
|
||||
"""Test handling of state attributes."""
|
||||
config = {DOMAIN: {'platform': 'group', CONF_ENTITIES: [
|
||||
DEMO_COVER, DEMO_COVER_POS, DEMO_COVER_TILT, DEMO_TILT]}}
|
||||
config = {
|
||||
DOMAIN: {
|
||||
"platform": "group",
|
||||
CONF_ENTITIES: [DEMO_COVER, DEMO_COVER_POS, DEMO_COVER_TILT, DEMO_TILT],
|
||||
}
|
||||
}
|
||||
|
||||
with assert_setup_component(1, DOMAIN):
|
||||
await async_setup_component(hass, DOMAIN, config)
|
||||
@@ -60,8 +80,7 @@ async def test_attributes(hass):
|
||||
assert ATTR_CURRENT_TILT_POSITION not in state.attributes
|
||||
|
||||
# Add Entity that supports open / close / stop
|
||||
hass.states.async_set(
|
||||
DEMO_COVER, STATE_OPEN, {ATTR_SUPPORTED_FEATURES: 11})
|
||||
hass.states.async_set(DEMO_COVER, STATE_OPEN, {ATTR_SUPPORTED_FEATURES: 11})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(COVER_GROUP)
|
||||
@@ -73,8 +92,10 @@ async def test_attributes(hass):
|
||||
|
||||
# Add Entity that supports set_cover_position
|
||||
hass.states.async_set(
|
||||
DEMO_COVER_POS, STATE_OPEN,
|
||||
{ATTR_SUPPORTED_FEATURES: 4, ATTR_CURRENT_POSITION: 70})
|
||||
DEMO_COVER_POS,
|
||||
STATE_OPEN,
|
||||
{ATTR_SUPPORTED_FEATURES: 4, ATTR_CURRENT_POSITION: 70},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(COVER_GROUP)
|
||||
@@ -85,8 +106,7 @@ async def test_attributes(hass):
|
||||
assert ATTR_CURRENT_TILT_POSITION not in state.attributes
|
||||
|
||||
# Add Entity that supports open tilt / close tilt / stop tilt
|
||||
hass.states.async_set(
|
||||
DEMO_TILT, STATE_OPEN, {ATTR_SUPPORTED_FEATURES: 112})
|
||||
hass.states.async_set(DEMO_TILT, STATE_OPEN, {ATTR_SUPPORTED_FEATURES: 112})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(COVER_GROUP)
|
||||
@@ -98,8 +118,10 @@ async def test_attributes(hass):
|
||||
|
||||
# Add Entity that supports set_tilt_position
|
||||
hass.states.async_set(
|
||||
DEMO_COVER_TILT, STATE_OPEN,
|
||||
{ATTR_SUPPORTED_FEATURES: 128, ATTR_CURRENT_TILT_POSITION: 60})
|
||||
DEMO_COVER_TILT,
|
||||
STATE_OPEN,
|
||||
{ATTR_SUPPORTED_FEATURES: 128, ATTR_CURRENT_TILT_POSITION: 60},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(COVER_GROUP)
|
||||
@@ -114,8 +136,8 @@ async def test_attributes(hass):
|
||||
|
||||
# For covers
|
||||
hass.states.async_set(
|
||||
DEMO_COVER, STATE_OPEN,
|
||||
{ATTR_SUPPORTED_FEATURES: 4, ATTR_CURRENT_POSITION: 100})
|
||||
DEMO_COVER, STATE_OPEN, {ATTR_SUPPORTED_FEATURES: 4, ATTR_CURRENT_POSITION: 100}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(COVER_GROUP)
|
||||
@@ -138,8 +160,10 @@ async def test_attributes(hass):
|
||||
|
||||
# For tilts
|
||||
hass.states.async_set(
|
||||
DEMO_TILT, STATE_OPEN,
|
||||
{ATTR_SUPPORTED_FEATURES: 128, ATTR_CURRENT_TILT_POSITION: 100})
|
||||
DEMO_TILT,
|
||||
STATE_OPEN,
|
||||
{ATTR_SUPPORTED_FEATURES: 128, ATTR_CURRENT_TILT_POSITION: 100},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(COVER_GROUP)
|
||||
@@ -160,8 +184,7 @@ async def test_attributes(hass):
|
||||
assert ATTR_CURRENT_POSITION not in state.attributes
|
||||
assert ATTR_CURRENT_TILT_POSITION not in state.attributes
|
||||
|
||||
hass.states.async_set(
|
||||
DEMO_TILT, STATE_CLOSED, {ATTR_ASSUMED_STATE: True})
|
||||
hass.states.async_set(DEMO_TILT, STATE_CLOSED, {ATTR_ASSUMED_STATE: True})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(COVER_GROUP)
|
||||
@@ -171,8 +194,8 @@ async def test_attributes(hass):
|
||||
async def test_open_covers(hass, setup_comp):
|
||||
"""Test open cover function."""
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_OPEN_COVER,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
|
||||
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
|
||||
)
|
||||
for _ in range(10):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
@@ -183,17 +206,15 @@ async def test_open_covers(hass, setup_comp):
|
||||
assert state.attributes[ATTR_CURRENT_POSITION] == 100
|
||||
|
||||
assert hass.states.get(DEMO_COVER).state == STATE_OPEN
|
||||
assert hass.states.get(DEMO_COVER_POS) \
|
||||
.attributes[ATTR_CURRENT_POSITION] == 100
|
||||
assert hass.states.get(DEMO_COVER_TILT) \
|
||||
.attributes[ATTR_CURRENT_POSITION] == 100
|
||||
assert hass.states.get(DEMO_COVER_POS).attributes[ATTR_CURRENT_POSITION] == 100
|
||||
assert hass.states.get(DEMO_COVER_TILT).attributes[ATTR_CURRENT_POSITION] == 100
|
||||
|
||||
|
||||
async def test_close_covers(hass, setup_comp):
|
||||
"""Test close cover function."""
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_CLOSE_COVER,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
|
||||
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
|
||||
)
|
||||
for _ in range(10):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
@@ -204,18 +225,16 @@ async def test_close_covers(hass, setup_comp):
|
||||
assert state.attributes[ATTR_CURRENT_POSITION] == 0
|
||||
|
||||
assert hass.states.get(DEMO_COVER).state == STATE_CLOSED
|
||||
assert hass.states.get(DEMO_COVER_POS) \
|
||||
.attributes[ATTR_CURRENT_POSITION] == 0
|
||||
assert hass.states.get(DEMO_COVER_TILT) \
|
||||
.attributes[ATTR_CURRENT_POSITION] == 0
|
||||
assert hass.states.get(DEMO_COVER_POS).attributes[ATTR_CURRENT_POSITION] == 0
|
||||
assert hass.states.get(DEMO_COVER_TILT).attributes[ATTR_CURRENT_POSITION] == 0
|
||||
|
||||
|
||||
async def test_toggle_covers(hass, setup_comp):
|
||||
"""Test toggle cover function."""
|
||||
# Start covers in open state
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_OPEN_COVER,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
|
||||
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
|
||||
)
|
||||
for _ in range(10):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
@@ -226,8 +245,8 @@ async def test_toggle_covers(hass, setup_comp):
|
||||
|
||||
# Toggle will close covers
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_TOGGLE,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
|
||||
DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
|
||||
)
|
||||
for _ in range(10):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
@@ -238,15 +257,13 @@ async def test_toggle_covers(hass, setup_comp):
|
||||
assert state.attributes[ATTR_CURRENT_POSITION] == 0
|
||||
|
||||
assert hass.states.get(DEMO_COVER).state == STATE_CLOSED
|
||||
assert hass.states.get(DEMO_COVER_POS) \
|
||||
.attributes[ATTR_CURRENT_POSITION] == 0
|
||||
assert hass.states.get(DEMO_COVER_TILT) \
|
||||
.attributes[ATTR_CURRENT_POSITION] == 0
|
||||
assert hass.states.get(DEMO_COVER_POS).attributes[ATTR_CURRENT_POSITION] == 0
|
||||
assert hass.states.get(DEMO_COVER_TILT).attributes[ATTR_CURRENT_POSITION] == 0
|
||||
|
||||
# Toggle again will open covers
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_TOGGLE,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
|
||||
DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
|
||||
)
|
||||
for _ in range(10):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
@@ -257,24 +274,22 @@ async def test_toggle_covers(hass, setup_comp):
|
||||
assert state.attributes[ATTR_CURRENT_POSITION] == 100
|
||||
|
||||
assert hass.states.get(DEMO_COVER).state == STATE_OPEN
|
||||
assert hass.states.get(DEMO_COVER_POS) \
|
||||
.attributes[ATTR_CURRENT_POSITION] == 100
|
||||
assert hass.states.get(DEMO_COVER_TILT) \
|
||||
.attributes[ATTR_CURRENT_POSITION] == 100
|
||||
assert hass.states.get(DEMO_COVER_POS).attributes[ATTR_CURRENT_POSITION] == 100
|
||||
assert hass.states.get(DEMO_COVER_TILT).attributes[ATTR_CURRENT_POSITION] == 100
|
||||
|
||||
|
||||
async def test_stop_covers(hass, setup_comp):
|
||||
"""Test stop cover function."""
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_OPEN_COVER,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
|
||||
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
|
||||
)
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_STOP_COVER,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
|
||||
DOMAIN, SERVICE_STOP_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
|
||||
)
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
await hass.async_block_till_done()
|
||||
@@ -284,17 +299,18 @@ async def test_stop_covers(hass, setup_comp):
|
||||
assert state.attributes[ATTR_CURRENT_POSITION] == 100
|
||||
|
||||
assert hass.states.get(DEMO_COVER).state == STATE_OPEN
|
||||
assert hass.states.get(DEMO_COVER_POS) \
|
||||
.attributes[ATTR_CURRENT_POSITION] == 20
|
||||
assert hass.states.get(DEMO_COVER_TILT) \
|
||||
.attributes[ATTR_CURRENT_POSITION] == 80
|
||||
assert hass.states.get(DEMO_COVER_POS).attributes[ATTR_CURRENT_POSITION] == 20
|
||||
assert hass.states.get(DEMO_COVER_TILT).attributes[ATTR_CURRENT_POSITION] == 80
|
||||
|
||||
|
||||
async def test_set_cover_position(hass, setup_comp):
|
||||
"""Test set cover position function."""
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_SET_COVER_POSITION,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP, ATTR_POSITION: 50}, blocking=True)
|
||||
DOMAIN,
|
||||
SERVICE_SET_COVER_POSITION,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP, ATTR_POSITION: 50},
|
||||
blocking=True,
|
||||
)
|
||||
for _ in range(4):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
@@ -305,17 +321,15 @@ async def test_set_cover_position(hass, setup_comp):
|
||||
assert state.attributes[ATTR_CURRENT_POSITION] == 50
|
||||
|
||||
assert hass.states.get(DEMO_COVER).state == STATE_CLOSED
|
||||
assert hass.states.get(DEMO_COVER_POS) \
|
||||
.attributes[ATTR_CURRENT_POSITION] == 50
|
||||
assert hass.states.get(DEMO_COVER_TILT) \
|
||||
.attributes[ATTR_CURRENT_POSITION] == 50
|
||||
assert hass.states.get(DEMO_COVER_POS).attributes[ATTR_CURRENT_POSITION] == 50
|
||||
assert hass.states.get(DEMO_COVER_TILT).attributes[ATTR_CURRENT_POSITION] == 50
|
||||
|
||||
|
||||
async def test_open_tilts(hass, setup_comp):
|
||||
"""Test open tilt function."""
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_OPEN_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
|
||||
DOMAIN, SERVICE_OPEN_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
|
||||
)
|
||||
for _ in range(5):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
@@ -325,15 +339,16 @@ async def test_open_tilts(hass, setup_comp):
|
||||
assert state.state == STATE_OPEN
|
||||
assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 100
|
||||
|
||||
assert hass.states.get(DEMO_COVER_TILT) \
|
||||
.attributes[ATTR_CURRENT_TILT_POSITION] == 100
|
||||
assert (
|
||||
hass.states.get(DEMO_COVER_TILT).attributes[ATTR_CURRENT_TILT_POSITION] == 100
|
||||
)
|
||||
|
||||
|
||||
async def test_close_tilts(hass, setup_comp):
|
||||
"""Test close tilt function."""
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_CLOSE_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
|
||||
DOMAIN, SERVICE_CLOSE_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
|
||||
)
|
||||
for _ in range(5):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
@@ -343,16 +358,15 @@ async def test_close_tilts(hass, setup_comp):
|
||||
assert state.state == STATE_OPEN
|
||||
assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 0
|
||||
|
||||
assert hass.states.get(DEMO_COVER_TILT) \
|
||||
.attributes[ATTR_CURRENT_TILT_POSITION] == 0
|
||||
assert hass.states.get(DEMO_COVER_TILT).attributes[ATTR_CURRENT_TILT_POSITION] == 0
|
||||
|
||||
|
||||
async def test_toggle_tilts(hass, setup_comp):
|
||||
"""Test toggle tilt function."""
|
||||
# Start tilted open
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_OPEN_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
|
||||
DOMAIN, SERVICE_OPEN_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
|
||||
)
|
||||
for _ in range(10):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
@@ -362,13 +376,14 @@ async def test_toggle_tilts(hass, setup_comp):
|
||||
assert state.state == STATE_OPEN
|
||||
assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 100
|
||||
|
||||
assert hass.states.get(DEMO_COVER_TILT) \
|
||||
.attributes[ATTR_CURRENT_TILT_POSITION] == 100
|
||||
assert (
|
||||
hass.states.get(DEMO_COVER_TILT).attributes[ATTR_CURRENT_TILT_POSITION] == 100
|
||||
)
|
||||
|
||||
# Toggle will tilt closed
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_TOGGLE_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
|
||||
DOMAIN, SERVICE_TOGGLE_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
|
||||
)
|
||||
for _ in range(10):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
@@ -378,13 +393,12 @@ async def test_toggle_tilts(hass, setup_comp):
|
||||
assert state.state == STATE_OPEN
|
||||
assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 0
|
||||
|
||||
assert hass.states.get(DEMO_COVER_TILT) \
|
||||
.attributes[ATTR_CURRENT_TILT_POSITION] == 0
|
||||
assert hass.states.get(DEMO_COVER_TILT).attributes[ATTR_CURRENT_TILT_POSITION] == 0
|
||||
|
||||
# Toggle again will tilt open
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_TOGGLE_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
|
||||
DOMAIN, SERVICE_TOGGLE_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
|
||||
)
|
||||
for _ in range(10):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
@@ -394,22 +408,23 @@ async def test_toggle_tilts(hass, setup_comp):
|
||||
assert state.state == STATE_OPEN
|
||||
assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 100
|
||||
|
||||
assert hass.states.get(DEMO_COVER_TILT) \
|
||||
.attributes[ATTR_CURRENT_TILT_POSITION] == 100
|
||||
assert (
|
||||
hass.states.get(DEMO_COVER_TILT).attributes[ATTR_CURRENT_TILT_POSITION] == 100
|
||||
)
|
||||
|
||||
|
||||
async def test_stop_tilts(hass, setup_comp):
|
||||
"""Test stop tilts function."""
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_OPEN_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
|
||||
DOMAIN, SERVICE_OPEN_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
|
||||
)
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_STOP_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
|
||||
DOMAIN, SERVICE_STOP_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
|
||||
)
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
await hass.async_block_till_done()
|
||||
@@ -418,15 +433,17 @@ async def test_stop_tilts(hass, setup_comp):
|
||||
assert state.state == STATE_OPEN
|
||||
assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 60
|
||||
|
||||
assert hass.states.get(DEMO_COVER_TILT) \
|
||||
.attributes[ATTR_CURRENT_TILT_POSITION] == 60
|
||||
assert hass.states.get(DEMO_COVER_TILT).attributes[ATTR_CURRENT_TILT_POSITION] == 60
|
||||
|
||||
|
||||
async def test_set_tilt_positions(hass, setup_comp):
|
||||
"""Test set tilt position function."""
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_SET_COVER_TILT_POSITION,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP, ATTR_TILT_POSITION: 80}, blocking=True)
|
||||
DOMAIN,
|
||||
SERVICE_SET_COVER_TILT_POSITION,
|
||||
{ATTR_ENTITY_ID: COVER_GROUP, ATTR_TILT_POSITION: 80},
|
||||
blocking=True,
|
||||
)
|
||||
for _ in range(3):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
@@ -436,5 +453,4 @@ async def test_set_tilt_positions(hass, setup_comp):
|
||||
assert state.state == STATE_OPEN
|
||||
assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 80
|
||||
|
||||
assert hass.states.get(DEMO_COVER_TILT) \
|
||||
.attributes[ATTR_CURRENT_TILT_POSITION] == 80
|
||||
assert hass.states.get(DEMO_COVER_TILT).attributes[ATTR_CURRENT_TILT_POSITION] == 80
|
||||
+243
-202
@@ -7,8 +7,16 @@ from unittest.mock import patch
|
||||
|
||||
from homeassistant.setup import setup_component, async_setup_component
|
||||
from homeassistant.const import (
|
||||
STATE_ON, STATE_OFF, STATE_HOME, STATE_UNKNOWN, ATTR_ICON, ATTR_HIDDEN,
|
||||
ATTR_ASSUMED_STATE, STATE_NOT_HOME, ATTR_FRIENDLY_NAME)
|
||||
STATE_ON,
|
||||
STATE_OFF,
|
||||
STATE_HOME,
|
||||
STATE_UNKNOWN,
|
||||
ATTR_ICON,
|
||||
ATTR_HIDDEN,
|
||||
ATTR_ASSUMED_STATE,
|
||||
STATE_NOT_HOME,
|
||||
ATTR_FRIENDLY_NAME,
|
||||
)
|
||||
import homeassistant.components.group as group
|
||||
|
||||
from tests.common import get_test_home_assistant, assert_setup_component
|
||||
@@ -30,49 +38,53 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
|
||||
def test_setup_group_with_mixed_groupable_states(self):
|
||||
"""Try to set up a group with mixed groupable states."""
|
||||
self.hass.states.set('light.Bowl', STATE_ON)
|
||||
self.hass.states.set('device_tracker.Paulus', STATE_HOME)
|
||||
self.hass.states.set("light.Bowl", STATE_ON)
|
||||
self.hass.states.set("device_tracker.Paulus", STATE_HOME)
|
||||
group.Group.create_group(
|
||||
self.hass, 'person_and_light',
|
||||
['light.Bowl', 'device_tracker.Paulus'])
|
||||
self.hass, "person_and_light", ["light.Bowl", "device_tracker.Paulus"]
|
||||
)
|
||||
|
||||
assert STATE_ON == \
|
||||
self.hass.states.get(
|
||||
group.ENTITY_ID_FORMAT.format('person_and_light')).state
|
||||
assert (
|
||||
STATE_ON
|
||||
== self.hass.states.get(
|
||||
group.ENTITY_ID_FORMAT.format("person_and_light")
|
||||
).state
|
||||
)
|
||||
|
||||
def test_setup_group_with_a_non_existing_state(self):
|
||||
"""Try to set up a group with a non existing state."""
|
||||
self.hass.states.set('light.Bowl', STATE_ON)
|
||||
self.hass.states.set("light.Bowl", STATE_ON)
|
||||
|
||||
grp = group.Group.create_group(
|
||||
self.hass, 'light_and_nothing',
|
||||
['light.Bowl', 'non.existing'])
|
||||
self.hass, "light_and_nothing", ["light.Bowl", "non.existing"]
|
||||
)
|
||||
|
||||
assert STATE_ON == grp.state
|
||||
|
||||
def test_setup_group_with_non_groupable_states(self):
|
||||
"""Test setup with groups which are not groupable."""
|
||||
self.hass.states.set('cast.living_room', "Plex")
|
||||
self.hass.states.set('cast.bedroom', "Netflix")
|
||||
self.hass.states.set("cast.living_room", "Plex")
|
||||
self.hass.states.set("cast.bedroom", "Netflix")
|
||||
|
||||
grp = group.Group.create_group(
|
||||
self.hass, 'chromecasts',
|
||||
['cast.living_room', 'cast.bedroom'])
|
||||
self.hass, "chromecasts", ["cast.living_room", "cast.bedroom"]
|
||||
)
|
||||
|
||||
assert STATE_UNKNOWN == grp.state
|
||||
|
||||
def test_setup_empty_group(self):
|
||||
"""Try to set up an empty group."""
|
||||
grp = group.Group.create_group(self.hass, 'nothing', [])
|
||||
grp = group.Group.create_group(self.hass, "nothing", [])
|
||||
|
||||
assert STATE_UNKNOWN == grp.state
|
||||
|
||||
def test_monitor_group(self):
|
||||
"""Test if the group keeps track of states."""
|
||||
self.hass.states.set('light.Bowl', STATE_ON)
|
||||
self.hass.states.set('light.Ceiling', STATE_OFF)
|
||||
self.hass.states.set("light.Bowl", STATE_ON)
|
||||
self.hass.states.set("light.Ceiling", STATE_OFF)
|
||||
test_group = group.Group.create_group(
|
||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
||||
self.hass, "init_group", ["light.Bowl", "light.Ceiling"], False
|
||||
)
|
||||
|
||||
# Test if group setup in our init mode is ok
|
||||
assert test_group.entity_id in self.hass.states.entity_ids()
|
||||
@@ -83,10 +95,11 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
|
||||
def test_group_turns_off_if_all_off(self):
|
||||
"""Test if turn off if the last device that was on turns off."""
|
||||
self.hass.states.set('light.Bowl', STATE_OFF)
|
||||
self.hass.states.set('light.Ceiling', STATE_OFF)
|
||||
self.hass.states.set("light.Bowl", STATE_OFF)
|
||||
self.hass.states.set("light.Ceiling", STATE_OFF)
|
||||
test_group = group.Group.create_group(
|
||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
||||
self.hass, "init_group", ["light.Bowl", "light.Ceiling"], False
|
||||
)
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
@@ -95,13 +108,14 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
|
||||
def test_group_turns_on_if_all_are_off_and_one_turns_on(self):
|
||||
"""Test if turn on if all devices were turned off and one turns on."""
|
||||
self.hass.states.set('light.Bowl', STATE_OFF)
|
||||
self.hass.states.set('light.Ceiling', STATE_OFF)
|
||||
self.hass.states.set("light.Bowl", STATE_OFF)
|
||||
self.hass.states.set("light.Ceiling", STATE_OFF)
|
||||
test_group = group.Group.create_group(
|
||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
||||
self.hass, "init_group", ["light.Bowl", "light.Ceiling"], False
|
||||
)
|
||||
|
||||
# Turn one on
|
||||
self.hass.states.set('light.Ceiling', STATE_ON)
|
||||
self.hass.states.set("light.Ceiling", STATE_ON)
|
||||
self.hass.block_till_done()
|
||||
|
||||
group_state = self.hass.states.get(test_group.entity_id)
|
||||
@@ -109,14 +123,14 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
|
||||
def test_allgroup_stays_off_if_all_are_off_and_one_turns_on(self):
|
||||
"""Group with all: true, stay off if one device turns on."""
|
||||
self.hass.states.set('light.Bowl', STATE_OFF)
|
||||
self.hass.states.set('light.Ceiling', STATE_OFF)
|
||||
self.hass.states.set("light.Bowl", STATE_OFF)
|
||||
self.hass.states.set("light.Ceiling", STATE_OFF)
|
||||
test_group = group.Group.create_group(
|
||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False,
|
||||
mode=True)
|
||||
self.hass, "init_group", ["light.Bowl", "light.Ceiling"], False, mode=True
|
||||
)
|
||||
|
||||
# Turn one on
|
||||
self.hass.states.set('light.Ceiling', STATE_ON)
|
||||
self.hass.states.set("light.Ceiling", STATE_ON)
|
||||
self.hass.block_till_done()
|
||||
|
||||
group_state = self.hass.states.get(test_group.entity_id)
|
||||
@@ -124,14 +138,14 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
|
||||
def test_allgroup_turn_on_if_last_turns_on(self):
|
||||
"""Group with all: true, turn on if all devices are on."""
|
||||
self.hass.states.set('light.Bowl', STATE_ON)
|
||||
self.hass.states.set('light.Ceiling', STATE_OFF)
|
||||
self.hass.states.set("light.Bowl", STATE_ON)
|
||||
self.hass.states.set("light.Ceiling", STATE_OFF)
|
||||
test_group = group.Group.create_group(
|
||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False,
|
||||
mode=True)
|
||||
self.hass, "init_group", ["light.Bowl", "light.Ceiling"], False, mode=True
|
||||
)
|
||||
|
||||
# Turn one on
|
||||
self.hass.states.set('light.Ceiling', STATE_ON)
|
||||
self.hass.states.set("light.Ceiling", STATE_ON)
|
||||
self.hass.block_till_done()
|
||||
|
||||
group_state = self.hass.states.get(test_group.entity_id)
|
||||
@@ -139,58 +153,62 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
|
||||
def test_is_on(self):
|
||||
"""Test is_on method."""
|
||||
self.hass.states.set('light.Bowl', STATE_ON)
|
||||
self.hass.states.set('light.Ceiling', STATE_OFF)
|
||||
self.hass.states.set("light.Bowl", STATE_ON)
|
||||
self.hass.states.set("light.Ceiling", STATE_OFF)
|
||||
test_group = group.Group.create_group(
|
||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
||||
self.hass, "init_group", ["light.Bowl", "light.Ceiling"], False
|
||||
)
|
||||
|
||||
assert group.is_on(self.hass, test_group.entity_id)
|
||||
self.hass.states.set('light.Bowl', STATE_OFF)
|
||||
self.hass.states.set("light.Bowl", STATE_OFF)
|
||||
self.hass.block_till_done()
|
||||
assert not group.is_on(self.hass, test_group.entity_id)
|
||||
|
||||
# Try on non existing state
|
||||
assert not group.is_on(self.hass, 'non.existing')
|
||||
assert not group.is_on(self.hass, "non.existing")
|
||||
|
||||
def test_expand_entity_ids(self):
|
||||
"""Test expand_entity_ids method."""
|
||||
self.hass.states.set('light.Bowl', STATE_ON)
|
||||
self.hass.states.set('light.Ceiling', STATE_OFF)
|
||||
self.hass.states.set("light.Bowl", STATE_ON)
|
||||
self.hass.states.set("light.Ceiling", STATE_OFF)
|
||||
test_group = group.Group.create_group(
|
||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
||||
self.hass, "init_group", ["light.Bowl", "light.Ceiling"], False
|
||||
)
|
||||
|
||||
assert sorted(['light.ceiling', 'light.bowl']) == \
|
||||
sorted(group.expand_entity_ids(
|
||||
self.hass, [test_group.entity_id]))
|
||||
assert sorted(["light.ceiling", "light.bowl"]) == sorted(
|
||||
group.expand_entity_ids(self.hass, [test_group.entity_id])
|
||||
)
|
||||
|
||||
def test_expand_entity_ids_does_not_return_duplicates(self):
|
||||
"""Test that expand_entity_ids does not return duplicates."""
|
||||
self.hass.states.set('light.Bowl', STATE_ON)
|
||||
self.hass.states.set('light.Ceiling', STATE_OFF)
|
||||
self.hass.states.set("light.Bowl", STATE_ON)
|
||||
self.hass.states.set("light.Ceiling", STATE_OFF)
|
||||
test_group = group.Group.create_group(
|
||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
||||
self.hass, "init_group", ["light.Bowl", "light.Ceiling"], False
|
||||
)
|
||||
|
||||
assert ['light.bowl', 'light.ceiling'] == \
|
||||
sorted(group.expand_entity_ids(
|
||||
self.hass, [test_group.entity_id, 'light.Ceiling']))
|
||||
assert ["light.bowl", "light.ceiling"] == sorted(
|
||||
group.expand_entity_ids(self.hass, [test_group.entity_id, "light.Ceiling"])
|
||||
)
|
||||
|
||||
assert ['light.bowl', 'light.ceiling'] == \
|
||||
sorted(group.expand_entity_ids(
|
||||
self.hass, ['light.bowl', test_group.entity_id]))
|
||||
assert ["light.bowl", "light.ceiling"] == sorted(
|
||||
group.expand_entity_ids(self.hass, ["light.bowl", test_group.entity_id])
|
||||
)
|
||||
|
||||
def test_expand_entity_ids_recursive(self):
|
||||
"""Test expand_entity_ids method with a group that contains itself."""
|
||||
self.hass.states.set('light.Bowl', STATE_ON)
|
||||
self.hass.states.set('light.Ceiling', STATE_OFF)
|
||||
self.hass.states.set("light.Bowl", STATE_ON)
|
||||
self.hass.states.set("light.Ceiling", STATE_OFF)
|
||||
test_group = group.Group.create_group(
|
||||
self.hass,
|
||||
'init_group',
|
||||
['light.Bowl', 'light.Ceiling', 'group.init_group'],
|
||||
False)
|
||||
"init_group",
|
||||
["light.Bowl", "light.Ceiling", "group.init_group"],
|
||||
False,
|
||||
)
|
||||
|
||||
assert sorted(['light.ceiling', 'light.bowl']) == \
|
||||
sorted(group.expand_entity_ids(
|
||||
self.hass, [test_group.entity_id]))
|
||||
assert sorted(["light.ceiling", "light.bowl"]) == sorted(
|
||||
group.expand_entity_ids(self.hass, [test_group.entity_id])
|
||||
)
|
||||
|
||||
def test_expand_entity_ids_ignores_non_strings(self):
|
||||
"""Test that non string elements in lists are ignored."""
|
||||
@@ -198,32 +216,35 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
|
||||
def test_get_entity_ids(self):
|
||||
"""Test get_entity_ids method."""
|
||||
self.hass.states.set('light.Bowl', STATE_ON)
|
||||
self.hass.states.set('light.Ceiling', STATE_OFF)
|
||||
self.hass.states.set("light.Bowl", STATE_ON)
|
||||
self.hass.states.set("light.Ceiling", STATE_OFF)
|
||||
test_group = group.Group.create_group(
|
||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
||||
self.hass, "init_group", ["light.Bowl", "light.Ceiling"], False
|
||||
)
|
||||
|
||||
assert ['light.bowl', 'light.ceiling'] == \
|
||||
sorted(group.get_entity_ids(self.hass, test_group.entity_id))
|
||||
assert ["light.bowl", "light.ceiling"] == sorted(
|
||||
group.get_entity_ids(self.hass, test_group.entity_id)
|
||||
)
|
||||
|
||||
def test_get_entity_ids_with_domain_filter(self):
|
||||
"""Test if get_entity_ids works with a domain_filter."""
|
||||
self.hass.states.set('switch.AC', STATE_OFF)
|
||||
self.hass.states.set("switch.AC", STATE_OFF)
|
||||
|
||||
mixed_group = group.Group.create_group(
|
||||
self.hass, 'mixed_group', ['light.Bowl', 'switch.AC'], False)
|
||||
self.hass, "mixed_group", ["light.Bowl", "switch.AC"], False
|
||||
)
|
||||
|
||||
assert ['switch.ac'] == \
|
||||
group.get_entity_ids(
|
||||
self.hass, mixed_group.entity_id, domain_filter="switch")
|
||||
assert ["switch.ac"] == group.get_entity_ids(
|
||||
self.hass, mixed_group.entity_id, domain_filter="switch"
|
||||
)
|
||||
|
||||
def test_get_entity_ids_with_non_existing_group_name(self):
|
||||
"""Test get_entity_ids with a non existing group."""
|
||||
assert [] == group.get_entity_ids(self.hass, 'non_existing')
|
||||
assert [] == group.get_entity_ids(self.hass, "non_existing")
|
||||
|
||||
def test_get_entity_ids_with_non_group_state(self):
|
||||
"""Test get_entity_ids with a non group state."""
|
||||
assert [] == group.get_entity_ids(self.hass, 'switch.AC')
|
||||
assert [] == group.get_entity_ids(self.hass, "switch.AC")
|
||||
|
||||
def test_group_being_init_before_first_tracked_state_is_set_to_on(self):
|
||||
"""Test if the groups turn on.
|
||||
@@ -232,9 +253,10 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
as ON.
|
||||
"""
|
||||
test_group = group.Group.create_group(
|
||||
self.hass, 'test group', ['light.not_there_1'])
|
||||
self.hass, "test group", ["light.not_there_1"]
|
||||
)
|
||||
|
||||
self.hass.states.set('light.not_there_1', STATE_ON)
|
||||
self.hass.states.set("light.not_there_1", STATE_ON)
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
@@ -248,9 +270,10 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
as OFF.
|
||||
"""
|
||||
test_group = group.Group.create_group(
|
||||
self.hass, 'test group', ['light.not_there_1'])
|
||||
self.hass, "test group", ["light.not_there_1"]
|
||||
)
|
||||
|
||||
self.hass.states.set('light.not_there_1', STATE_OFF)
|
||||
self.hass.states.set("light.not_there_1", STATE_OFF)
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
@@ -259,42 +282,43 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
|
||||
def test_setup(self):
|
||||
"""Test setup method."""
|
||||
self.hass.states.set('light.Bowl', STATE_ON)
|
||||
self.hass.states.set('light.Ceiling', STATE_OFF)
|
||||
self.hass.states.set("light.Bowl", STATE_ON)
|
||||
self.hass.states.set("light.Ceiling", STATE_OFF)
|
||||
test_group = group.Group.create_group(
|
||||
self.hass, 'init_group', ['light.Bowl', 'light.Ceiling'], False)
|
||||
self.hass, "init_group", ["light.Bowl", "light.Ceiling"], False
|
||||
)
|
||||
|
||||
group_conf = OrderedDict()
|
||||
group_conf['second_group'] = {
|
||||
'entities': 'light.Bowl, ' + test_group.entity_id,
|
||||
'icon': 'mdi:work',
|
||||
'view': True,
|
||||
'control': 'hidden',
|
||||
group_conf["second_group"] = {
|
||||
"entities": "light.Bowl, " + test_group.entity_id,
|
||||
"icon": "mdi:work",
|
||||
"view": True,
|
||||
"control": "hidden",
|
||||
}
|
||||
group_conf['test_group'] = 'hello.world,sensor.happy'
|
||||
group_conf['empty_group'] = {'name': 'Empty Group', 'entities': None}
|
||||
group_conf["test_group"] = "hello.world,sensor.happy"
|
||||
group_conf["empty_group"] = {"name": "Empty Group", "entities": None}
|
||||
|
||||
setup_component(self.hass, 'group', {'group': group_conf})
|
||||
setup_component(self.hass, "group", {"group": group_conf})
|
||||
|
||||
group_state = self.hass.states.get(
|
||||
group.ENTITY_ID_FORMAT.format('second_group'))
|
||||
group.ENTITY_ID_FORMAT.format("second_group")
|
||||
)
|
||||
assert STATE_ON == group_state.state
|
||||
assert set((test_group.entity_id, 'light.bowl')) == \
|
||||
set(group_state.attributes['entity_id'])
|
||||
assert set((test_group.entity_id, "light.bowl")) == set(
|
||||
group_state.attributes["entity_id"]
|
||||
)
|
||||
assert group_state.attributes.get(group.ATTR_AUTO) is None
|
||||
assert 'mdi:work' == \
|
||||
group_state.attributes.get(ATTR_ICON)
|
||||
assert "mdi:work" == group_state.attributes.get(ATTR_ICON)
|
||||
assert group_state.attributes.get(group.ATTR_VIEW)
|
||||
assert 'hidden' == \
|
||||
group_state.attributes.get(group.ATTR_CONTROL)
|
||||
assert "hidden" == group_state.attributes.get(group.ATTR_CONTROL)
|
||||
assert group_state.attributes.get(ATTR_HIDDEN)
|
||||
assert 1 == group_state.attributes.get(group.ATTR_ORDER)
|
||||
|
||||
group_state = self.hass.states.get(
|
||||
group.ENTITY_ID_FORMAT.format('test_group'))
|
||||
group_state = self.hass.states.get(group.ENTITY_ID_FORMAT.format("test_group"))
|
||||
assert STATE_UNKNOWN == group_state.state
|
||||
assert set(('sensor.happy', 'hello.world')) == \
|
||||
set(group_state.attributes['entity_id'])
|
||||
assert set(("sensor.happy", "hello.world")) == set(
|
||||
group_state.attributes["entity_id"]
|
||||
)
|
||||
assert group_state.attributes.get(group.ATTR_AUTO) is None
|
||||
assert group_state.attributes.get(ATTR_ICON) is None
|
||||
assert group_state.attributes.get(group.ATTR_VIEW) is None
|
||||
@@ -304,45 +328,46 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
|
||||
def test_groups_get_unique_names(self):
|
||||
"""Two groups with same name should both have a unique entity id."""
|
||||
grp1 = group.Group.create_group(self.hass, 'Je suis Charlie')
|
||||
grp2 = group.Group.create_group(self.hass, 'Je suis Charlie')
|
||||
grp1 = group.Group.create_group(self.hass, "Je suis Charlie")
|
||||
grp2 = group.Group.create_group(self.hass, "Je suis Charlie")
|
||||
|
||||
assert grp1.entity_id != grp2.entity_id
|
||||
|
||||
def test_expand_entity_ids_expands_nested_groups(self):
|
||||
"""Test if entity ids epands to nested groups."""
|
||||
group.Group.create_group(self.hass, "light", ["light.test_1", "light.test_2"])
|
||||
group.Group.create_group(
|
||||
self.hass, 'light', ['light.test_1', 'light.test_2'])
|
||||
self.hass, "switch", ["switch.test_1", "switch.test_2"]
|
||||
)
|
||||
group.Group.create_group(
|
||||
self.hass, 'switch', ['switch.test_1', 'switch.test_2'])
|
||||
group.Group.create_group(
|
||||
self.hass, 'group_of_groups', ['group.light', 'group.switch'])
|
||||
self.hass, "group_of_groups", ["group.light", "group.switch"]
|
||||
)
|
||||
|
||||
assert ['light.test_1', 'light.test_2',
|
||||
'switch.test_1', 'switch.test_2'] == \
|
||||
sorted(group.expand_entity_ids(self.hass,
|
||||
['group.group_of_groups']))
|
||||
assert [
|
||||
"light.test_1",
|
||||
"light.test_2",
|
||||
"switch.test_1",
|
||||
"switch.test_2",
|
||||
] == sorted(group.expand_entity_ids(self.hass, ["group.group_of_groups"]))
|
||||
|
||||
def test_set_assumed_state_based_on_tracked(self):
|
||||
"""Test assumed state."""
|
||||
self.hass.states.set('light.Bowl', STATE_ON)
|
||||
self.hass.states.set('light.Ceiling', STATE_OFF)
|
||||
self.hass.states.set("light.Bowl", STATE_ON)
|
||||
self.hass.states.set("light.Ceiling", STATE_OFF)
|
||||
test_group = group.Group.create_group(
|
||||
self.hass, 'init_group',
|
||||
['light.Bowl', 'light.Ceiling', 'sensor.no_exist'])
|
||||
self.hass, "init_group", ["light.Bowl", "light.Ceiling", "sensor.no_exist"]
|
||||
)
|
||||
|
||||
state = self.hass.states.get(test_group.entity_id)
|
||||
assert not state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
self.hass.states.set('light.Bowl', STATE_ON, {
|
||||
ATTR_ASSUMED_STATE: True
|
||||
})
|
||||
self.hass.states.set("light.Bowl", STATE_ON, {ATTR_ASSUMED_STATE: True})
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get(test_group.entity_id)
|
||||
assert state.attributes.get(ATTR_ASSUMED_STATE)
|
||||
|
||||
self.hass.states.set('light.Bowl', STATE_ON)
|
||||
self.hass.states.set("light.Bowl", STATE_ON)
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get(test_group.entity_id)
|
||||
@@ -350,65 +375,78 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
|
||||
def test_group_updated_after_device_tracker_zone_change(self):
|
||||
"""Test group state when device tracker in group changes zone."""
|
||||
self.hass.states.set('device_tracker.Adam', STATE_HOME)
|
||||
self.hass.states.set('device_tracker.Eve', STATE_NOT_HOME)
|
||||
self.hass.states.set("device_tracker.Adam", STATE_HOME)
|
||||
self.hass.states.set("device_tracker.Eve", STATE_NOT_HOME)
|
||||
self.hass.block_till_done()
|
||||
group.Group.create_group(
|
||||
self.hass, 'peeps',
|
||||
['device_tracker.Adam', 'device_tracker.Eve'])
|
||||
self.hass.states.set('device_tracker.Adam', 'cool_state_not_home')
|
||||
self.hass, "peeps", ["device_tracker.Adam", "device_tracker.Eve"]
|
||||
)
|
||||
self.hass.states.set("device_tracker.Adam", "cool_state_not_home")
|
||||
self.hass.block_till_done()
|
||||
assert STATE_NOT_HOME == \
|
||||
self.hass.states.get(
|
||||
group.ENTITY_ID_FORMAT.format('peeps')).state
|
||||
assert (
|
||||
STATE_NOT_HOME
|
||||
== self.hass.states.get(group.ENTITY_ID_FORMAT.format("peeps")).state
|
||||
)
|
||||
|
||||
def test_reloading_groups(self):
|
||||
"""Test reloading the group config."""
|
||||
assert setup_component(self.hass, 'group', {'group': {
|
||||
'second_group': {
|
||||
'entities': 'light.Bowl',
|
||||
'icon': 'mdi:work',
|
||||
'view': True,
|
||||
assert setup_component(
|
||||
self.hass,
|
||||
"group",
|
||||
{
|
||||
"group": {
|
||||
"second_group": {
|
||||
"entities": "light.Bowl",
|
||||
"icon": "mdi:work",
|
||||
"view": True,
|
||||
},
|
||||
"test_group": "hello.world,sensor.happy",
|
||||
"empty_group": {"name": "Empty Group", "entities": None},
|
||||
}
|
||||
},
|
||||
'test_group': 'hello.world,sensor.happy',
|
||||
'empty_group': {'name': 'Empty Group', 'entities': None},
|
||||
}})
|
||||
)
|
||||
|
||||
group.Group.create_group(
|
||||
self.hass, 'all tests',
|
||||
['test.one', 'test.two'],
|
||||
user_defined=False)
|
||||
self.hass, "all tests", ["test.one", "test.two"], user_defined=False
|
||||
)
|
||||
|
||||
assert sorted(self.hass.states.entity_ids()) == \
|
||||
['group.all_tests', 'group.empty_group', 'group.second_group',
|
||||
'group.test_group']
|
||||
assert self.hass.bus.listeners['state_changed'] == 3
|
||||
assert sorted(self.hass.states.entity_ids()) == [
|
||||
"group.all_tests",
|
||||
"group.empty_group",
|
||||
"group.second_group",
|
||||
"group.test_group",
|
||||
]
|
||||
assert self.hass.bus.listeners["state_changed"] == 3
|
||||
|
||||
with patch('homeassistant.config.load_yaml_config_file', return_value={
|
||||
'group': {
|
||||
'hello': {
|
||||
'entities': 'light.Bowl',
|
||||
'icon': 'mdi:work',
|
||||
'view': True,
|
||||
}}}):
|
||||
with patch('homeassistant.config.find_config_file',
|
||||
return_value=''):
|
||||
with patch(
|
||||
"homeassistant.config.load_yaml_config_file",
|
||||
return_value={
|
||||
"group": {
|
||||
"hello": {
|
||||
"entities": "light.Bowl",
|
||||
"icon": "mdi:work",
|
||||
"view": True,
|
||||
}
|
||||
}
|
||||
},
|
||||
):
|
||||
with patch("homeassistant.config.find_config_file", return_value=""):
|
||||
common.reload(self.hass)
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert sorted(self.hass.states.entity_ids()) == \
|
||||
['group.all_tests', 'group.hello']
|
||||
assert self.hass.bus.listeners['state_changed'] == 2
|
||||
assert sorted(self.hass.states.entity_ids()) == [
|
||||
"group.all_tests",
|
||||
"group.hello",
|
||||
]
|
||||
assert self.hass.bus.listeners["state_changed"] == 2
|
||||
|
||||
def test_changing_group_visibility(self):
|
||||
"""Test that a group can be hidden and shown."""
|
||||
assert setup_component(self.hass, 'group', {
|
||||
'group': {
|
||||
'test_group': 'hello.world,sensor.happy'
|
||||
}
|
||||
})
|
||||
assert setup_component(
|
||||
self.hass, "group", {"group": {"test_group": "hello.world,sensor.happy"}}
|
||||
)
|
||||
|
||||
group_entity_id = group.ENTITY_ID_FORMAT.format('test_group')
|
||||
group_entity_id = group.ENTITY_ID_FORMAT.format("test_group")
|
||||
|
||||
# Hide the group
|
||||
common.set_visibility(self.hass, group_entity_id, False)
|
||||
@@ -425,87 +463,90 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
def test_modify_group(self):
|
||||
"""Test modifying a group."""
|
||||
group_conf = OrderedDict()
|
||||
group_conf['modify_group'] = {
|
||||
'name': 'friendly_name',
|
||||
'icon': 'mdi:work'
|
||||
}
|
||||
group_conf["modify_group"] = {"name": "friendly_name", "icon": "mdi:work"}
|
||||
|
||||
assert setup_component(self.hass, 'group', {'group': group_conf})
|
||||
assert setup_component(self.hass, "group", {"group": group_conf})
|
||||
|
||||
# The old way would create a new group modify_group1 because
|
||||
# internally it didn't know anything about those created in the config
|
||||
common.set_group(self.hass, 'modify_group', icon="mdi:play")
|
||||
common.set_group(self.hass, "modify_group", icon="mdi:play")
|
||||
self.hass.block_till_done()
|
||||
|
||||
group_state = self.hass.states.get(
|
||||
group.ENTITY_ID_FORMAT.format('modify_group'))
|
||||
group.ENTITY_ID_FORMAT.format("modify_group")
|
||||
)
|
||||
|
||||
assert self.hass.states.entity_ids() == ['group.modify_group']
|
||||
assert group_state.attributes.get(ATTR_ICON) == 'mdi:play'
|
||||
assert group_state.attributes.get(ATTR_FRIENDLY_NAME) == \
|
||||
'friendly_name'
|
||||
assert self.hass.states.entity_ids() == ["group.modify_group"]
|
||||
assert group_state.attributes.get(ATTR_ICON) == "mdi:play"
|
||||
assert group_state.attributes.get(ATTR_FRIENDLY_NAME) == "friendly_name"
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_service_group_services(hass):
|
||||
"""Check if service are available."""
|
||||
with assert_setup_component(0, 'group'):
|
||||
yield from async_setup_component(hass, 'group', {
|
||||
'group': {}
|
||||
})
|
||||
with assert_setup_component(0, "group"):
|
||||
yield from async_setup_component(hass, "group", {"group": {}})
|
||||
|
||||
assert hass.services.has_service('group', group.SERVICE_SET)
|
||||
assert hass.services.has_service('group', group.SERVICE_REMOVE)
|
||||
assert hass.services.has_service("group", group.SERVICE_SET)
|
||||
assert hass.services.has_service("group", group.SERVICE_REMOVE)
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
@asyncio.coroutine
|
||||
def test_service_group_set_group_remove_group(hass):
|
||||
"""Check if service are available."""
|
||||
with assert_setup_component(0, 'group'):
|
||||
yield from async_setup_component(hass, 'group', {
|
||||
'group': {}
|
||||
})
|
||||
with assert_setup_component(0, "group"):
|
||||
yield from async_setup_component(hass, "group", {"group": {}})
|
||||
|
||||
common.async_set_group(hass, 'user_test_group', name="Test")
|
||||
common.async_set_group(hass, "user_test_group", name="Test")
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
group_state = hass.states.get('group.user_test_group')
|
||||
group_state = hass.states.get("group.user_test_group")
|
||||
assert group_state
|
||||
assert group_state.attributes[group.ATTR_AUTO]
|
||||
assert group_state.attributes['friendly_name'] == "Test"
|
||||
assert group_state.attributes["friendly_name"] == "Test"
|
||||
|
||||
common.async_set_group(
|
||||
hass, 'user_test_group', view=True, visible=False,
|
||||
entity_ids=['test.entity_bla1'])
|
||||
hass,
|
||||
"user_test_group",
|
||||
view=True,
|
||||
visible=False,
|
||||
entity_ids=["test.entity_bla1"],
|
||||
)
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
group_state = hass.states.get('group.user_test_group')
|
||||
group_state = hass.states.get("group.user_test_group")
|
||||
assert group_state
|
||||
assert group_state.attributes[group.ATTR_VIEW]
|
||||
assert group_state.attributes[group.ATTR_AUTO]
|
||||
assert group_state.attributes['hidden']
|
||||
assert group_state.attributes['friendly_name'] == "Test"
|
||||
assert list(group_state.attributes['entity_id']) == ['test.entity_bla1']
|
||||
assert group_state.attributes["hidden"]
|
||||
assert group_state.attributes["friendly_name"] == "Test"
|
||||
assert list(group_state.attributes["entity_id"]) == ["test.entity_bla1"]
|
||||
|
||||
common.async_set_group(
|
||||
hass, 'user_test_group', icon="mdi:camera", name="Test2",
|
||||
control="hidden", add=['test.entity_id2'])
|
||||
hass,
|
||||
"user_test_group",
|
||||
icon="mdi:camera",
|
||||
name="Test2",
|
||||
control="hidden",
|
||||
add=["test.entity_id2"],
|
||||
)
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
group_state = hass.states.get('group.user_test_group')
|
||||
group_state = hass.states.get("group.user_test_group")
|
||||
assert group_state
|
||||
assert group_state.attributes[group.ATTR_VIEW]
|
||||
assert group_state.attributes[group.ATTR_AUTO]
|
||||
assert group_state.attributes['hidden']
|
||||
assert group_state.attributes['friendly_name'] == "Test2"
|
||||
assert group_state.attributes['icon'] == "mdi:camera"
|
||||
assert group_state.attributes["hidden"]
|
||||
assert group_state.attributes["friendly_name"] == "Test2"
|
||||
assert group_state.attributes["icon"] == "mdi:camera"
|
||||
assert group_state.attributes[group.ATTR_CONTROL] == "hidden"
|
||||
assert sorted(list(group_state.attributes['entity_id'])) == sorted([
|
||||
'test.entity_bla1', 'test.entity_id2'])
|
||||
assert sorted(list(group_state.attributes["entity_id"])) == sorted(
|
||||
["test.entity_bla1", "test.entity_id2"]
|
||||
)
|
||||
|
||||
common.async_remove(hass, 'user_test_group')
|
||||
common.async_remove(hass, "user_test_group")
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
group_state = hass.states.get('group.user_test_group')
|
||||
group_state = hass.states.get("group.user_test_group")
|
||||
assert group_state is None
|
||||
@@ -11,379 +11,440 @@ from tests.components.light import common
|
||||
|
||||
async def test_default_state(hass):
|
||||
"""Test light group default state."""
|
||||
await async_setup_component(hass, 'light', {'light': {
|
||||
'platform': 'group', 'entities': [], 'name': 'Bedroom Group'
|
||||
}})
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
{"light": {"platform": "group", "entities": [], "name": "Bedroom Group"}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('light.bedroom_group')
|
||||
state = hass.states.get("light.bedroom_group")
|
||||
assert state is not None
|
||||
assert state.state == 'unavailable'
|
||||
assert state.attributes['supported_features'] == 0
|
||||
assert state.attributes.get('brightness') is None
|
||||
assert state.attributes.get('hs_color') is None
|
||||
assert state.attributes.get('color_temp') is None
|
||||
assert state.attributes.get('white_value') is None
|
||||
assert state.attributes.get('effect_list') is None
|
||||
assert state.attributes.get('effect') is None
|
||||
assert state.state == "unavailable"
|
||||
assert state.attributes["supported_features"] == 0
|
||||
assert state.attributes.get("brightness") is None
|
||||
assert state.attributes.get("hs_color") is None
|
||||
assert state.attributes.get("color_temp") is None
|
||||
assert state.attributes.get("white_value") is None
|
||||
assert state.attributes.get("effect_list") is None
|
||||
assert state.attributes.get("effect") is None
|
||||
|
||||
|
||||
async def test_state_reporting(hass):
|
||||
"""Test the state reporting."""
|
||||
await async_setup_component(hass, 'light', {'light': {
|
||||
'platform': 'group', 'entities': ['light.test1', 'light.test2']
|
||||
}})
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
{"light": {"platform": "group", "entities": ["light.test1", "light.test2"]}},
|
||||
)
|
||||
|
||||
hass.states.async_set('light.test1', 'on')
|
||||
hass.states.async_set('light.test2', 'unavailable')
|
||||
hass.states.async_set("light.test1", "on")
|
||||
hass.states.async_set("light.test2", "unavailable")
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get('light.light_group').state == 'on'
|
||||
assert hass.states.get("light.light_group").state == "on"
|
||||
|
||||
hass.states.async_set('light.test1', 'on')
|
||||
hass.states.async_set('light.test2', 'off')
|
||||
hass.states.async_set("light.test1", "on")
|
||||
hass.states.async_set("light.test2", "off")
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get('light.light_group').state == 'on'
|
||||
assert hass.states.get("light.light_group").state == "on"
|
||||
|
||||
hass.states.async_set('light.test1', 'off')
|
||||
hass.states.async_set('light.test2', 'off')
|
||||
hass.states.async_set("light.test1", "off")
|
||||
hass.states.async_set("light.test2", "off")
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get('light.light_group').state == 'off'
|
||||
assert hass.states.get("light.light_group").state == "off"
|
||||
|
||||
hass.states.async_set('light.test1', 'unavailable')
|
||||
hass.states.async_set('light.test2', 'unavailable')
|
||||
hass.states.async_set("light.test1", "unavailable")
|
||||
hass.states.async_set("light.test2", "unavailable")
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get('light.light_group').state == 'unavailable'
|
||||
assert hass.states.get("light.light_group").state == "unavailable"
|
||||
|
||||
|
||||
async def test_brightness(hass):
|
||||
"""Test brightness reporting."""
|
||||
await async_setup_component(hass, 'light', {'light': {
|
||||
'platform': 'group', 'entities': ['light.test1', 'light.test2']
|
||||
}})
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
{"light": {"platform": "group", "entities": ["light.test1", "light.test2"]}},
|
||||
)
|
||||
|
||||
hass.states.async_set('light.test1', 'on',
|
||||
{'brightness': 255, 'supported_features': 1})
|
||||
hass.states.async_set(
|
||||
"light.test1", "on", {"brightness": 255, "supported_features": 1}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.state == 'on'
|
||||
assert state.attributes['supported_features'] == 1
|
||||
assert state.attributes['brightness'] == 255
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.state == "on"
|
||||
assert state.attributes["supported_features"] == 1
|
||||
assert state.attributes["brightness"] == 255
|
||||
|
||||
hass.states.async_set('light.test2', 'on',
|
||||
{'brightness': 100, 'supported_features': 1})
|
||||
hass.states.async_set(
|
||||
"light.test2", "on", {"brightness": 100, "supported_features": 1}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.state == 'on'
|
||||
assert state.attributes['brightness'] == 177
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.state == "on"
|
||||
assert state.attributes["brightness"] == 177
|
||||
|
||||
hass.states.async_set('light.test1', 'off',
|
||||
{'brightness': 255, 'supported_features': 1})
|
||||
hass.states.async_set(
|
||||
"light.test1", "off", {"brightness": 255, "supported_features": 1}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.state == 'on'
|
||||
assert state.attributes['supported_features'] == 1
|
||||
assert state.attributes['brightness'] == 100
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.state == "on"
|
||||
assert state.attributes["supported_features"] == 1
|
||||
assert state.attributes["brightness"] == 100
|
||||
|
||||
|
||||
async def test_color(hass):
|
||||
"""Test RGB reporting."""
|
||||
await async_setup_component(hass, 'light', {'light': {
|
||||
'platform': 'group', 'entities': ['light.test1', 'light.test2']
|
||||
}})
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
{"light": {"platform": "group", "entities": ["light.test1", "light.test2"]}},
|
||||
)
|
||||
|
||||
hass.states.async_set('light.test1', 'on',
|
||||
{'hs_color': (0, 100), 'supported_features': 16})
|
||||
hass.states.async_set(
|
||||
"light.test1", "on", {"hs_color": (0, 100), "supported_features": 16}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.state == 'on'
|
||||
assert state.attributes['supported_features'] == 16
|
||||
assert state.attributes['hs_color'] == (0, 100)
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.state == "on"
|
||||
assert state.attributes["supported_features"] == 16
|
||||
assert state.attributes["hs_color"] == (0, 100)
|
||||
|
||||
hass.states.async_set('light.test2', 'on',
|
||||
{'hs_color': (0, 50),
|
||||
'supported_features': 16})
|
||||
hass.states.async_set(
|
||||
"light.test2", "on", {"hs_color": (0, 50), "supported_features": 16}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['hs_color'] == (0, 75)
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["hs_color"] == (0, 75)
|
||||
|
||||
hass.states.async_set('light.test1', 'off',
|
||||
{'hs_color': (0, 0), 'supported_features': 16})
|
||||
hass.states.async_set(
|
||||
"light.test1", "off", {"hs_color": (0, 0), "supported_features": 16}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['hs_color'] == (0, 50)
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["hs_color"] == (0, 50)
|
||||
|
||||
|
||||
async def test_white_value(hass):
|
||||
"""Test white value reporting."""
|
||||
await async_setup_component(hass, 'light', {'light': {
|
||||
'platform': 'group', 'entities': ['light.test1', 'light.test2']
|
||||
}})
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
{"light": {"platform": "group", "entities": ["light.test1", "light.test2"]}},
|
||||
)
|
||||
|
||||
hass.states.async_set('light.test1', 'on',
|
||||
{'white_value': 255, 'supported_features': 128})
|
||||
hass.states.async_set(
|
||||
"light.test1", "on", {"white_value": 255, "supported_features": 128}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['white_value'] == 255
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["white_value"] == 255
|
||||
|
||||
hass.states.async_set('light.test2', 'on',
|
||||
{'white_value': 100, 'supported_features': 128})
|
||||
hass.states.async_set(
|
||||
"light.test2", "on", {"white_value": 100, "supported_features": 128}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['white_value'] == 177
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["white_value"] == 177
|
||||
|
||||
hass.states.async_set('light.test1', 'off',
|
||||
{'white_value': 255, 'supported_features': 128})
|
||||
hass.states.async_set(
|
||||
"light.test1", "off", {"white_value": 255, "supported_features": 128}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['white_value'] == 100
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["white_value"] == 100
|
||||
|
||||
|
||||
async def test_color_temp(hass):
|
||||
"""Test color temp reporting."""
|
||||
await async_setup_component(hass, 'light', {'light': {
|
||||
'platform': 'group', 'entities': ['light.test1', 'light.test2']
|
||||
}})
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
{"light": {"platform": "group", "entities": ["light.test1", "light.test2"]}},
|
||||
)
|
||||
|
||||
hass.states.async_set('light.test1', 'on',
|
||||
{'color_temp': 2, 'supported_features': 2})
|
||||
hass.states.async_set(
|
||||
"light.test1", "on", {"color_temp": 2, "supported_features": 2}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['color_temp'] == 2
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["color_temp"] == 2
|
||||
|
||||
hass.states.async_set('light.test2', 'on',
|
||||
{'color_temp': 1000, 'supported_features': 2})
|
||||
hass.states.async_set(
|
||||
"light.test2", "on", {"color_temp": 1000, "supported_features": 2}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['color_temp'] == 501
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["color_temp"] == 501
|
||||
|
||||
hass.states.async_set('light.test1', 'off',
|
||||
{'color_temp': 2, 'supported_features': 2})
|
||||
hass.states.async_set(
|
||||
"light.test1", "off", {"color_temp": 2, "supported_features": 2}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['color_temp'] == 1000
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["color_temp"] == 1000
|
||||
|
||||
|
||||
async def test_min_max_mireds(hass):
|
||||
"""Test min/max mireds reporting."""
|
||||
await async_setup_component(hass, 'light', {'light': {
|
||||
'platform': 'group', 'entities': ['light.test1', 'light.test2']
|
||||
}})
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
{"light": {"platform": "group", "entities": ["light.test1", "light.test2"]}},
|
||||
)
|
||||
|
||||
hass.states.async_set('light.test1', 'on',
|
||||
{'min_mireds': 2, 'max_mireds': 5,
|
||||
'supported_features': 2})
|
||||
hass.states.async_set(
|
||||
"light.test1", "on", {"min_mireds": 2, "max_mireds": 5, "supported_features": 2}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['min_mireds'] == 2
|
||||
assert state.attributes['max_mireds'] == 5
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["min_mireds"] == 2
|
||||
assert state.attributes["max_mireds"] == 5
|
||||
|
||||
hass.states.async_set('light.test2', 'on',
|
||||
{'min_mireds': 7, 'max_mireds': 1234567890,
|
||||
'supported_features': 2})
|
||||
hass.states.async_set(
|
||||
"light.test2",
|
||||
"on",
|
||||
{"min_mireds": 7, "max_mireds": 1234567890, "supported_features": 2},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['min_mireds'] == 2
|
||||
assert state.attributes['max_mireds'] == 1234567890
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["min_mireds"] == 2
|
||||
assert state.attributes["max_mireds"] == 1234567890
|
||||
|
||||
hass.states.async_set('light.test1', 'off',
|
||||
{'min_mireds': 1, 'max_mireds': 2,
|
||||
'supported_features': 2})
|
||||
hass.states.async_set(
|
||||
"light.test1",
|
||||
"off",
|
||||
{"min_mireds": 1, "max_mireds": 2, "supported_features": 2},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['min_mireds'] == 1
|
||||
assert state.attributes['max_mireds'] == 1234567890
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["min_mireds"] == 1
|
||||
assert state.attributes["max_mireds"] == 1234567890
|
||||
|
||||
|
||||
async def test_effect_list(hass):
|
||||
"""Test effect_list reporting."""
|
||||
await async_setup_component(hass, 'light', {'light': {
|
||||
'platform': 'group', 'entities': ['light.test1', 'light.test2']
|
||||
}})
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
{"light": {"platform": "group", "entities": ["light.test1", "light.test2"]}},
|
||||
)
|
||||
|
||||
hass.states.async_set('light.test1', 'on',
|
||||
{'effect_list': ['None', 'Random', 'Colorloop'],
|
||||
'supported_features': 4})
|
||||
hass.states.async_set(
|
||||
"light.test1",
|
||||
"on",
|
||||
{"effect_list": ["None", "Random", "Colorloop"], "supported_features": 4},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert set(state.attributes['effect_list']) == {
|
||||
'None', 'Random', 'Colorloop'}
|
||||
state = hass.states.get("light.light_group")
|
||||
assert set(state.attributes["effect_list"]) == {"None", "Random", "Colorloop"}
|
||||
|
||||
hass.states.async_set('light.test2', 'on',
|
||||
{'effect_list': ['None', 'Random', 'Rainbow'],
|
||||
'supported_features': 4})
|
||||
hass.states.async_set(
|
||||
"light.test2",
|
||||
"on",
|
||||
{"effect_list": ["None", "Random", "Rainbow"], "supported_features": 4},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert set(state.attributes['effect_list']) == {
|
||||
'None', 'Random', 'Colorloop', 'Rainbow'}
|
||||
state = hass.states.get("light.light_group")
|
||||
assert set(state.attributes["effect_list"]) == {
|
||||
"None",
|
||||
"Random",
|
||||
"Colorloop",
|
||||
"Rainbow",
|
||||
}
|
||||
|
||||
hass.states.async_set('light.test1', 'off',
|
||||
{'effect_list': ['None', 'Colorloop', 'Seven'],
|
||||
'supported_features': 4})
|
||||
hass.states.async_set(
|
||||
"light.test1",
|
||||
"off",
|
||||
{"effect_list": ["None", "Colorloop", "Seven"], "supported_features": 4},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert set(state.attributes['effect_list']) == {
|
||||
'None', 'Random', 'Colorloop', 'Seven', 'Rainbow'}
|
||||
state = hass.states.get("light.light_group")
|
||||
assert set(state.attributes["effect_list"]) == {
|
||||
"None",
|
||||
"Random",
|
||||
"Colorloop",
|
||||
"Seven",
|
||||
"Rainbow",
|
||||
}
|
||||
|
||||
|
||||
async def test_effect(hass):
|
||||
"""Test effect reporting."""
|
||||
await async_setup_component(hass, 'light', {'light': {
|
||||
'platform': 'group', 'entities': ['light.test1', 'light.test2',
|
||||
'light.test3']
|
||||
}})
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
{
|
||||
"light": {
|
||||
"platform": "group",
|
||||
"entities": ["light.test1", "light.test2", "light.test3"],
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
hass.states.async_set('light.test1', 'on',
|
||||
{'effect': 'None', 'supported_features': 6})
|
||||
hass.states.async_set(
|
||||
"light.test1", "on", {"effect": "None", "supported_features": 6}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['effect'] == 'None'
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["effect"] == "None"
|
||||
|
||||
hass.states.async_set('light.test2', 'on',
|
||||
{'effect': 'None', 'supported_features': 6})
|
||||
hass.states.async_set(
|
||||
"light.test2", "on", {"effect": "None", "supported_features": 6}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['effect'] == 'None'
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["effect"] == "None"
|
||||
|
||||
hass.states.async_set('light.test3', 'on',
|
||||
{'effect': 'Random', 'supported_features': 6})
|
||||
hass.states.async_set(
|
||||
"light.test3", "on", {"effect": "Random", "supported_features": 6}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['effect'] == 'None'
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["effect"] == "None"
|
||||
|
||||
hass.states.async_set('light.test1', 'off',
|
||||
{'effect': 'None', 'supported_features': 6})
|
||||
hass.states.async_set('light.test2', 'off',
|
||||
{'effect': 'None', 'supported_features': 6})
|
||||
hass.states.async_set(
|
||||
"light.test1", "off", {"effect": "None", "supported_features": 6}
|
||||
)
|
||||
hass.states.async_set(
|
||||
"light.test2", "off", {"effect": "None", "supported_features": 6}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['effect'] == 'Random'
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["effect"] == "Random"
|
||||
|
||||
|
||||
async def test_supported_features(hass):
|
||||
"""Test supported features reporting."""
|
||||
await async_setup_component(hass, 'light', {'light': {
|
||||
'platform': 'group', 'entities': ['light.test1', 'light.test2']
|
||||
}})
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
{"light": {"platform": "group", "entities": ["light.test1", "light.test2"]}},
|
||||
)
|
||||
|
||||
hass.states.async_set('light.test1', 'on',
|
||||
{'supported_features': 0})
|
||||
hass.states.async_set("light.test1", "on", {"supported_features": 0})
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['supported_features'] == 0
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["supported_features"] == 0
|
||||
|
||||
hass.states.async_set('light.test2', 'on',
|
||||
{'supported_features': 2})
|
||||
hass.states.async_set("light.test2", "on", {"supported_features": 2})
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['supported_features'] == 2
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["supported_features"] == 2
|
||||
|
||||
hass.states.async_set('light.test1', 'off',
|
||||
{'supported_features': 41})
|
||||
hass.states.async_set("light.test1", "off", {"supported_features": 41})
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['supported_features'] == 43
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["supported_features"] == 43
|
||||
|
||||
hass.states.async_set('light.test2', 'off',
|
||||
{'supported_features': 256})
|
||||
hass.states.async_set("light.test2", "off", {"supported_features": 256})
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('light.light_group')
|
||||
assert state.attributes['supported_features'] == 41
|
||||
state = hass.states.get("light.light_group")
|
||||
assert state.attributes["supported_features"] == 41
|
||||
|
||||
|
||||
async def test_service_calls(hass):
|
||||
"""Test service calls."""
|
||||
await async_setup_component(hass, 'light', {'light': [
|
||||
{'platform': 'demo'},
|
||||
{'platform': 'group', 'entities': ['light.bed_light',
|
||||
'light.ceiling_lights',
|
||||
'light.kitchen_lights']}
|
||||
]})
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
{
|
||||
"light": [
|
||||
{"platform": "demo"},
|
||||
{
|
||||
"platform": "group",
|
||||
"entities": [
|
||||
"light.bed_light",
|
||||
"light.ceiling_lights",
|
||||
"light.kitchen_lights",
|
||||
],
|
||||
},
|
||||
]
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get('light.light_group').state == 'on'
|
||||
await common.async_toggle(hass, 'light.light_group')
|
||||
assert hass.states.get("light.light_group").state == "on"
|
||||
await common.async_toggle(hass, "light.light_group")
|
||||
|
||||
assert hass.states.get('light.bed_light').state == 'off'
|
||||
assert hass.states.get('light.ceiling_lights').state == 'off'
|
||||
assert hass.states.get('light.kitchen_lights').state == 'off'
|
||||
assert hass.states.get("light.bed_light").state == "off"
|
||||
assert hass.states.get("light.ceiling_lights").state == "off"
|
||||
assert hass.states.get("light.kitchen_lights").state == "off"
|
||||
|
||||
await common.async_turn_on(hass, 'light.light_group')
|
||||
await common.async_turn_on(hass, "light.light_group")
|
||||
|
||||
assert hass.states.get('light.bed_light').state == 'on'
|
||||
assert hass.states.get('light.ceiling_lights').state == 'on'
|
||||
assert hass.states.get('light.kitchen_lights').state == 'on'
|
||||
assert hass.states.get("light.bed_light").state == "on"
|
||||
assert hass.states.get("light.ceiling_lights").state == "on"
|
||||
assert hass.states.get("light.kitchen_lights").state == "on"
|
||||
|
||||
await common.async_turn_off(hass, 'light.light_group')
|
||||
await common.async_turn_off(hass, "light.light_group")
|
||||
|
||||
assert hass.states.get('light.bed_light').state == 'off'
|
||||
assert hass.states.get('light.ceiling_lights').state == 'off'
|
||||
assert hass.states.get('light.kitchen_lights').state == 'off'
|
||||
assert hass.states.get("light.bed_light").state == "off"
|
||||
assert hass.states.get("light.ceiling_lights").state == "off"
|
||||
assert hass.states.get("light.kitchen_lights").state == "off"
|
||||
|
||||
await common.async_turn_on(hass, 'light.light_group', brightness=128,
|
||||
effect='Random', rgb_color=(42, 255, 255))
|
||||
await common.async_turn_on(
|
||||
hass,
|
||||
"light.light_group",
|
||||
brightness=128,
|
||||
effect="Random",
|
||||
rgb_color=(42, 255, 255),
|
||||
)
|
||||
|
||||
state = hass.states.get('light.bed_light')
|
||||
assert state.state == 'on'
|
||||
assert state.attributes['brightness'] == 128
|
||||
assert state.attributes['effect'] == 'Random'
|
||||
assert state.attributes['rgb_color'] == (42, 255, 255)
|
||||
state = hass.states.get("light.bed_light")
|
||||
assert state.state == "on"
|
||||
assert state.attributes["brightness"] == 128
|
||||
assert state.attributes["effect"] == "Random"
|
||||
assert state.attributes["rgb_color"] == (42, 255, 255)
|
||||
|
||||
state = hass.states.get('light.ceiling_lights')
|
||||
assert state.state == 'on'
|
||||
assert state.attributes['brightness'] == 128
|
||||
assert state.attributes['effect'] == 'Random'
|
||||
assert state.attributes['rgb_color'] == (42, 255, 255)
|
||||
state = hass.states.get("light.ceiling_lights")
|
||||
assert state.state == "on"
|
||||
assert state.attributes["brightness"] == 128
|
||||
assert state.attributes["effect"] == "Random"
|
||||
assert state.attributes["rgb_color"] == (42, 255, 255)
|
||||
|
||||
state = hass.states.get('light.kitchen_lights')
|
||||
assert state.state == 'on'
|
||||
assert state.attributes['brightness'] == 128
|
||||
assert state.attributes['effect'] == 'Random'
|
||||
assert state.attributes['rgb_color'] == (42, 255, 255)
|
||||
state = hass.states.get("light.kitchen_lights")
|
||||
assert state.state == "on"
|
||||
assert state.attributes["brightness"] == 128
|
||||
assert state.attributes["effect"] == "Random"
|
||||
assert state.attributes["rgb_color"] == (42, 255, 255)
|
||||
|
||||
|
||||
async def test_invalid_service_calls(hass):
|
||||
"""Test invalid service call arguments get discarded."""
|
||||
add_entities = MagicMock()
|
||||
await group.async_setup_platform(hass, {
|
||||
'entities': ['light.test1', 'light.test2']
|
||||
}, add_entities)
|
||||
await group.async_setup_platform(
|
||||
hass, {"entities": ["light.test1", "light.test2"]}, add_entities
|
||||
)
|
||||
|
||||
assert add_entities.call_count == 1
|
||||
grouped_light = add_entities.call_args[0][0][0]
|
||||
grouped_light.hass = hass
|
||||
|
||||
with asynctest.patch.object(hass.services, 'async_call') as mock_call:
|
||||
await grouped_light.async_turn_on(brightness=150, four_oh_four='404')
|
||||
data = {
|
||||
'entity_id': ['light.test1', 'light.test2'],
|
||||
'brightness': 150
|
||||
}
|
||||
mock_call.assert_called_once_with('light', 'turn_on', data,
|
||||
blocking=True)
|
||||
with asynctest.patch.object(hass.services, "async_call") as mock_call:
|
||||
await grouped_light.async_turn_on(brightness=150, four_oh_four="404")
|
||||
data = {"entity_id": ["light.test1", "light.test2"], "brightness": 150}
|
||||
mock_call.assert_called_once_with("light", "turn_on", data, blocking=True)
|
||||
mock_call.reset_mock()
|
||||
|
||||
await grouped_light.async_turn_off(transition=4, four_oh_four='404')
|
||||
data = {
|
||||
'entity_id': ['light.test1', 'light.test2'],
|
||||
'transition': 4
|
||||
}
|
||||
mock_call.assert_called_once_with('light', 'turn_off', data,
|
||||
blocking=True)
|
||||
await grouped_light.async_turn_off(transition=4, four_oh_four="404")
|
||||
data = {"entity_id": ["light.test1", "light.test2"], "transition": 4}
|
||||
mock_call.assert_called_once_with("light", "turn_off", data, blocking=True)
|
||||
mock_call.reset_mock()
|
||||
|
||||
data = {
|
||||
'brightness': 150,
|
||||
'xy_color': (0.5, 0.42),
|
||||
'rgb_color': (80, 120, 50),
|
||||
'color_temp': 1234,
|
||||
'white_value': 1,
|
||||
'effect': 'Sunshine',
|
||||
'transition': 4,
|
||||
'flash': 'long'
|
||||
"brightness": 150,
|
||||
"xy_color": (0.5, 0.42),
|
||||
"rgb_color": (80, 120, 50),
|
||||
"color_temp": 1234,
|
||||
"white_value": 1,
|
||||
"effect": "Sunshine",
|
||||
"transition": 4,
|
||||
"flash": "long",
|
||||
}
|
||||
await grouped_light.async_turn_on(**data)
|
||||
data['entity_id'] = ['light.test1', 'light.test2']
|
||||
data.pop('rgb_color')
|
||||
data.pop('xy_color')
|
||||
mock_call.assert_called_once_with('light', 'turn_on', data,
|
||||
blocking=True)
|
||||
data["entity_id"] = ["light.test1", "light.test2"]
|
||||
data.pop("rgb_color")
|
||||
data.pop("xy_color")
|
||||
mock_call.assert_called_once_with("light", "turn_on", data, blocking=True)
|
||||
@@ -25,29 +25,41 @@ class TestNotifyGroup(unittest.TestCase):
|
||||
self.service2.send_message = MagicMock(autospec=True)
|
||||
|
||||
def mock_get_service(hass, config, discovery_info=None):
|
||||
if config['name'] == 'demo1':
|
||||
if config["name"] == "demo1":
|
||||
return self.service1
|
||||
return self.service2
|
||||
|
||||
with assert_setup_component(2, notify.DOMAIN), \
|
||||
patch.object(demo, 'get_service', mock_get_service):
|
||||
setup_component(self.hass, notify.DOMAIN, {
|
||||
'notify': [{
|
||||
'name': 'demo1',
|
||||
'platform': 'demo'
|
||||
}, {
|
||||
'name': 'demo2',
|
||||
'platform': 'demo'
|
||||
}]
|
||||
})
|
||||
with assert_setup_component(2, notify.DOMAIN), patch.object(
|
||||
demo, "get_service", mock_get_service
|
||||
):
|
||||
setup_component(
|
||||
self.hass,
|
||||
notify.DOMAIN,
|
||||
{
|
||||
"notify": [
|
||||
{"name": "demo1", "platform": "demo"},
|
||||
{"name": "demo2", "platform": "demo"},
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
self.service = run_coroutine_threadsafe(
|
||||
group.async_get_service(self.hass, {'services': [
|
||||
{'service': 'demo1'},
|
||||
{'service': 'demo2',
|
||||
'data': {'target': 'unnamed device',
|
||||
'data': {'test': 'message'}}}]}),
|
||||
self.hass.loop
|
||||
group.async_get_service(
|
||||
self.hass,
|
||||
{
|
||||
"services": [
|
||||
{"service": "demo1"},
|
||||
{
|
||||
"service": "demo2",
|
||||
"data": {
|
||||
"target": "unnamed device",
|
||||
"data": {"test": "message"},
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
),
|
||||
self.hass.loop,
|
||||
).result()
|
||||
|
||||
assert self.service is not None
|
||||
@@ -60,18 +72,20 @@ class TestNotifyGroup(unittest.TestCase):
|
||||
"""Test sending a message with to a notify group."""
|
||||
run_coroutine_threadsafe(
|
||||
self.service.async_send_message(
|
||||
'Hello', title='Test notification', data={'hello': 'world'}),
|
||||
self.hass.loop).result()
|
||||
"Hello", title="Test notification", data={"hello": "world"}
|
||||
),
|
||||
self.hass.loop,
|
||||
).result()
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert self.service1.send_message.mock_calls[0][1][0] == 'Hello'
|
||||
assert self.service1.send_message.mock_calls[0][1][0] == "Hello"
|
||||
assert self.service1.send_message.mock_calls[0][2] == {
|
||||
'title': 'Test notification',
|
||||
'data': {'hello': 'world'}
|
||||
"title": "Test notification",
|
||||
"data": {"hello": "world"},
|
||||
}
|
||||
assert self.service2.send_message.mock_calls[0][1][0] == 'Hello'
|
||||
assert self.service2.send_message.mock_calls[0][1][0] == "Hello"
|
||||
assert self.service2.send_message.mock_calls[0][2] == {
|
||||
'target': ['unnamed device'],
|
||||
'title': 'Test notification',
|
||||
'data': {'hello': 'world', 'test': 'message'}
|
||||
"target": ["unnamed device"],
|
||||
"title": "Test notification",
|
||||
"data": {"hello": "world", "test": "message"},
|
||||
}
|
||||
@@ -12,34 +12,39 @@ async def test_reproduce_group(hass):
|
||||
|
||||
def clone_state(state, entity_id):
|
||||
"""Return a cloned state with different entity_id."""
|
||||
return State(entity_id,
|
||||
state.state,
|
||||
state.attributes,
|
||||
last_changed=state.last_changed,
|
||||
last_updated=state.last_updated,
|
||||
context=state.context)
|
||||
return State(
|
||||
entity_id,
|
||||
state.state,
|
||||
state.attributes,
|
||||
last_changed=state.last_changed,
|
||||
last_updated=state.last_updated,
|
||||
context=state.context,
|
||||
)
|
||||
|
||||
with patch('homeassistant.helpers.state.async_reproduce_state') as fun:
|
||||
with patch("homeassistant.helpers.state.async_reproduce_state") as fun:
|
||||
fun.return_value = Future()
|
||||
fun.return_value.set_result(None)
|
||||
|
||||
hass.states.async_set('group.test', 'off', {
|
||||
'entity_id': ['light.test1', 'light.test2', 'switch.test1']})
|
||||
hass.states.async_set('light.test1', 'off')
|
||||
hass.states.async_set('light.test2', 'off')
|
||||
hass.states.async_set('switch.test1', 'off')
|
||||
hass.states.async_set(
|
||||
"group.test",
|
||||
"off",
|
||||
{"entity_id": ["light.test1", "light.test2", "switch.test1"]},
|
||||
)
|
||||
hass.states.async_set("light.test1", "off")
|
||||
hass.states.async_set("light.test2", "off")
|
||||
hass.states.async_set("switch.test1", "off")
|
||||
|
||||
state = State('group.test', 'on')
|
||||
state = State("group.test", "on")
|
||||
|
||||
await async_reproduce_states(
|
||||
hass,
|
||||
[state],
|
||||
context)
|
||||
await async_reproduce_states(hass, [state], context)
|
||||
|
||||
fun.assert_called_once_with(
|
||||
hass,
|
||||
[clone_state(state, 'light.test1'),
|
||||
clone_state(state, 'light.test2'),
|
||||
clone_state(state, 'switch.test1')],
|
||||
[
|
||||
clone_state(state, "light.test1"),
|
||||
clone_state(state, "light.test2"),
|
||||
clone_state(state, "switch.test1"),
|
||||
],
|
||||
blocking=True,
|
||||
context=context)
|
||||
context=context,
|
||||
)
|
||||
Reference in new issue
Block a user