Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions custom_components/animated_scenes/animations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from collections.abc import Callable
import colorsys
import logging
import math
from random import choices, randrange, sample, uniform
from typing import Any

Expand Down Expand Up @@ -525,8 +526,16 @@ def get_static_or_random(self, value: int | list, step: int = 1) -> float:
"""
if isinstance(value, list):
if isinstance(value[0], float) or isinstance(value[1], float):
return round(uniform(value[0], value[1]), 1)
return randrange(value[0], value[1], step)
# Use math.nextafter to nudge the upper bound slightly upward so
# that after rounding the result can inclusively reach the
# configured upper value. This makes the behavior effectively
# inclusive for the rounded one-decimal result.
upper = math.nextafter(value[1], math.inf)
return round(uniform(value[0], upper), 1)
# randrange's stop is exclusive. Add `step` to the stop value so
# the configured upper bound can be selected when it aligns with
# the step. This makes the integer range behave inclusively.
return randrange(value[0], value[1] + step, step)
return value

def pick_color(self) -> dict[str, Any]:
Expand Down
Loading