Clooos / Bubble-Card

Bubble Card is a minimalist card collection for Home Assistant with a nice pop-up touch.
MIT License
1.62k stars 46 forks source link

Divide by zero in Slider sometimes produces NaN for brightness/volume #350

Closed MrEbbinghaus closed 2 months ago

MrEbbinghaus commented 7 months ago

Describe the bug When sliding the slide you sometimes get an error: Failed to call service light/turn_on. Expected int for dictionary value @ data['brightness']

To Reproduce Steps to reproduce the behavior:

  1. Create a button for a light with type slider.
  2. Slide the slider a couple of times.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots

image

Desktop:

Additional context I've checked the debugger and it seems like it is caused by a divide by zero in updateRange.

function updateRange(x) {
    const rect = rangeSlider.getBoundingClientRect();
    const position = Math.min(Math.max(x - rect.left, 0), rect.width);
    const percentage = position / rect.width;
    if (entityId.startsWith("light.")) {
        brightness = Math.round(percentage * 255);
    } else if (entityId.startsWith("media_player.")) {
        volume = percentage;
    }

    rangeFill.style.transition = 'none';
    rangeFill.style.transform = `translateX(${percentage * 100}%)`;
}

https://github.com/Clooos/Bubble-Card/blob/main/src/cards/button.ts#L250

image

I don't know why sometimes the rangeSlider is 0 in every dimension.

Clooos commented 4 months ago

This issue should be finally fixed in the v2 beta!

Here is the link to the full changelog: https://github.com/Clooos/Bubble-Card/releases/tag/v2.0.0-beta.1