Prevent more I/O in apns (#6413)

This commit is contained in:
Paulus Schoutsen 2017-03-04 19:57:04 -08:00 committed by GitHub
parent b939626497
commit 307514e3a7
2 changed files with 23 additions and 17 deletions

View file

@ -190,7 +190,6 @@ class ApnsNotificationService(BaseNotificationService):
has a tracking id specified.
"""
self.device_states[entity_id] = str(to_s.state)
return
def write_devices(self):
"""Write all known devices to file."""

View file

@ -1,7 +1,7 @@
"""The tests for the APNS component."""
import io
import unittest
from unittest.mock import Mock, patch
from unittest.mock import Mock, patch, mock_open
from apns2.errors import Unregistered
import yaml
@ -23,6 +23,7 @@ CONFIG = {
}
@patch('homeassistant.components.notify.apns.open', mock_open(), create=True)
class TestApns(unittest.TestCase):
"""Test the APNS component."""
@ -315,28 +316,34 @@ class TestApns(unittest.TestCase):
"""Test updating an existing device."""
send = mock_client.return_value.send_notification
devices_path = self.hass.config.path('test_app_apns.yaml')
with open(devices_path, 'w+') as out:
out.write('1234: {name: test device 1, '
'tracking_device_id: tracking123}\n')
out.write('5678: {name: test device 2, '
'tracking_device_id: tracking456}\n')
yaml_file = {
1234: {
'name': 'test device 1',
'tracking_device_id': 'tracking123',
},
5678: {
'name': 'test device 2',
'tracking_device_id': 'tracking456',
},
}
notify_service = apns.ApnsNotificationService(
self.hass,
'test_app',
'testapp.appname',
False,
'test_app.pem'
)
with patch(
'homeassistant.components.notify.apns.load_yaml_config_file',
Mock(return_value=yaml_file)), \
patch('os.path.isfile', Mock(return_value=True)):
notify_service = apns.ApnsNotificationService(
self.hass,
'test_app',
'testapp.appname',
False,
'test_app.pem'
)
notify_service.device_state_changed_listener(
'device_tracker.tracking456',
State('device_tracker.tracking456', None),
State('device_tracker.tracking456', 'home'))
self.hass.block_till_done()
notify_service.send_message(message='Hello', target='home')
self.assertTrue(send.called)