Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device names with numbers only #176

Open
DeltaCore opened this issue Dec 2, 2016 · 1 comment
Open

Device names with numbers only #176

DeltaCore opened this issue Dec 2, 2016 · 1 comment
Labels

Comments

@DeltaCore
Copy link

DeltaCore commented Dec 2, 2016

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
Copy link
Author

DeltaCore commented Dec 7, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants