From 743166d284819443f3d1f305dc92456aabe45308 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 14 Mar 2020 05:58:32 +0100 Subject: [PATCH] Fix brightness_pct in light device turn_on action (#32787) --- homeassistant/components/light/device_action.py | 10 +++++----- tests/components/light/test_device_action.py | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/light/device_action.py b/homeassistant/components/light/device_action.py index 5ee2785a700..5c534cc4150 100644 --- a/homeassistant/components/light/device_action.py +++ b/homeassistant/components/light/device_action.py @@ -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) ) } diff --git a/tests/components/light/test_device_action.py b/tests/components/light/test_device_action.py index 610f61dea52..6cddfc15744 100644 --- a/tests/components/light/test_device_action.py +++ b/tests/components/light/test_device_action.py @@ -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