widget_homematic.js wird nicht angenommen

Begonnen von Rompe, 28 Juli 2017, 22:59:42

Vorheriges Thema - Nächstes Thema

Rompe

Huhu Leute.

Habe bei dem Widget noch das Problem, dass beim Klicken auf + oder - die Werte Step für Step übertragen werden und nicht, wie es mit der .js eigentlich sein soll, mit Verzögerung.


Eingebunden ist es folgendermaßen:

visu.js

var scriptFolder = (function() {
var result = document.currentScript.getAttribute("src", 2);
  return result.substring(0, result.lastIndexOf("/") +1);
}());

function include(script) {
  script = scriptFolder + script;
  $.ajax({
    url: script,
    dataType: "script",
    async: false,
    error: function () {
      alert("Could not load '" + script + "'");
    }
  });
}

-----------------------------------------------------------------------------
W I D G E T S
-----------------------------------------------------------------------------
include("widget_homematic.js");


widget_homematic.js

// this function sets the value to the web instantly and starts a timer to send the value delayed to the server
function deviceHmTc_setDelayed(uid, item, val) {
    widget.update(item, val);
   
    obj = $('#' + uid);
   
    // check if there is still a timer
    if (obj.prop("setDelayTimer") != undefined ){
        clearTimeout(obj.prop("setDelayTimer"));
        obj.removeProp("setDelayTimer");
    }
   
    // set timer to send the value delayed
    obj.prop("setDelayTimer", setTimeout(function(){
                                           io.write(item, val);
                                           $('#' + uid).removeProp("setDelayTimer");
                                         }, 3000));
                                         
}

$(document).delegate('div[data-widget="device.hmtc"] > div > a[data-icon="minus"]', {
    'click': function (event, response) {
        var uid = $(this).parent().parent().attr('id');
        var step = $('#' + uid).attr('data-step');
        var item = $('#' + uid + 'set').attr('data-item');

        var temp = (Math.round((widget.get(item) - step) * 10) / 10).toFixed(1);
        temp = Math.max($('#' + uid).attr('min_temp'), temp);
        deviceHmTc_setDelayed(uid, item, temp);
    }
});

$(document).delegate('div[data-widget="device.hmtc"] > div > a[data-icon="plus"]', {
    'click': function (event, response) {
        var uid = $(this).parent().parent().attr('id');
        var step = $('#' + uid).attr('data-step');
        var item = $('#' + uid + 'set').attr('data-item');

        var temp = (Math.round((widget.get(item) * 1 + step * 1) * 10) / 10).toFixed(1);
        temp = Math.min($('#' + uid).attr('max_temp'), temp);
        deviceHmTc_setDelayed(uid, item, temp);
    }
});


widget_homematic.html Ausschnitt

{% macro hmtc(id, txt, gad_actual, gad_set, gad_controlmode, gad_daytemp, gad_nighttemp, gad_window, gad_battery, gad_state, gad_txt, step, gad_valve, gad_humidity) %}
{% import "basic.html" as basic %}
{% import "icon.html" as icon %}
<div id="{{ uid(page, id) }}" data-widget="device.rtr" data-step="{{ step|default(0.5) }}"
class="rtr">
<div class="actual">
<div class="temp">
{{ basic.symbol(id~'windowopen', gad_window, '', icon1~'fts_window_2w_open.png','open') }}
{{ basic.symbol(id~'windowclose', gad_window, '', icon0~'fts_window_2w.png','closed') }}
&nbsp;{{ basic.float(id~'actual', gad_actual, '°' ) }}
{{ icon.battery(id~'battery', '', gad_battery, '2.2', '3') }}
</div>

{% if gad_humidity %}<div style="font-size:0.8em">Luftfeuchte:&nbsp;{{ basic.value(id~'humidity', gad_humidity) }}%</div>{% endif %}
{% if gad_valve %}<div style="font-size:0.8em">Ventil:&nbsp;{{ basic.value(id~'valve', gad_valve) }}%</div>{% endif %}

<div class="text">
{{ txt }} {{ basic.value(id~'controlmode', gad_controlmode) }} {% if gad_txt %} {{ basic.value(id~'txt', gad_txt) }} {% endif %}
</div>
</div>

{% if gad_set %}
<div class="set">
<a data-role="button" data-icon="minus" data-inline="true" data-iconpos="notext" class="ui-mini"></a>
<div class="temp">{{ basic.float(id~'set', gad_set, '°' ) }}</div>
<a data-role="button" data-icon="plus" data-inline="true" data-iconpos="notext" class="ui-mini"></a>
</div>
{% endif %}

<div class="control" style="width: 250px;">
<table align="center" cellpadding="0">
<tr>
<td>{{ basic.switch(id~'manauto', gad_controlmode, icon1~'sani_heating_automatic.png', icon0~'sani_heating_manual.png', 'auto', 'manual') }}</td>
<td>{{ basic.switch(id~'boost', gad_controlmode, icon1~'sani_heating_boost.png', icon0~'sani_heating_boost.png', 'boost', 'auto') }}</td>
<td>{{ basic.switch(id~'night', gad_set, icon1~'scene_night.png', icon0~'scene_night.png', '17', '21') }}</td>
<td>{{ basic.switch(id~'day', gad_set, icon1~'scene_day.png', icon0~'scene_day.png', '21', '17') }}</td>
{% if gad_state %}<td>{{ basic.switch(id~'state', gad_state, icon1~'sani_heating.png', icon0~'sani_heating.png') }}</td>{% endif %}
</tr>
</table>
</div>
</div>
{% endmacro %}


Alle Dateien liegen unter /pages/MeineWohnung/


Habe auch schon ein anderes Script versucht, in welcher die Widgets unter /pages/MeineWohnung/widgets/ abgelegt werden, leider auch erfolglos. Dateirechte habe ich den Dateien auch schon temporär 777 verpasst, alles leider ohne Erfolg.

Was übersehe ich? Kann mir jemand bitte auf die Sprünge helfen?


MfG,
Tobi

Volker

Hallo Tobi,

hast du dein Problem gelöst? Ich stehe hier vor dem gleichen Verhalten. Konnte es insoweit eingrenzen, das ich herausgefunden habe das die events nicht den Buttons zugeordnet werden, aber ich habe keine Ahnung warum.
MfG

Volker

RasPi als FHEM-Plattform, BananaPi, HMLan, HM-LC_Bl1PBU-FM, HM-LC-SW4-DR, HM-LC-SW4-PCB, HM-TC-IT-WM-W-EU, HM-CC-RT-DN

Florie

Dann zeig mal die Definiton von Deinem Gerät im der HTML des entsprechenden Raumes ...