fhem-tablet-ui icon indicating copy to clipboard operation
fhem-tablet-ui copied to clipboard

Device names with numbers only

Open DeltaCore opened this issue 8 years ago • 1 comments

I had the problem that when i wanted to use a switch with a device which name consists of only numbers, the current state of the button was not displayed correctly after reloading the page.

My steps to get this bug. I pushed the button: button turns orange, fhem set's device reading onoff to on. The i reload the page and the button was gray again.

The switch widget i used.

<div 
  data-type="switch" 
  data-device="631343"
  data-set="onoff" 
  data-get="onoff" 
  class="bigger"
>

And the FHEM device definition:

github-issue

I found a simple fix:

In js/fhem-tablet-ui.js Change the lines1418 and 1819 from

$.fn.getReading = function (key, idx) {
    var devname = $(this).data('device'),
        paraname = $(this).data(key);

Javascript parses it directly to an integer and to call the length option on that does not work really well :').

So i made this change to it:

$.fn.getReading = function (key, idx) {
var devname = $(this).data('device').toString(),
        paraname = $(this).data(key).toString();

I am using the latest tablet-ui. Installed today via the 2 commands on the wiki page.

Hopes this helps.

Best Regards Marcel

DeltaCore avatar Dec 02 '16 22:12 DeltaCore

Upadate!

Found a second occurrence where numberonly devices cause problems:

$.fn.filterDeviceReading = function (key, device, param) {
    return this.filter(function () {
        var elem = $(this);
        var value = elem.data(key);
        return (value === param && elem.data('device') === device) ||
            (value === device + ':' + param) ||
            ($.inArray(param, value) > -1 && elem.data('device') === device) ||
            ($.inArray(device + ':' + param, value) > -1);
    });
};

Again - .toString to the rescure!

$.fn.filterDeviceReading = function (key, device, param) {
    return this.filter(function () {
        device = device.toString(); // Maybe not needed
        key = key.toString(); // Maybe not needed
        param = param.toString(); // Maybe not needed
        var elem = $(this);
        var value = elem.data(key);
        if(value != undefined){ // Maybe not needed
            value = value.toString();
        }
        return (value === param && elem.data('device').toString() === device) || // NEEDED (the .toString())
            (value === device + ':' + param) ||
            ($.inArray(param, value) > -1 && elem.data('device').toString() === device) || // NEEDED (the .toString())
            ($.inArray(device + ':' + param, value) > -1);
    });
};

The setup was basically the same, but this time a dimmer widget:

<div data-type="dimmer" data-device="196721"
      data-get="state"
      data-get-on="on" data-get-off="off"
      data-set="state"
      data-set-on="on" data-set-off="off"
      data-dim="value"></div>

Would be nice if you could try that for yourself.

Best Regards Marcel

DeltaCore avatar Dec 07 '16 20:12 DeltaCore