1
mirror of https://github.com/home-assistant/core synced 2024-07-12 07:21:24 +02:00

Fix missing service call context in multiple locations (#37094)

This commit is contained in:
Franck Nijhof 2020-06-26 02:09:52 +02:00 committed by GitHub
parent 98a388e65a
commit f42eb0d5ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 66 additions and 23 deletions

View File

@ -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."""

View File

@ -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."""

View File

@ -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):

View File

@ -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):

View File

@ -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:

View File

@ -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."""

View File

@ -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):

View File

@ -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}")

View File

@ -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

View File

@ -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
)