'Send a message to a specified target.
If no target specified, a \'normal\' push will be sent to all devices
linked to the Pushbullet account.
Email is special, these are assumed to always exist. We use a special
call which doesn\'t require a push object.'

def send_message(self, message=None, **kwargs):

    targets = kwargs.get(ATTR_TARGET)
    title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
    data = kwargs.get(ATTR_DATA)
    url = None
    filepath = None
    if data:
        url = data.get(ATTR_URL, None)
        filepath = data.get(ATTR_FILE, None)
    refreshed = False
    if (not targets):
        if url:
            self.pushbullet.push_link(title, url, body=message)
        if self.hass.config.is_allowed_path(filepath):
            with open(filepath, 'rb') as fileh:
                filedata = self.pushbullet.upload_file(fileh, filepath)
                self.pushbullet.push_file(title=title, body=message, **filedata)
        else:
            self.pushbullet.push_note(title, message)
        _LOGGER.info('Sent    notification    to    self')
        return
    for target in targets:
        try:
            (ttype, tname) = target.split('/', 1)
        except ValueError:
            _LOGGER.error('Invalid    target    syntax:    %s', target)
            continue
        if (ttype == 'email'):
            if url:
                self.pushbullet.push_link(title, url, body=message, email=tname)
            if self.hass.config.is_allowed_path(filepath):
                with open(filepath, 'rb') as fileh:
                    filedata = self.pushbullet.upload_file(fileh, filepath)
                    self.pushbullet.push_file(title=title, body=message, **filedata)
            else:
                self.pushbullet.push_note(title, message, email=tname)
            _LOGGER.info('Sent    notification    to    email    %s', tname)
            continue
        if (ttype not in self.pbtargets):
            _LOGGER.error('Invalid    target    syntax:    %s', target)
            continue
        tname = tname.lower()
        if ((tname not in self.pbtargets[ttype]) and (not refreshed)):
            self.refresh()
            refreshed = True
        try:
            if url:
                self.pbtargets[ttype][tname].push_link(title, url, body=message)
            else:
                self.pbtargets[ttype][tname].push_note(title, message)
            _LOGGER.info('Sent    notification    to    %s/%s', ttype, tname)
        except KeyError:
            _LOGGER.error('No    such    target:    %s/%s', ttype, tname)
            continue
        except self.pushbullet.errors.PushError:
            _LOGGER.error('Notify    failed    to:    %s/%s', ttype, tname)
            continue
