Prevent more I/O in apns (#6413)
This commit is contained in:
parent
b939626497
commit
307514e3a7
2 changed files with 23 additions and 17 deletions
|
@ -190,7 +190,6 @@ class ApnsNotificationService(BaseNotificationService):
|
||||||
has a tracking id specified.
|
has a tracking id specified.
|
||||||
"""
|
"""
|
||||||
self.device_states[entity_id] = str(to_s.state)
|
self.device_states[entity_id] = str(to_s.state)
|
||||||
return
|
|
||||||
|
|
||||||
def write_devices(self):
|
def write_devices(self):
|
||||||
"""Write all known devices to file."""
|
"""Write all known devices to file."""
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""The tests for the APNS component."""
|
"""The tests for the APNS component."""
|
||||||
import io
|
import io
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch, mock_open
|
||||||
|
|
||||||
from apns2.errors import Unregistered
|
from apns2.errors import Unregistered
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -23,6 +23,7 @@ CONFIG = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@patch('homeassistant.components.notify.apns.open', mock_open(), create=True)
|
||||||
class TestApns(unittest.TestCase):
|
class TestApns(unittest.TestCase):
|
||||||
"""Test the APNS component."""
|
"""Test the APNS component."""
|
||||||
|
|
||||||
|
@ -315,28 +316,34 @@ class TestApns(unittest.TestCase):
|
||||||
"""Test updating an existing device."""
|
"""Test updating an existing device."""
|
||||||
send = mock_client.return_value.send_notification
|
send = mock_client.return_value.send_notification
|
||||||
|
|
||||||
devices_path = self.hass.config.path('test_app_apns.yaml')
|
yaml_file = {
|
||||||
with open(devices_path, 'w+') as out:
|
1234: {
|
||||||
out.write('1234: {name: test device 1, '
|
'name': 'test device 1',
|
||||||
'tracking_device_id: tracking123}\n')
|
'tracking_device_id': 'tracking123',
|
||||||
out.write('5678: {name: test device 2, '
|
},
|
||||||
'tracking_device_id: tracking456}\n')
|
5678: {
|
||||||
|
'name': 'test device 2',
|
||||||
|
'tracking_device_id': 'tracking456',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
notify_service = apns.ApnsNotificationService(
|
with patch(
|
||||||
self.hass,
|
'homeassistant.components.notify.apns.load_yaml_config_file',
|
||||||
'test_app',
|
Mock(return_value=yaml_file)), \
|
||||||
'testapp.appname',
|
patch('os.path.isfile', Mock(return_value=True)):
|
||||||
False,
|
notify_service = apns.ApnsNotificationService(
|
||||||
'test_app.pem'
|
self.hass,
|
||||||
)
|
'test_app',
|
||||||
|
'testapp.appname',
|
||||||
|
False,
|
||||||
|
'test_app.pem'
|
||||||
|
)
|
||||||
|
|
||||||
notify_service.device_state_changed_listener(
|
notify_service.device_state_changed_listener(
|
||||||
'device_tracker.tracking456',
|
'device_tracker.tracking456',
|
||||||
State('device_tracker.tracking456', None),
|
State('device_tracker.tracking456', None),
|
||||||
State('device_tracker.tracking456', 'home'))
|
State('device_tracker.tracking456', 'home'))
|
||||||
|
|
||||||
self.hass.block_till_done()
|
|
||||||
|
|
||||||
notify_service.send_message(message='Hello', target='home')
|
notify_service.send_message(message='Hello', target='home')
|
||||||
|
|
||||||
self.assertTrue(send.called)
|
self.assertTrue(send.called)
|
||||||
|
|
Loading…
Add table
Reference in a new issue