From f42eb0d5cadb2ebd2eeb5a5f1240fda9163da46c Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Fri, 26 Jun 2020 02:09:52 +0200 Subject: [PATCH] Fix missing service call context in multiple locations (#37094) --- homeassistant/components/alert/__init__.py | 4 +++- .../components/generic_thermostat/climate.py | 8 +++++-- homeassistant/components/group/cover.py | 24 ++++++++++++------- homeassistant/components/group/light.py | 19 ++++++++++++--- .../components/homeassistant/__init__.py | 4 +++- homeassistant/components/lifx/light.py | 4 +++- homeassistant/components/switch/light.py | 12 ++++++++-- homeassistant/components/tts/__init__.py | 6 ++++- .../components/universal/media_player.py | 2 +- tests/components/group/test_light.py | 6 ++--- 10 files changed, 66 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/alert/__init__.py b/homeassistant/components/alert/__init__.py index 0ac4621cb0a7..d85c13731b2a 100644 --- a/homeassistant/components/alert/__init__.py +++ b/homeassistant/components/alert/__init__.py @@ -305,7 +305,9 @@ class Alert(ToggleEntity): _LOGGER.debug(msg_payload) for target in self._notifiers: - await self.hass.services.async_call(DOMAIN_NOTIFY, target, msg_payload) + await self.hass.services.async_call( + DOMAIN_NOTIFY, target, msg_payload, context=self._context + ) async def async_turn_on(self, **kwargs): """Async Unacknowledge alert.""" diff --git a/homeassistant/components/generic_thermostat/climate.py b/homeassistant/components/generic_thermostat/climate.py index d78895134028..407923dc1610 100644 --- a/homeassistant/components/generic_thermostat/climate.py +++ b/homeassistant/components/generic_thermostat/climate.py @@ -449,12 +449,16 @@ class GenericThermostat(ClimateEntity, RestoreEntity): async def _async_heater_turn_on(self): """Turn heater toggleable device on.""" data = {ATTR_ENTITY_ID: self.heater_entity_id} - await self.hass.services.async_call(HA_DOMAIN, SERVICE_TURN_ON, data) + await self.hass.services.async_call( + HA_DOMAIN, SERVICE_TURN_ON, data, context=self._context + ) async def _async_heater_turn_off(self): """Turn heater toggleable device off.""" data = {ATTR_ENTITY_ID: self.heater_entity_id} - await self.hass.services.async_call(HA_DOMAIN, SERVICE_TURN_OFF, data) + await self.hass.services.async_call( + HA_DOMAIN, SERVICE_TURN_OFF, data, context=self._context + ) async def async_set_preset_mode(self, preset_mode: str): """Set new preset mode.""" diff --git a/homeassistant/components/group/cover.py b/homeassistant/components/group/cover.py index 2638ce072a31..427530dadb50 100644 --- a/homeassistant/components/group/cover.py +++ b/homeassistant/components/group/cover.py @@ -209,21 +209,21 @@ class CoverGroup(CoverEntity): """Move the covers up.""" data = {ATTR_ENTITY_ID: self._covers[KEY_OPEN_CLOSE]} await self.hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, data, blocking=True + DOMAIN, SERVICE_OPEN_COVER, data, blocking=True, context=self._context ) async def async_close_cover(self, **kwargs): """Move the covers down.""" data = {ATTR_ENTITY_ID: self._covers[KEY_OPEN_CLOSE]} await self.hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, data, blocking=True + DOMAIN, SERVICE_CLOSE_COVER, data, blocking=True, context=self._context ) async def async_stop_cover(self, **kwargs): """Fire the stop action.""" data = {ATTR_ENTITY_ID: self._covers[KEY_STOP]} await self.hass.services.async_call( - DOMAIN, SERVICE_STOP_COVER, data, blocking=True + DOMAIN, SERVICE_STOP_COVER, data, blocking=True, context=self._context ) async def async_set_cover_position(self, **kwargs): @@ -233,28 +233,32 @@ class CoverGroup(CoverEntity): ATTR_POSITION: kwargs[ATTR_POSITION], } await self.hass.services.async_call( - DOMAIN, SERVICE_SET_COVER_POSITION, data, blocking=True + DOMAIN, + SERVICE_SET_COVER_POSITION, + data, + blocking=True, + context=self._context, ) async def async_open_cover_tilt(self, **kwargs): """Tilt covers open.""" data = {ATTR_ENTITY_ID: self._tilts[KEY_OPEN_CLOSE]} await self.hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER_TILT, data, blocking=True + DOMAIN, SERVICE_OPEN_COVER_TILT, data, blocking=True, context=self._context ) async def async_close_cover_tilt(self, **kwargs): """Tilt covers closed.""" data = {ATTR_ENTITY_ID: self._tilts[KEY_OPEN_CLOSE]} await self.hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER_TILT, data, blocking=True + DOMAIN, SERVICE_CLOSE_COVER_TILT, data, blocking=True, context=self._context ) async def async_stop_cover_tilt(self, **kwargs): """Stop cover tilt.""" data = {ATTR_ENTITY_ID: self._tilts[KEY_STOP]} await self.hass.services.async_call( - DOMAIN, SERVICE_STOP_COVER_TILT, data, blocking=True + DOMAIN, SERVICE_STOP_COVER_TILT, data, blocking=True, context=self._context ) async def async_set_cover_tilt_position(self, **kwargs): @@ -264,7 +268,11 @@ class CoverGroup(CoverEntity): ATTR_TILT_POSITION: kwargs[ATTR_TILT_POSITION], } await self.hass.services.async_call( - DOMAIN, SERVICE_SET_COVER_TILT_POSITION, data, blocking=True + DOMAIN, + SERVICE_SET_COVER_TILT_POSITION, + data, + blocking=True, + context=self._context, ) async def async_update(self): diff --git a/homeassistant/components/group/light.py b/homeassistant/components/group/light.py index 1136df7eac06..69329b96122c 100644 --- a/homeassistant/components/group/light.py +++ b/homeassistant/components/group/light.py @@ -233,7 +233,11 @@ class LightGroup(light.LightEntity): if not emulate_color_temp_entity_ids: await self.hass.services.async_call( - light.DOMAIN, light.SERVICE_TURN_ON, data, blocking=True + light.DOMAIN, + light.SERVICE_TURN_ON, + data, + blocking=True, + context=self._context, ) return @@ -249,13 +253,18 @@ class LightGroup(light.LightEntity): await asyncio.gather( self.hass.services.async_call( - light.DOMAIN, light.SERVICE_TURN_ON, data, blocking=True + light.DOMAIN, + light.SERVICE_TURN_ON, + data, + blocking=True, + context=self._context, ), self.hass.services.async_call( light.DOMAIN, light.SERVICE_TURN_ON, emulate_color_temp_data, blocking=True, + context=self._context, ), ) @@ -267,7 +276,11 @@ class LightGroup(light.LightEntity): data[ATTR_TRANSITION] = kwargs[ATTR_TRANSITION] await self.hass.services.async_call( - light.DOMAIN, light.SERVICE_TURN_OFF, data, blocking=True + light.DOMAIN, + light.SERVICE_TURN_OFF, + data, + blocking=True, + context=self._context, ) async def async_update(self): diff --git a/homeassistant/components/homeassistant/__init__.py b/homeassistant/components/homeassistant/__init__.py index e0a4d88ec6a4..83166ba4cce7 100644 --- a/homeassistant/components/homeassistant/__init__.py +++ b/homeassistant/components/homeassistant/__init__.py @@ -78,7 +78,9 @@ async def async_setup(hass: ha.HomeAssistant, config: dict) -> bool: data[ATTR_ENTITY_ID] = list(ent_ids) tasks.append( - hass.services.async_call(domain, service.service, data, blocking) + hass.services.async_call( + domain, service.service, data, blocking, context=service.context + ) ) if tasks: diff --git a/homeassistant/components/lifx/light.py b/homeassistant/components/lifx/light.py index 2b7629cdaf20..26a2acfa5176 100644 --- a/homeassistant/components/lifx/light.py +++ b/homeassistant/components/lifx/light.py @@ -641,7 +641,9 @@ class LIFXLight(LightEntity): """Start an effect with default parameters.""" service = kwargs[ATTR_EFFECT] data = {ATTR_ENTITY_ID: self.entity_id} - await self.hass.services.async_call(LIFX_DOMAIN, service, data) + await self.hass.services.async_call( + LIFX_DOMAIN, service, data, context=self._context + ) async def async_update(self): """Update bulb status.""" diff --git a/homeassistant/components/switch/light.py b/homeassistant/components/switch/light.py index f40ccde5b0b0..c23390a3e3e6 100644 --- a/homeassistant/components/switch/light.py +++ b/homeassistant/components/switch/light.py @@ -84,14 +84,22 @@ class LightSwitch(LightEntity): """Forward the turn_on command to the switch in this light switch.""" data = {ATTR_ENTITY_ID: self._switch_entity_id} await self.hass.services.async_call( - switch.DOMAIN, switch.SERVICE_TURN_ON, data, blocking=True + switch.DOMAIN, + switch.SERVICE_TURN_ON, + data, + blocking=True, + context=self._context, ) async def async_turn_off(self, **kwargs): """Forward the turn_off command to the switch in this light switch.""" data = {ATTR_ENTITY_ID: self._switch_entity_id} await self.hass.services.async_call( - switch.DOMAIN, switch.SERVICE_TURN_OFF, data, blocking=True + switch.DOMAIN, + switch.SERVICE_TURN_OFF, + data, + blocking=True, + context=self._context, ) async def async_update(self): diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index ebd7a1c84118..39e4702e8557 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -175,7 +175,11 @@ async def async_setup(hass, config): } await hass.services.async_call( - DOMAIN_MP, SERVICE_PLAY_MEDIA, data, blocking=True + DOMAIN_MP, + SERVICE_PLAY_MEDIA, + data, + blocking=True, + context=service.context, ) service_name = p_config.get(CONF_SERVICE_NAME, f"{p_type}_{SERVICE_SAY}") diff --git a/homeassistant/components/universal/media_player.py b/homeassistant/components/universal/media_player.py index f1cad7e8abfc..ec4b53cd2e0c 100644 --- a/homeassistant/components/universal/media_player.py +++ b/homeassistant/components/universal/media_player.py @@ -205,7 +205,7 @@ class UniversalMediaPlayer(MediaPlayerEntity): service_data[ATTR_ENTITY_ID] = active_child.entity_id await self.hass.services.async_call( - DOMAIN, service_name, service_data, blocking=True + DOMAIN, service_name, service_data, blocking=True, context=self._context ) @property diff --git a/tests/components/group/test_light.py b/tests/components/group/test_light.py index 1f68279ae05c..2a2e21f77c50 100644 --- a/tests/components/group/test_light.py +++ b/tests/components/group/test_light.py @@ -570,14 +570,14 @@ async def test_invalid_service_calls(hass): await grouped_light.async_turn_on(brightness=150, four_oh_four="404") data = {ATTR_ENTITY_ID: ["light.test1", "light.test2"], ATTR_BRIGHTNESS: 150} mock_call.assert_called_once_with( - LIGHT_DOMAIN, SERVICE_TURN_ON, data, blocking=True + LIGHT_DOMAIN, SERVICE_TURN_ON, data, blocking=True, context=None ) mock_call.reset_mock() await grouped_light.async_turn_off(transition=4, four_oh_four="404") data = {ATTR_ENTITY_ID: ["light.test1", "light.test2"], ATTR_TRANSITION: 4} mock_call.assert_called_once_with( - LIGHT_DOMAIN, SERVICE_TURN_OFF, data, blocking=True + LIGHT_DOMAIN, SERVICE_TURN_OFF, data, blocking=True, context=None ) mock_call.reset_mock() @@ -596,5 +596,5 @@ async def test_invalid_service_calls(hass): data.pop(ATTR_RGB_COLOR) data.pop(ATTR_XY_COLOR) mock_call.assert_called_once_with( - LIGHT_DOMAIN, SERVICE_TURN_ON, data, blocking=True + LIGHT_DOMAIN, SERVICE_TURN_ON, data, blocking=True, context=None )