"""
Pushetta platform for notify component.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/notify.pushetta/
"""
import logging

import voluptuous as vol

from homeassistant.components.notify import (
    ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA, BaseNotificationService)
from homeassistant.const import CONF_API_KEY
import homeassistant.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['pushetta==1.0.15']


CONF_CHANNEL_NAME = 'channel_name'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_API_KEY): cv.string,
    vol.Required(CONF_CHANNEL_NAME): cv.string,
})


def get_service(hass, config):
    """Get the Pushetta notification service."""
    from pushetta import Pushetta, exceptions

    try:
        pushetta = Pushetta(config[CONF_API_KEY])
        pushetta.pushMessage(config[CONF_CHANNEL_NAME],
                             "Home Assistant started")
    except exceptions.TokenValidationError:
        _LOGGER.error("Please check your access token")
        return None
    except exceptions.ChannelNotFoundError:
        _LOGGER.error("Channel '%s' not found", config[CONF_CHANNEL_NAME])
        return None

    return PushettaNotificationService(config[CONF_API_KEY],
                                       config[CONF_CHANNEL_NAME])


# pylint: disable=too-few-public-methods
class PushettaNotificationService(BaseNotificationService):
    """Implement the notification service for Pushetta."""

    def __init__(self, api_key, channel_name):
        """Initialize the service."""
        from pushetta import Pushetta
        self._api_key = api_key
        self._channel_name = channel_name
        self.pushetta = Pushetta(self._api_key)

    def send_message(self, message="", **kwargs):
        """Send a message to a user."""
        title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
        self.pushetta.pushMessage(self._channel_name,
                                  "{} {}".format(title, message))

@@ -546,16 +546,53 @@
 el_name'
+%0ACONF_SEND_TEST_MSG = 'send_test_msg'
 %0A%0APLATFO
@@ -719,16 +719,81 @@
 string,%0A
+    vol.Optional(CONF_SEND_TEST_MSG, default=False): cv.boolean,%0A
 %7D)%0A%0A%0Adef
@@ -869,37 +869,32 @@
 ice.%22%22%22%0A    
-from 
 pushetta
  import Push
@@ -885,124 +885,45 @@
 etta
- import Pushetta, exceptions%0A%0A    try:%0A        pushetta = Pushetta(config%5BCONF_API_KEY%5D)%0A        pushetta.pushMessag
+_service = PushettaNotificationServic
 e(co
@@ -932,28 +932,23 @@
 ig%5BCONF_
-CHANNEL_NAME
+API_KEY
 %5D,%0A     
@@ -975,245 +975,29 @@
     
-%22Home Assistant started%22)%0A    except exceptions.TokenValidationError:%0A        _LOGGER.error(%22Please check your access token%22)%0A        return None%0A    except exceptions.ChannelNotFoundError:%0A        _LOGGER.error(%22Channel '%25s' not found%22,
+                     
  con
@@ -1018,17 +1018,17 @@
 EL_NAME%5D
-)
+,
 %0A       
@@ -1032,147 +1032,145 @@
     
-return None%0A%0A    return PushettaNotificationService(config%5BCONF_API_KEY%5D,%0A                                       config%5BCONF_CHANNEL_NAME%5D)
+                                           config%5BCONF_SEND_TEST_MSG%5D)%0A%0A    if pushetta_service.is_valid:%0A        return pushetta_service
 %0A%0A%0A#
@@ -1373,16 +1373,31 @@
 nel_name
+, send_test_msg
 ):%0A     
@@ -1558,41 +1558,147 @@
 elf.
-pushetta = Pushetta(self._api_key
+is_valid = True%0A        self.pushetta = Pushetta(api_key)%0A%0A        if send_test_msg:%0A            self.send_message(%22Home Assistant started%22
 )%0A%0A 
@@ -1782,24 +1782,64 @@
  a user.%22%22%22%0A
+        from pushetta import exceptions%0A
         titl
@@ -1885,16 +1885,34 @@
 EFAULT)%0A
+%0A        try:%0A    
         
@@ -1991,16 +1991,20 @@
         
+    
 %22%7B%7D %7B%7D%22.
@@ -2027,8 +2027,304 @@
 ssage))%0A
+        except exceptions.TokenValidationError:%0A            _LOGGER.error(%22Please check your access token%22)%0A            self.is_valid = False%0A        except exceptions.ChannelNotFoundError:%0A            _LOGGER.error(%22Channel '%25s' not found%22, self._channel_name)%0A            self.is_valid = False%0A

customize if pushetta should send test message on start up