Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix locative device update #24744

Merged
merged 2 commits into from
Jun 25, 2019
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
2 changes: 2 additions & 0 deletions homeassistant/components/locative/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ async def async_will_remove_from_hass(self):
@callback
def _async_receive_data(self, device, location, location_name):
"""Update device data."""
if device != self._name:
return
self._location_name = location_name
self._location = location
self.async_write_ha_state()
37 changes: 37 additions & 0 deletions tests/components/locative/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,43 @@ async def test_exit_first(hass, locative_client, webhook_id):
assert state.state == 'not_home'


async def test_two_devices(hass, locative_client, webhook_id):
"""Test updating two different devices."""
url = '/api/webhook/{}'.format(webhook_id)

data_device_1 = {
'latitude': 40.7855,
'longitude': -111.7367,
'device': 'device_1',
'id': 'Home',
'trigger': 'exit'
}

# Exit Home
req = await locative_client.post(url, data=data_device_1)
await hass.async_block_till_done()
assert req.status == HTTP_OK

state = hass.states.get('{}.{}'.format(DEVICE_TRACKER_DOMAIN,
data_device_1['device']))
assert state.state == 'not_home'

# Enter Home
data_device_2 = dict(data_device_1)
data_device_2['device'] = 'device_2'
data_device_2['trigger'] = 'enter'
req = await locative_client.post(url, data=data_device_2)
await hass.async_block_till_done()
assert req.status == HTTP_OK

state = hass.states.get('{}.{}'.format(DEVICE_TRACKER_DOMAIN,
data_device_2['device']))
assert state.state == 'home'
state = hass.states.get('{}.{}'.format(DEVICE_TRACKER_DOMAIN,
data_device_1['device']))
assert state.state == 'not_home'


@pytest.mark.xfail(
reason='The device_tracker component does not support unloading yet.'
)
Expand Down