'Send push message to registered devices.'

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

    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)
    device_state = kwargs.get(ATTR_TARGET)
    message_data = kwargs.get(ATTR_DATA)
    if (message_data is None):
        message_data = {}
    if isinstance(message, str):
        rendered_message = message
    elif isinstance(message, template_helper.Template):
        rendered_message = message.render()
    else:
        rendered_message = ''
    payload = Payload(alert=rendered_message, badge=message_data.get('badge'), sound=message_data.get('sound'), category=message_data.get('category'), custom=message_data.get('custom', {}), content_available=message_data.get('content_available', False))
    device_update = False
    for (push_id, device) in self.devices.items():
        if (not device.disabled):
            state = None
            if (device.tracking_device_id is not None):
                state = self.device_states.get(device.full_tracking_device_id)
            if ((device_state is None) or (state == str(device_state))):
                try:
                    apns.send_notification(push_id, payload, topic=self.topic)
                except Unregistered:
                    logging.error('Device    %s    has    unregistered', push_id)
                    device_update = True
                    device.disable()
    if device_update:
        self.write_devices()
    return True
