Report device unavailable state through Emulated Hue (#29029)
If an entity is in unavailable state in HA, we expose this as unreachable to Hue clients. This helps when troubleshooting Hue issues because you can now receive feedback if there is an issue on the HA side.pull/29046/head
parent
aa00e56e1c
commit
5690313084
|
@ -56,6 +56,7 @@ from homeassistant.const import (
|
|||
SERVICE_VOLUME_SET,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.util.network import is_local
|
||||
|
||||
|
@ -578,7 +579,7 @@ def entity_to_json(config, entity, state):
|
|||
HUE_API_STATE_BRI: state[STATE_BRIGHTNESS],
|
||||
HUE_API_STATE_HUE: state[STATE_HUE],
|
||||
HUE_API_STATE_SAT: state[STATE_SATURATION],
|
||||
"reachable": True,
|
||||
"reachable": entity.state != STATE_UNAVAILABLE,
|
||||
},
|
||||
"type": "Dimmable light",
|
||||
"name": config.get_entity_name(entity),
|
||||
|
@ -587,7 +588,10 @@ def entity_to_json(config, entity, state):
|
|||
"swversion": "123",
|
||||
}
|
||||
return {
|
||||
"state": {HUE_API_STATE_ON: state[STATE_ON], "reachable": True},
|
||||
"state": {
|
||||
HUE_API_STATE_ON: state[STATE_ON],
|
||||
"reachable": entity.state != STATE_UNAVAILABLE,
|
||||
},
|
||||
"type": "On/off light",
|
||||
"name": config.get_entity_name(entity),
|
||||
"modelid": "HASS321",
|
||||
|
|
|
@ -232,6 +232,26 @@ def test_light_without_brightness_supported(hass_hue, hue_client):
|
|||
assert light_without_brightness_json["type"] == "On/off light"
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
@pytest.mark.parametrize(
|
||||
"state,is_reachable",
|
||||
[
|
||||
(const.STATE_UNAVAILABLE, False),
|
||||
(const.STATE_OK, True),
|
||||
(const.STATE_UNKNOWN, True),
|
||||
],
|
||||
)
|
||||
def test_reachable_for_state(hass_hue, hue_client, state, is_reachable):
|
||||
"""Test that an entity is reported as unreachable if in unavailable state."""
|
||||
entity_id = "light.ceiling_lights"
|
||||
|
||||
hass_hue.states.async_set(entity_id, state)
|
||||
|
||||
state_json = yield from perform_get_light_state(hue_client, entity_id, 200)
|
||||
|
||||
assert state_json["state"]["reachable"] == is_reachable, state_json
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_light_state(hass_hue, hue_client):
|
||||
"""Test the getting of light state."""
|
||||
|
|
Loading…
Reference in New Issue