diff --git a/homeassistant/components/apns/notify.py b/homeassistant/components/apns/notify.py index dbd45013a3c..c24c9cc1605 100644 --- a/homeassistant/components/apns/notify.py +++ b/homeassistant/components/apns/notify.py @@ -1,14 +1,11 @@ """APNS Notification platform.""" import logging +from apns2.client import APNsClient +from apns2.errors import Unregistered +from apns2.payload import Payload import voluptuous as vol -from homeassistant.config import load_yaml_config_file -from homeassistant.const import ATTR_NAME, CONF_NAME, CONF_PLATFORM -from homeassistant.helpers import template as template_helper -import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.event import track_state_change - from homeassistant.components.notify import ( ATTR_DATA, ATTR_TARGET, @@ -16,6 +13,11 @@ from homeassistant.components.notify import ( PLATFORM_SCHEMA, BaseNotificationService, ) +from homeassistant.config import load_yaml_config_file +from homeassistant.const import ATTR_NAME, CONF_NAME, CONF_PLATFORM +from homeassistant.helpers import template as template_helper +import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.event import track_state_change APNS_DEVICES = "apns.yaml" CONF_CERTFILE = "cert_file" @@ -213,9 +215,6 @@ class ApnsNotificationService(BaseNotificationService): def send_message(self, message=None, **kwargs): """Send push message to registered devices.""" - from apns2.client import APNsClient - from apns2.payload import Payload - from apns2.errors import Unregistered apns = APNsClient( self.certificate, use_sandbox=self.sandbox, use_alternative_port=False diff --git a/tests/components/apns/test_notify.py b/tests/components/apns/test_notify.py index a4202f74d39..78f597c58ad 100644 --- a/tests/components/apns/test_notify.py +++ b/tests/components/apns/test_notify.py @@ -239,7 +239,7 @@ class TestApns(unittest.TestCase): assert "tracking123" == test_device_1.tracking_device_id assert "tracking456" == test_device_2.tracking_device_id - @patch("apns2.client.APNsClient") + @patch("homeassistant.components.apns.notify.APNsClient") def test_send(self, mock_client): """Test updating an existing device.""" send = mock_client.return_value.send_notification @@ -274,7 +274,7 @@ class TestApns(unittest.TestCase): assert "test.mp3" == payload.sound assert "testing" == payload.category - @patch("apns2.client.APNsClient") + @patch("homeassistant.components.apns.notify.APNsClient") def test_send_when_disabled(self, mock_client): """Test updating an existing device.""" send = mock_client.return_value.send_notification @@ -299,7 +299,7 @@ class TestApns(unittest.TestCase): assert not send.called - @patch("apns2.client.APNsClient") + @patch("homeassistant.components.apns.notify.APNsClient") def test_send_with_state(self, mock_client): """Test updating an existing device.""" send = mock_client.return_value.send_notification @@ -334,7 +334,7 @@ class TestApns(unittest.TestCase): assert "5678" == target assert "Hello" == payload.alert - @patch("apns2.client.APNsClient") + @patch("homeassistant.components.apns.notify.APNsClient") @patch("homeassistant.components.apns.notify._write_device") def test_disable_when_unregistered(self, mock_write, mock_client): """Test disabling a device when it is unregistered."""