Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions homeassistant/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,9 +1098,11 @@ async def async_call(self, domain: str, service: str,
raise ServiceNotFound(domain, service) from None

if handler.schema:
service_data = handler.schema(service_data)
processed_data = handler.schema(service_data)
else:
processed_data = service_data

service_call = ServiceCall(domain, service, service_data, context)
service_call = ServiceCall(domain, service, processed_data, context)

self._hass.bus.async_fire(EVENT_CALL_SERVICE, {
ATTR_DOMAIN: domain.lower(),
Expand Down
27 changes: 26 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from datetime import datetime, timedelta
from tempfile import TemporaryDirectory

import voluptuous as vol
import pytz
import pytest

Expand All @@ -21,7 +22,7 @@
__version__, EVENT_STATE_CHANGED, ATTR_FRIENDLY_NAME, CONF_UNIT_SYSTEM,
ATTR_NOW, EVENT_TIME_CHANGED, EVENT_TIMER_OUT_OF_SYNC, ATTR_SECONDS,
EVENT_HOMEASSISTANT_STOP, EVENT_HOMEASSISTANT_CLOSE,
EVENT_SERVICE_REGISTERED, EVENT_SERVICE_REMOVED)
EVENT_SERVICE_REGISTERED, EVENT_SERVICE_REMOVED, EVENT_CALL_SERVICE)

from tests.common import get_test_home_assistant, async_mock_service

Expand Down Expand Up @@ -1000,3 +1001,27 @@ async def handle_outer(call):
assert len(calls) == 4
assert [call.service for call in calls] == [
'outer', 'inner', 'inner', 'outer']


async def test_service_call_event_contains_original_data(hass):
"""Test that service call event contains original data."""
events = []

@ha.callback
def callback(event):
events.append(event)

hass.bus.async_listen(EVENT_CALL_SERVICE, callback)

calls = async_mock_service(hass, 'test', 'service', vol.Schema({
'number': vol.Coerce(int)
}))

await hass.services.async_call('test', 'service', {
'number': '23'
}, blocking=True)
await hass.async_block_till_done()
assert len(events) == 1
assert events[0].data['service_data']['number'] == '23'
assert len(calls) == 1
assert calls[0].data['number'] == 23