mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Bond - Make assumed state conditional (#38209)
This commit is contained in:
parent
e6e3517a94
commit
02e2c40c48
@ -46,7 +46,7 @@ class BondEntity(Entity):
|
||||
@property
|
||||
def assumed_state(self) -> bool:
|
||||
"""Let HA know this entity relies on an assumed state tracked by Bond."""
|
||||
return True
|
||||
return self._hub.is_bridge and not self._device.trust_state
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
|
@ -24,6 +24,11 @@ class BondDevice:
|
||||
"""Get the type of this device."""
|
||||
return self._attrs["type"]
|
||||
|
||||
@property
|
||||
def trust_state(self) -> bool:
|
||||
"""Check if Trust State is turned on."""
|
||||
return self.props.get("trust_state", False)
|
||||
|
||||
def supports_speed(self) -> bool:
|
||||
"""Return True if this device supports any of the speed related commands."""
|
||||
actions: List[str] = self._attrs["actions"]
|
||||
@ -89,3 +94,8 @@ class BondHub:
|
||||
def devices(self) -> List[BondDevice]:
|
||||
"""Return a list of all devices controlled by this hub."""
|
||||
return self._devices
|
||||
|
||||
@property
|
||||
def is_bridge(self) -> bool:
|
||||
"""Return if the Bond is a Bond Bridge. If False, it means that it is a Smart by Bond product. Assumes that it is if the model is not available."""
|
||||
return self._version.get("model", "BD-").startswith("BD-")
|
||||
|
@ -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
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user