<commit_before><!-- Copyright (c) 2016 <NAME>, see LICENSE for details.-->
<!-- Begin H command -->
<script type="text/x-red" data-template-name="H command">
    <div class="form-row">
        <label for="node-input-server"><i class="fa fa-server"></i> Hub</label>
        <input type="text" id="node-input-server">
    </div>
    <div class="form-row">
        <label for="node-input-name"><i class="icon-tag"></i> Name</label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>
    <div class="form-row">
        <label for="node-input-activity"><i class="fa fa-television"></i> Activity</label>
        <select id="node-input-activity" style="width: 60%;"></select>
        <a id="node-input-scan" class="editor-button"><i class="fa fa-refresh"></i></a>
    </div>
    <div class="form-row">
        <label for="node-input-command"><i class="fa fa-keyboard-o"></i> Command</label>
        <select id="node-input-command" style="width: 60%;"></select>
        <a id="node-input-commandscan" class="editor-button"><i class="fa fa-refresh"></i></a>
    </div>
    <div class="form-row">
        <label for="node-input-repeat"><i class="fa fa-repeat"></i> Repeat</label>
        <input type="text" id="node-input-repeat">
    </div>
</script>
<script type="text/x-red" data-help-name="H command">
    <p>A node to send a <b>Command</b> to a Harmony Hub through Node-RED.</p>
    <p>
    A Harmony <i class="fa fa-server" /> <b>Hub</b> needs to be selected from the list or created by clicking on the edit button. The Harmony Hub
    <b>IP</b> address can be autodetected by clicking on the search button in the configuration node.
	</p>
	<p>
    An <i class="fa fa-television" /> <b>Activity</b> that is set up on the Harmony Hub needs to be selected. The dropdown loads available activities automatically, 
    if needed the list can be refreshed by clicking on the <i class="fa fa-refresh" /> button next to the dropdown.
    Selecting an activity changes the available commands below, therefore when changing the activity, you'll need to reselect a command below.
	</p>
	<p>
    A <i class="fa fa-keyboard-o"/> <b>Command</b> from the selected <i class="fa fa-television" /> <b>Activity</b> needs to be provided, it's a stanza <i>query</i>. The dropdown loads available commands 
    for the selected activity automatically, if needed the list can be refreshed by clicking on the <i class="fa fa-refresh" /> button next to the dropdown.
	</p>
    <p>
    The <i class="fa fa-repeat" /> <b>Repeat</b> field allows for the command to be repeated. The default is <i>1</i>, meaning the command is send once.
    For example entering <i>10</i> will send the command exactly 10 times. This can be helpful when using commands
    for volume or channels.
    </p>
    <p>
    The command configured in the node will be triggered by any input injected into the node, the output slot will return <i>msg.payload = true</i>
    if the command was sent successfully.
	</p>
</script>

