
function update_devices(data){

    $.each(data, function(key,status){

        // Authorized Instrument at LBT
        $('[data-status="'+key+'"]').text(status.value)

        /// In limit
        var in_limit = $('var[data-'+key+'-in_limit]')
        var named = $('var[data-'+key+'-named]')

        $.each(status, function(k,v){
            var elem = $('var[data-'+key+'-'+k+']');
            elem.text(v)

            if (status.is_moving) {
                elem.addClass("text-warning")
                named.text("moving...")
            } else {
                elem.removeClass("text-warning")
            }
            elem.data(key+'-'+k, v)

            if (status.encoder == 0) {
                elem.addClass("text-success")
            } else {
                elem.removeClass("text-success")
            }

        });

        /// In limit
        if (status.in_limit) {
            in_limit.addClass("text-danger")
            named.addClass("text-danger")
            named.text("in limit!")
        } else {
            in_limit.removeClass("text-danger")
            named.removeClass("text-danger")
        }

        /// Named position
        if (status.named == "not defined") {
            if (status.encoder == 0) {
                named.addClass("text-success")
                named.text("in home!")
            } else {
                named.addClass("text-warning")
            }
        } else {
            named.removeClass("text-success")
            named.removeClass("text-warning")
        }

    });

}
