Astrisk getting the BLF lighs to show Orange when hint is unavailable

As I could not find this anywhere on the internet and lot of other asking over the years in forums
I thought i would post this for others

Getting the BLF lights to go Orange when a hint is in the unavailable state on a cisco spa5xx phone

when a subscription for a hint is made and that hint is unavailable
this will respond with "480 Temporarily Unavailable"
and not subscribe to the the hint & making the subscription fail & changing the led to orange
as this relies on a subscription request
we need to make sure the phone is making these requests on a reasonable interval
we change "maxexpiry" to say 120
this means we should see a result in under 2 mins of a unavailable hint
or in case of a phone up to 4 mins for both the state to change & the next hint subscriptions to be retried
you want to change "minexpiry" if you have a lot of hints also as each failed subscription gets retried by this time

this is no way as responsive as normal hints responses give you extra notification
that I at lest I expected as normal behavior from the phone system

this was using asterisk-16.13.0

sip.conf
maxexpiry=120 ;Registration Maximum Expiry
minexpiry=60 ;Registration Default Expiry

channels\chan_sip.c

was

			if (data.state < 0) {
				ao2_cleanup(device_state_info);
				if (p->expiry > 0) {
					ast_log(LOG_NOTICE, "Got SUBSCRIBE for extension %s@%s from %s, but there is no hint for that extension.\n", p->exten, p->context, ast_sockaddr_stringify(&p->sa));
				}
				transmit_response(p, "404 Not found", req);
				pvt_set_needdestroy(p, "no extension for SUBSCRIBE");
				if (authpeer) {
					sip_unref_peer(authpeer, "sip_unref_peer, from handle_request_subscribe (authpeer 6)");
				}
				return 0;
			}
			if (allow_notify_user_presence(p)) {
				data.presence_state = ast_hint_presence_state(NULL, p->context, p->exten, &subtype, &message);
				data.presence_subtype = subtype;
				data.presence_message = message;
			}
			ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
			transmit_response(p, "200 OK", req);

change to

if (data.state < 0) {
				ao2_cleanup(device_state_info);
				if (p->expiry > 0) {
					ast_log(LOG_NOTICE, "Got SUBSCRIBE for extension %s@%s from %s, but there is no hint for that extension.\n", p->exten, p->context, ast_sockaddr_stringify(&p->sa));
				}
				transmit_response(p, "404 Not found", req);
				pvt_set_needdestroy(p, "no extension for SUBSCRIBE");
				if (authpeer) {
					sip_unref_peer(authpeer, "sip_unref_peer, from handle_request_subscribe (authpeer 6)");
				}
			
			return 0;
			}
			if (data.state == AST_EXTENSION_UNAVAILABLE) {
				ao2_cleanup(device_state_info);
				transmit_response(p, "480 Temporarily Unavailable", req);
				pvt_set_needdestroy(p, "no extension for SUBSCRIBE");
				return 0;
			}
			if (allow_notify_user_presence(p)) {
				data.presence_state = ast_hint_presence_state(NULL, p->context, p->exten, &subtype, &message);
				data.presence_subtype = subtype;
				data.presence_message = message;
			}
			ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
			transmit_response(p, "200 OK", req);