Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report device unavailable state through Emulated Hue #29029

Merged
merged 1 commit into from Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions homeassistant/components/emulated_hue/hue_api.py
Expand Up @@ -56,6 +56,7 @@
SERVICE_VOLUME_SET,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.util.network import is_local

Expand Down Expand Up @@ -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),
Expand All @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions tests/components/emulated_hue/test_hue_api.py
Expand Up @@ -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."""
Expand Down