<script type="text/javascript">
    RED.nodes.registerType('H command',{
        category: 'harmony',
        color: '#a6bbcf',
        defaults: {
            name: {value:""},
            server: {type:"harmony-server", required:true},
            activity: {value:""},
            label: {value:""},
            command: {value:"", required:true},
            repeat: {value:"1", validate:function(v) { return v > 0 } }
        },
        inputs:1,
        outputs:1,
        icon: "feed.png",
        label: function() {
            return this.name||"H command";
        },
        oneditprepare: function() {

            var config = RED.nodes.node($('#node-input-server').val())

            loadActivities(this.activity)
            loadCommands(this.activity,this.command)

            $('#node-input-scan').click( function() {
                loadActivities($('#node-input-activity').val())
            })

            $('#node-input-commandscan').click( function() {
                loadCommands($('#node-input-activity').val(),$('#node-input-command').val())
            });

            $('#node-input-activity').on('change', function() {
                loadCommands(this.value,null)
            });

            function loadActivities(selected_act){
                if (config && config.ip) {
                $('#node-input-activity').append("<option value='' selected>Loading activities...</option>")
                $.get('harmony/activities', { ip: config.ip } )
                    .done(function(data) {
                        var acts = JSON.parse(data);
                        $('#node-input-activity').empty()
                        if(!acts || acts.length <= 0) {
                            $('#node-input-activity').append("<option value='' selected>No activities</option>")
                            RED.notify("No activities found.", "error")
                        } else {
                            acts.forEach(function(act){
                                $('#node-input-activity').append('<option value="' + act.id + '">' + act.label + '</option>')
                            })
                            $('#node-input-activity').val(selected_act)                     
                        }
                    }).fail(function(err) {
                        RED.notify(err.responseText, "error")
                    })
                }          
            }

            function loadCommands(act_id,selected_comm){
                if (config && config.ip && act_id) {
                    $('#node-input-command').append("<option value='' selected>Loading commands...</option>")
                    $.get('harmony/commands', { ip: config.ip, activity: act_id } )
                        .done(function(data) {
                            var comms = JSON.parse(data);
                            $('#node-input-command').empty()
                            if(!comms || comms.length <= 0) {
                                $('#node-input-command').append("<option value='' selected>No commands</option>")
                                RED.notify("No commands found.", "error")
                            } else {
                                comms.forEach(function(comm){
                                    comm.function.forEach(function(item){
                                        $('#node-input-command').append('<option value="' + encodeURI(item.action.replace(/\:/g, '::')) + '">' + item.label + '</option>')
                                    })
                                })
                                if( selected_comm != null ){
                                    $('#node-input-command').val(selected_comm)
                                }
                            }
                        }).fail(function(err) {
                            RED.notify(err.responseText, "error");
                        })
                }

            }
        },
        oneditsave: function() {
            this.activity = $('#node-input-activity').val();
            this.label = $('select#node-input-activity option:selected').text();
            this.command = $('#node-input-command').val();
        }
    });
</script>
<!-- End H command -->

<!-- Begin H activity -->
<script type="text/x-red" data-template-name="H activity"><commit_msg>Small adjustments in dorpdown behaviour, disable on load<commit_after><!-- Copyright (c) 2016 <NAME>, see LICENSE for details.-->
<!-- Begin H command -->
<script type="text/x-red" data-template-name="H command">
    <div class="form-row">
        <label for="node-input-server"><i class="fa fa-server"></i> Hub</label>
        <input type="text" id="node-input-server">
    </div>
    <div class="form-row">
        <label for="node-input-name"><i class="icon-tag"></i> Name</label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>
    <div class="form-row">
        <label for="node-input-activity"><i class="fa fa-television"></i> Activity</label>
        <select id="node-input-activity" style="width: 60%;"></select>
        <a id="node-input-scan" class="editor-button"><i class="fa fa-refresh"></i></a>
    </div>
    <div class="form-row">
        <label for="node-input-command"><i class="fa fa-keyboard-o"></i> Command</label>
        <select id="node-input-command" style="width: 60%;"></select>
        <a id="node-input-commandscan" class="editor-button"><i class="fa fa-refresh"></i></a>
    </div>
    <div class="form-row">
        <label for="node-input-repeat"><i class="fa fa-repeat"></i> Repeat</label>
        <input type="text" id="node-input-repeat">
    </div>
</script>
<script type="text/x-red" data-help-name="H command">
    <p>A node to send a <b>Command</b> to a Harmony Hub through Node-RED.</p>
    <p>
    A Harmony <i class="fa fa-server" /> <b>Hub</b> needs to be selected from the list or created by clicking on the edit button. The Harmony Hub
    <b>IP</b> address can be autodetected by clicking on the search button in the configuration node.
	</p>
	<p>
    An <i class="fa fa-television" /> <b>Activity</b> that is set up on the Harmony Hub needs to be selected. The dropdown loads available activities automatically, 
    if needed the list can be refreshed by clicking on the <i class="fa fa-refresh" /> button next to the dropdown.
    Selecting an activity changes the available commands below, therefore when changing the activity, you'll need to reselect a command below.
	</p>
	<p>
    A <i class="fa fa-keyboard-o"/> <b>Command</b> from the selected <i class="fa fa-television" /> <b>Activity</b> needs to be provided, it's a stanza <i>query</i>. The dropdown loads available commands 
    for the selected activity automatically, if needed the list can be refreshed by clicking on the <i class="fa fa-refresh" /> button next to the dropdown.
	</p>
    <p>
    The <i class="fa fa-repeat" /> <b>Repeat</b> field allows for the command to be repeated. The default is <i>1</i>, meaning the command is send once.
    For example entering <i>10</i> will send the command exactly 10 times. This can be helpful when using commands
    for volume or channels.
    </p>
    <p>
    The command configured in the node will be triggered by any input injected into the node, the output slot will return <i>msg.payload = true</i>
    if the command was sent successfully.
	</p>
