Fix brightness_pct in light device turn_on action (#32787)
This commit is contained in:
parent
b5c8b5b91f
commit
e666485ea9
2 changed files with 9 additions and 9 deletions
|
@ -15,7 +15,7 @@ from homeassistant.core import Context, HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv, entity_registry
|
from homeassistant.helpers import config_validation as cv, entity_registry
|
||||||
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
|
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_INCREASE = "brightness_increase"
|
||||||
TYPE_BRIGHTNESS_DECREASE = "brightness_decrease"
|
TYPE_BRIGHTNESS_DECREASE = "brightness_decrease"
|
||||||
|
@ -28,7 +28,7 @@ ACTION_SCHEMA = cv.DEVICE_ACTION_BASE_SCHEMA.extend(
|
||||||
toggle_entity.DEVICE_ACTION_TYPES
|
toggle_entity.DEVICE_ACTION_TYPES
|
||||||
+ [TYPE_BRIGHTNESS_INCREASE, TYPE_BRIGHTNESS_DECREASE]
|
+ [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)
|
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
|
data[ATTR_BRIGHTNESS_STEP_PCT] = 10
|
||||||
elif config[CONF_TYPE] == TYPE_BRIGHTNESS_DECREASE:
|
elif config[CONF_TYPE] == TYPE_BRIGHTNESS_DECREASE:
|
||||||
data[ATTR_BRIGHTNESS_STEP_PCT] = -10
|
data[ATTR_BRIGHTNESS_STEP_PCT] = -10
|
||||||
elif ATTR_BRIGHTNESS in config:
|
elif ATTR_BRIGHTNESS_PCT in config:
|
||||||
data[ATTR_BRIGHTNESS] = config[ATTR_BRIGHTNESS]
|
data[ATTR_BRIGHTNESS_PCT] = config[ATTR_BRIGHTNESS_PCT]
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN, SERVICE_TURN_ON, data, blocking=True, context=context
|
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 {
|
return {
|
||||||
"extra_fields": vol.Schema(
|
"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)
|
vol.Coerce(int), vol.Range(min=0, max=100)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ async def test_get_action_capabilities_brightness(hass, device_reg, entity_reg):
|
||||||
expected_capabilities = {
|
expected_capabilities = {
|
||||||
"extra_fields": [
|
"extra_fields": [
|
||||||
{
|
{
|
||||||
"name": "brightness",
|
"name": "brightness_pct",
|
||||||
"optional": True,
|
"optional": True,
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"valueMax": 100,
|
"valueMax": 100,
|
||||||
|
@ -218,7 +218,7 @@ async def test_action(hass, calls):
|
||||||
"device_id": "",
|
"device_id": "",
|
||||||
"entity_id": ent1.entity_id,
|
"entity_id": ent1.entity_id,
|
||||||
"type": "turn_on",
|
"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 len(turn_on_calls) == 3
|
||||||
assert turn_on_calls[2].data["entity_id"] == ent1.entity_id
|
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")
|
hass.bus.async_fire("test_on")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(turn_on_calls) == 4
|
assert len(turn_on_calls) == 4
|
||||||
assert turn_on_calls[3].data["entity_id"] == ent1.entity_id
|
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue