mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix wrong exposed light for emulated hue (#25581)
* Add auto detect if brightness is supported * Fix * Fix tests * Cleanup
This commit is contained in:
parent
3a3f70ef21
commit
8ffc6c05b7
@ -517,21 +517,35 @@ def get_entity_state(config, entity):
|
|||||||
|
|
||||||
def entity_to_json(config, entity, state):
|
def entity_to_json(config, entity, state):
|
||||||
"""Convert an entity to its Hue bridge JSON representation."""
|
"""Convert an entity to its Hue bridge JSON representation."""
|
||||||
|
entity_features = entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||||
|
if entity_features & SUPPORT_BRIGHTNESS:
|
||||||
|
return {
|
||||||
|
'state':
|
||||||
|
{
|
||||||
|
HUE_API_STATE_ON: state[STATE_ON],
|
||||||
|
HUE_API_STATE_BRI: state[STATE_BRIGHTNESS],
|
||||||
|
HUE_API_STATE_HUE: state[STATE_HUE],
|
||||||
|
HUE_API_STATE_SAT: state[STATE_SATURATION],
|
||||||
|
'reachable': True
|
||||||
|
},
|
||||||
|
'type': 'Dimmable light',
|
||||||
|
'name': config.get_entity_name(entity),
|
||||||
|
'modelid': 'HASS123',
|
||||||
|
'uniqueid': entity.entity_id,
|
||||||
|
'swversion': '123'
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
'state':
|
'state':
|
||||||
{
|
{
|
||||||
HUE_API_STATE_ON: state[STATE_ON],
|
HUE_API_STATE_ON: state[STATE_ON],
|
||||||
HUE_API_STATE_BRI: state[STATE_BRIGHTNESS],
|
|
||||||
HUE_API_STATE_HUE: state[STATE_HUE],
|
|
||||||
HUE_API_STATE_SAT: state[STATE_SATURATION],
|
|
||||||
'reachable': True
|
'reachable': True
|
||||||
},
|
},
|
||||||
'type': 'Dimmable light',
|
'type': 'On/off light',
|
||||||
'name': config.get_entity_name(entity),
|
'name': config.get_entity_name(entity),
|
||||||
'modelid': 'HASS123',
|
'modelid': 'HASS123',
|
||||||
'uniqueid': entity.entity_id,
|
'uniqueid': entity.entity_id,
|
||||||
'swversion': '123'
|
'swversion': '123'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def create_hue_success_response(entity_id, attr, value):
|
def create_hue_success_response(entity_id, attr, value):
|
||||||
|
@ -121,6 +121,10 @@ def hass_hue(loop, hass):
|
|||||||
kitchen_light_entity.entity_id, kitchen_light_entity.state,
|
kitchen_light_entity.entity_id, kitchen_light_entity.state,
|
||||||
attributes=attrs)
|
attributes=attrs)
|
||||||
|
|
||||||
|
# create a lamp without brightness support
|
||||||
|
hass.states.async_set(
|
||||||
|
'light.no_brightness', 'on', {})
|
||||||
|
|
||||||
# Ceiling Fan is explicitly excluded from being exposed
|
# Ceiling Fan is explicitly excluded from being exposed
|
||||||
ceiling_fan_entity = hass.states.get('fan.ceiling_fan')
|
ceiling_fan_entity = hass.states.get('fan.ceiling_fan')
|
||||||
attrs = dict(ceiling_fan_entity.attributes)
|
attrs = dict(ceiling_fan_entity.attributes)
|
||||||
@ -219,6 +223,15 @@ def test_discover_lights(hue_client):
|
|||||||
assert 'climate.ecobee' not in devices
|
assert 'climate.ecobee' not in devices
|
||||||
|
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def test_light_without_brightness_supported(hass_hue, hue_client):
|
||||||
|
light_without_brightness_json = yield from perform_get_light_state(
|
||||||
|
hue_client, 'light.no_brightness', 200)
|
||||||
|
|
||||||
|
assert light_without_brightness_json['state'][HUE_API_STATE_ON] is True
|
||||||
|
assert light_without_brightness_json['type'] == 'On/off light'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_get_light_state(hass_hue, hue_client):
|
def test_get_light_state(hass_hue, hue_client):
|
||||||
"""Test the getting of light state."""
|
"""Test the getting of light state."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user