Home Assistant Unofficial Reference 2024.12.1
helpers.py
Go to the documentation of this file.
1 """Helper functions for Philips Hue v2."""
2 
3 from __future__ import annotations
4 
5 
6 def normalize_hue_brightness(brightness: float | None) -> float | None:
7  """Return calculated brightness values."""
8  if brightness is not None:
9  # Hue uses a range of [0, 100] to control brightness.
10  brightness = float((brightness / 255) * 100)
11 
12  return brightness
13 
14 
15 def normalize_hue_transition(transition: float | None) -> float | None:
16  """Return rounded transition values."""
17  if transition is not None:
18  # hue transition duration is in milliseconds and round them to 100ms
19  transition = int(round(transition, 1) * 1000)
20 
21  return transition
22 
23 
24 def normalize_hue_colortemp(colortemp: int | None) -> int | None:
25  """Return color temperature within Hue's ranges."""
26  if colortemp is not None:
27  # Hue only accepts a range between 153..500
28  colortemp = min(colortemp, 500)
29  colortemp = max(colortemp, 153)
30  return colortemp
float|None normalize_hue_brightness(float|None brightness)
Definition: helpers.py:6
float|None normalize_hue_transition(float|None transition)
Definition: helpers.py:15
int|None normalize_hue_colortemp(int|None colortemp)
Definition: helpers.py:24