Bond - Make assumed state conditional (#38209)

This commit is contained in:
Marcio Granzotto Rodrigues authored and GitHub committed 2020-07-27 20:39:23 -05:00
1 parent e6e3517a94
commit 02e2c40c48
4 files changed
+60 -3

No files matched your search

+2 -1
View File
@@ -51,6 +51,7 @@ async def setup_platform(
discovered_device: Dict[str, Any],
bond_device_id: str = "bond-device-id",
props: Dict[str, Any] = None,
bond_version: Dict[str, Any] = None,
):
"""Set up the specified Bond platform."""
mock_entry = MockConfigEntry(
@@ -60,7 +61,7 @@ async def setup_platform(
mock_entry.add_to_hass(hass)
with patch("homeassistant.components.bond.PLATFORMS", [platform]):
with patch_bond_version(), patch_bond_device_ids(
with patch_bond_version(return_value=bond_version), patch_bond_device_ids(
return_value=[bond_device_id]
), patch_bond_device(
return_value=discovered_device
+47 -1
View File
@@ -6,7 +6,12 @@ from bond_api import Action, DeviceType
from homeassistant import core
from homeassistant.components.light import ATTR_BRIGHTNESS, DOMAIN as LIGHT_DOMAIN
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.const import (
ATTR_ASSUMED_STATE,
ATTR_ENTITY_ID,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
)
from homeassistant.helpers.entity_registry import EntityRegistry
from homeassistant.util import utcnow
@@ -44,6 +49,47 @@ async def test_entity_registry(hass: core.HomeAssistant):
assert [key for key in registry.entities] == ["light.name_1"]
async def test_sbb_trust_state(hass: core.HomeAssistant):
"""Assumed state should be False if device is a Smart by Bond."""
version = {
"model": "MR123A",
"bondid": "test-bond-id",
}
await setup_platform(
hass, LIGHT_DOMAIN, ceiling_fan("name-1"), bond_version=version
)
device = hass.states.get("light.name_1")
assert device.attributes.get(ATTR_ASSUMED_STATE) is not True
async def test_trust_state_not_specified(hass: core.HomeAssistant):
"""Assumed state should be True if Trust State is not specified."""
await setup_platform(hass, LIGHT_DOMAIN, ceiling_fan("name-1"))
device = hass.states.get("light.name_1")
assert device.attributes.get(ATTR_ASSUMED_STATE) is True
async def test_trust_state(hass: core.HomeAssistant):
"""Assumed state should be True if Trust State is False."""
await setup_platform(
hass, LIGHT_DOMAIN, ceiling_fan("name-1"), props={"trust_state": False}
)
device = hass.states.get("light.name_1")
assert device.attributes.get(ATTR_ASSUMED_STATE) is True
async def test_no_trust_state(hass: core.HomeAssistant):
"""Assumed state should be False if Trust State is True."""
await setup_platform(
hass, LIGHT_DOMAIN, ceiling_fan("name-1"), props={"trust_state": True}
)
device = hass.states.get("light.name_1")
assert device.attributes.get(ATTR_ASSUMED_STATE) is not True
async def test_turn_on_light(hass: core.HomeAssistant):
"""Tests that turn on command delegates to API."""
await setup_platform(