From 34c694c20e84f827dc1343716fb2b94521adea4c Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 9 Mar 2018 19:39:50 -0800 Subject: [PATCH] allow ios device tracker see calls to go through (#13020) --- .../components/device_tracker/__init__.py | 9 ++++++++- tests/components/device_tracker/test_init.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/device_tracker/__init__.py b/homeassistant/components/device_tracker/__init__.py index 196c11a614f..9fea2bc104d 100644 --- a/homeassistant/components/device_tracker/__init__.py +++ b/homeassistant/components/device_tracker/__init__.py @@ -111,6 +111,9 @@ SERVICE_SEE_PAYLOAD_SCHEMA = vol.Schema(vol.All( ATTR_ATTRIBUTES: dict, ATTR_SOURCE_TYPE: vol.In(SOURCE_TYPES), ATTR_CONSIDER_HOME: cv.time_period, + # Temp workaround for iOS app introduced in 0.65 + vol.Optional('battery_status'): str, + vol.Optional('hostname'): str, })) @@ -219,7 +222,11 @@ def async_setup(hass: HomeAssistantType, config: ConfigType): @asyncio.coroutine def async_see_service(call): """Service to see a device.""" - yield from tracker.async_see(**call.data) + # Temp workaround for iOS, introduced in 0.65 + data = dict(call.data) + data.pop('hostname', None) + data.pop('battery_status', None) + yield from tracker.async_see(**data) hass.services.async_register( DOMAIN, SERVICE_SEE, async_see_service, SERVICE_SEE_PAYLOAD_SCHEMA) diff --git a/tests/components/device_tracker/test_init.py b/tests/components/device_tracker/test_init.py index ebf568309ad..9d122fa17b6 100644 --- a/tests/components/device_tracker/test_init.py +++ b/tests/components/device_tracker/test_init.py @@ -730,3 +730,18 @@ async def test_old_style_track_new_is_skipped(mock_device_tracker_conf, hass): await hass.async_block_till_done() assert len(mock_device_tracker_conf) == 1 assert mock_device_tracker_conf[0].track is False + + +def test_see_schema_allowing_ios_calls(): + """Test SEE service schema allows extra keys. + + Temp work around because the iOS app sends incorrect data. + """ + device_tracker.SERVICE_SEE_PAYLOAD_SCHEMA({ + 'dev_id': 'Test', + "battery": 35, + "battery_status": 'Unplugged', + "gps": [10.0, 10.0], + "gps_accuracy": 300, + "hostname": 'beer', + })