<commit_before>function ha_status(stream, dash, widgets)
{

    var webSocket = new ReconnectingWebSocket(stream);
            
    webSocket.onopen = function (event) 
    {
        webSocket.send(dash);
    };

    webSocket.onmessage = function (event) 
    {
        Object.keys(widgets).forEach(function (key)
        {
            if ("on_ha_data" in widgets[key])
            {
                widgets[key].on_ha_data(JSON.parse(event.data));
            }
        })
    };
    webSocket.onclose = function (event)
    {
        //window.alert("Server closed connection")
       // window.location.reload(false); 
    };

    webSocket.onerror = function (event)
    {
        //window.alert("Error occured")
        //window.location.reload(true);         
    }
}

var inheritsFrom = function (child, parent) {
    child.prototype = Object.create(parent.prototype);
};

var WidgetBase = function(widget_id, url, skin, parameters, monitored_entities, callbacks)
{
    child = this;
    child.url = url;
    
    // Function definitions
    
    this.set_field = function(self, field, value)
    {
        self.ViewModel[field](value)
    };
    
    this.format_number = function(self, value)
    {
        if ("precision" in self.parameters)
        {
            var precision = self.parameters.precision
        }
        else
        {
            var precision = 0
        }
        value = parseFloat(value);
        value = value.toFixed(precision);

        if ("shorten" in self.parameters && self.parameters.shorten == 1)
        {
            if (value >= 1E9)
            {
                value = (value / 1E9).toFixed(1) + "B"
            }
            else if (value >= 1E6)
            {
                value = (value / 1E6).toFixed(1) + "M"
            }
            else if (value >= 1E3)
            {
                value = (value / 1E3).toFixed(1) + "K"
            }
        }
        if ("use_comma" in self.parameters && self.parameters.use_comma == 1)
        {
            value = value.toString().replace(".", ",")
        }
        return value
    };

    
    this.map_state = function(self, value)
    {
        if ("state_map" in self.parameters)
        {
            if (value in self.parameters.state_map)
            {
                state = self.parameters.state_map[value]
            }
            else
            {
                state = value
            }
        }
        else
        {
            state = value
        }
        return (state)
    };
    
    this.set_icon = function(self, field, value)
    {
        self.ViewModel[field](value.split("-")[0] + ' ' + value)
    };
    
    this.get_state = function(child, base_url, entity)
    {
        state_url = base_url + "/state/" + entity.entity;
        $.ajax
        ({
            url: state_url, 
            type: 'GET',
            success: function(data)
                    {
                        if (data.state == null)
                        {
                            if ("title" in child.ViewModel)
                            {
                                child.ViewModel.title("entity not found: " + entity.entity);
                                new_state = null
                            }
                            else
                            {
                                console.log("Entity not found: " + entity.entity)
                            }
                        }
                        else
                        {
                            new_state = data.state;
                            if ("use_hass_icon" in child.parameters &&
                                parameters.use_hass_icon == 1 &&
                                "icon" in new_state.attributes)
                            {
                                icon = new_state.attributes.icon.replace(":", "-")
                                child.icons.icon_on = icon
                                child.icons.icon_off = icon
                            }
                            if ("title_is_friendly_name" in child.parameters 
                            && child.parameters.title_is_friendly_name == 1
                            && "friendly_name" in new_state.attributes)
                            {
                                child.ViewModel.title(new_state.attributes.friendly_name)
                            }
                            if (typeof child.entity_state === 'undefined')
                            {
                                child.entity_state = {}
                            }
                            child.entity_state[entity.entity] = new_state;
                            entity.initial(child, new_state)
                        }
                    },
            error: function(data)
                    {
                        alert("Error getting state, check Java Console for details")
                    }
                  
        });
    };
   
    this.on_ha_data = function(data)
    {
        entity = data.data.entity_id;
        elen = monitored_entities.length;<commit_msg>Fix device tracker & use_hass_icon<commit_after>function ha_status(stream, dash, widgets)
{

    var webSocket = new ReconnectingWebSocket(stream);
            
    webSocket.onopen = function (event) 
    {
        webSocket.send(dash);
    };

    webSocket.onmessage = function (event) 
    {
        Object.keys(widgets).forEach(function (key)
        {
            if ("on_ha_data" in widgets[key])
            {
                widgets[key].on_ha_data(JSON.parse(event.data));
            }
        })
    };
    webSocket.onclose = function (event)
    {
        //window.alert("Server closed connection")
       // window.location.reload(false); 
    };

    webSocket.onerror = function (event)
    {
        //window.alert("Error occured")
        //window.location.reload(true);         
    }
}

var inheritsFrom = function (child, parent) {
    child.prototype = Object.create(parent.prototype);
};

var WidgetBase = function(widget_id, url, skin, parameters, monitored_entities, callbacks)
{
    child = this;
    child.url = url;
    
    // Function definitions
    
    this.set_field = function(self, field, value)
    {
        self.ViewModel[field](value)
    };
    
    this.format_number = function(self, value)
    {
        if ("precision" in self.parameters)
        {
            var precision = self.parameters.precision
        }
        else
        {
            var precision = 0
        }
        value = parseFloat(value);
        value = value.toFixed(precision);

        if ("shorten" in self.parameters && self.parameters.shorten == 1)
        {
            if (value >= 1E9)
            {
                value = (value / 1E9).toFixed(1) + "B"
            }
            else if (value >= 1E6)
            {
                value = (value / 1E6).toFixed(1) + "M"
            }
            else if (value >= 1E3)
            {
                value = (value / 1E3).toFixed(1) + "K"
            }
        }
        if ("use_comma" in self.parameters && self.parameters.use_comma == 1)
        {
            value = value.toString().replace(".", ",")
        }
        return value
    };

    
    this.map_state = function(self, value)
    {
        if ("state_map" in self.parameters)
        {
            if (value in self.parameters.state_map)
            {
                state = self.parameters.state_map[value]
            }
            else
            {
                state = value
            }
        }
        else
        {
            state = value
        }
        return (state)
    };
    
    this.set_icon = function(self, field, value)
    {
        self.ViewModel[field](value.split("-")[0] + ' ' + value)
    };
    
    this.get_state = function(child, base_url, entity)
    {
        state_url = base_url + "/state/" + entity.entity;
        $.ajax
        ({
            url: state_url, 
            type: 'GET',
            success: function(data)
                    {
                        if (data.state == null)
                        {
                            if ("title" in child.ViewModel)
                            {
                                child.ViewModel.title("entity not found: " + entity.entity);
                                new_state = null
                            }
                            else
                            {
                                console.log("Entity not found: " + entity.entity)
                            }
                        }
                        else
                        {
                            new_state = data.state;
                            console.log(entity.entity)
                            console.log(new_state.attributes)
                            if ("use_hass_icon" in child.parameters &&
                                parameters.use_hass_icon == 1 &&
                                "icon" in new_state.attributes && new_state.attributes.icon != "False")
                            {
                                icon = new_state.attributes.icon.replace(":", "-")
                                child.icons.icon_on = icon
                                child.icons.icon_off = icon
                            }
                            if ("title_is_friendly_name" in child.parameters 
                            && child.parameters.title_is_friendly_name == 1
                            && "friendly_name" in new_state.attributes)
                            {
                                child.ViewModel.title(new_state.attributes.friendly_name)
                            }
                            if (typeof child.entity_state === 'undefined')
                            {
                                child.entity_state = {}
                            }
                            child.entity_state[entity.entity] = new_state;
                            entity.initial(child, new_state)
                        }
                    },
            error: function(data)
                    {
                        alert("Error getting state, check Java Console for details")
                    }
                  
        });
    };
   
    this.on_ha_data = function(data)
    {
        entity = data.data.entity_id;
        elen = monitored_entities.length;
{'fraction_non_alphanumeric': 0.09892120978616836, 'fraction_numerical': 0.004045463301868619, 'mean_word_length': 1.0165080598174403, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2125724', 'n_tokens_mistral': 2706, 'n_tokens_neox': 2585, 'n_words': 468}