</script>

<script type="text/javascript">
    RED.nodes.registerType('H command',{
        category: 'harmony',
        color: '#a6bbcf',
        defaults: {
            name: {value:""},
            server: {type:"harmony-server", required:true},
            activity: {value:""},
            label: {value:""},
            command: {value:""},
            repeat: {value:"1", validate:function(v) { return v > 0 } }
        },
        inputs:1,
        outputs:1,
        icon: "feed.png",
        label: function() {
            return this.name||"H command";
        },
        oneditprepare: function() {

            var config = RED.nodes.node($('#node-input-server').val())

            loadActivities(this.activity)
            loadCommands(this.activity,this.command)

            $('#node-input-scan').click( function() {
                loadActivities($('#node-input-activity').val())
            })

            $('#node-input-commandscan').click( function() {
                loadCommands($('#node-input-activity').val(),$('#node-input-command').val())
            });

            $('#node-input-activity').on('change', function() {
                loadCommands(this.value,null)
            });

            function loadActivities(selected_act){
                if (config && config.ip) {
                $('#node-input-activity').attr("disabled", "disabled")
                $('#node-input-activity').append("<option value='' selected>Loading activities...</option>")
                $.get('harmony/activities', { ip: config.ip } )
                    .done(function(data) {
                        var acts = JSON.parse(data);
                        $('#node-input-activity').empty()
                        if(!acts || acts.length <= 0) {
                            $('#node-input-activity').append("<option value='' selected>No activities</option>")
                            RED.notify("No activities found.", "error")
                        } else {
                            acts.forEach(function(act){
                                $('#node-input-activity').append('<option value="' + act.id + '">' + act.label + '</option>')
                            })
                            $('#node-input-activity').val(selected_act)
                            $('#node-input-activity').removeAttr("disabled");                
                        }
                    }).fail(function(err) {
                        RED.notify(err.responseText, "error")
                    })
                }          
            }

            function loadCommands(act_id,selected_comm){
                if (config && config.ip && act_id) {
                    $('#node-input-command').attr("disabled", "disabled")
                    $('#node-input-command').append("<option value='' selected>Loading commands...</option>")
                    $.get('harmony/commands', { ip: config.ip, activity: act_id } )
                        .done(function(data) {
                            var comms = JSON.parse(data);
                            $('#node-input-command').empty()
                            if(!comms || comms.length <= 0) {
                                $('#node-input-command').append("<option value='' selected>No commands</option>")
                                RED.notify("No commands found.", "error")
                            } else {
                                comms.forEach(function(comm){
                                    comm.function.forEach(function(item){
                                        $('#node-input-command').append('<option value="' + encodeURI(item.action.replace(/\:/g, '::')) + '">' + item.label + '</option>')
                                    })
                                })
                                if( selected_comm != null ){
                                    $('#node-input-command').val(selected_comm)
                                }
                                $('#node-input-command').removeAttr("disabled");  
                            }
                        }).fail(function(err) {
                            RED.notify(err.responseText, "error");
                        })
                }

            }
        },
        oneditsave: function() {
            this.activity = $('#node-input-activity').val();
            this.label = $('select#node-input-activity option:selected').text();
            this.command = $('#node-input-command').val();
        }
    });
</script>
<!-- End H command -->

<!-- Begin H activity -->
<script type="text/x-red" data-template-name="H activity">
{'fraction_non_alphanumeric': 0.15757858906760996, 'fraction_numerical': 0.002669692317960355, 'mean_word_length': 1.794479671764267, 'pattern_counts': {'":': 0, '<': 227, '<?xml version=': 0, '>': 225, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2444266', 'n_tokens_mistral': 4049, 'n_tokens_neox': 3926, 'n_words': 995}