Fix brightness_pct in light device turn_on action (#32787)

pull/32789/head
Franck Nijhof 2020-03-14 05:58:32 +01:00 committed by GitHub
parent 5dd031af17
commit 743166d284
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View File

@ -15,7 +15,7 @@ from homeassistant.core import Context, HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_registry
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
from . import ATTR_BRIGHTNESS, ATTR_BRIGHTNESS_STEP_PCT, DOMAIN, SUPPORT_BRIGHTNESS
from . import ATTR_BRIGHTNESS_PCT, ATTR_BRIGHTNESS_STEP_PCT, DOMAIN, SUPPORT_BRIGHTNESS
TYPE_BRIGHTNESS_INCREASE = "brightness_increase"
TYPE_BRIGHTNESS_DECREASE = "brightness_decrease"
@ -28,7 +28,7 @@ ACTION_SCHEMA = cv.DEVICE_ACTION_BASE_SCHEMA.extend(
toggle_entity.DEVICE_ACTION_TYPES
+ [TYPE_BRIGHTNESS_INCREASE, TYPE_BRIGHTNESS_DECREASE]
),
vol.Optional(ATTR_BRIGHTNESS): vol.All(
vol.Optional(ATTR_BRIGHTNESS_PCT): vol.All(
vol.Coerce(int), vol.Range(min=0, max=100)
),
}
@ -57,8 +57,8 @@ async def async_call_action_from_config(
data[ATTR_BRIGHTNESS_STEP_PCT] = 10
elif config[CONF_TYPE] == TYPE_BRIGHTNESS_DECREASE:
data[ATTR_BRIGHTNESS_STEP_PCT] = -10
elif ATTR_BRIGHTNESS in config:
data[ATTR_BRIGHTNESS] = config[ATTR_BRIGHTNESS]
elif ATTR_BRIGHTNESS_PCT in config:
data[ATTR_BRIGHTNESS_PCT] = config[ATTR_BRIGHTNESS_PCT]
await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, data, blocking=True, context=context
@ -125,7 +125,7 @@ async def async_get_action_capabilities(hass: HomeAssistant, config: dict) -> di
return {
"extra_fields": vol.Schema(
{
vol.Optional(ATTR_BRIGHTNESS): vol.All(
vol.Optional(ATTR_BRIGHTNESS_PCT): vol.All(
vol.Coerce(int), vol.Range(min=0, max=100)
)
}

View File

@ -126,7 +126,7 @@ async def test_get_action_capabilities_brightness(hass, device_reg, entity_reg):
expected_capabilities = {
"extra_fields": [
{
"name": "brightness",
"name": "brightness_pct",
"optional": True,
"type": "integer",
"valueMax": 100,
@ -218,7 +218,7 @@ async def test_action(hass, calls):
"device_id": "",
"entity_id": ent1.entity_id,
"type": "turn_on",
"brightness": 75,
"brightness_pct": 75,
},
},
]
@ -273,11 +273,11 @@ async def test_action(hass, calls):
assert len(turn_on_calls) == 3
assert turn_on_calls[2].data["entity_id"] == ent1.entity_id
assert turn_on_calls[2].data["brightness"] == 75
assert turn_on_calls[2].data["brightness_pct"] == 75
hass.bus.async_fire("test_on")
await hass.async_block_till_done()
assert len(turn_on_calls) == 4
assert turn_on_calls[3].data["entity_id"] == ent1.entity_id
assert "brightness" not in turn_on_calls[3].data
assert "brightness_pct" not in turn_on_calls[3].data