Color Handlers↲
The pyvesync.utils.colors module provides classes and functions for handling color conversions and representations. It includes the Color class, which serves as a base for color manipulation, and the HSV and RGB classes for specific color models. The RGBNightlightColor class provides the color helpers used by humidifiers with an RGB nightlight. The module is designed for internal use within the library and is not intended for public use.
Color class↲
This is the primary class that holds the color data and provides methods for conversion between different color models (RGB, HSV). It also includes methods for validating color values and generating color strings in various formats.
pyvesync.utils.colors.Color
dataclass
↲
Dataclass for color values.
This class should be instantiated through the from_rgb or from_hsv
classmethods. It will return a Color object with the appropriate color
values in RGB and HSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color_object
|
HSV | RGB
|
Named tuple with color values. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
hsv |
namedtuple
|
hue (0-360), saturation (0-100), value (0-100)
see |
rgb |
namedtuple
|
red (0-255), green (0-255), blue (0-255)
see |
Source code in src/pyvesync/utils/colors.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
__repr__ ↲
as_dict ↲
Return color values as dict.
Source code in src/pyvesync/utils/colors.py
from_hsv
classmethod
↲
from_hsv(
hue: float | None,
saturation: float | None,
value: float | None,
) -> Color | None
Create Color instance from HSV values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hue
|
float
|
The hue component of the color, in the range [0, 360). |
required |
saturation
|
float
|
The saturation component of the color, typically in the range [0, 1]. |
required |
value
|
float
|
The value (brightness) component of the color, typically in the range [0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
Color | None
|
Color | None: A Color object with the appropriate color values in RGB and HSV, or None if the input values are invalid. |
Source code in src/pyvesync/utils/colors.py
from_rgb
classmethod
↲
from_rgb(
red: float | None,
green: float | None,
blue: float | None,
) -> Color | None
Create Color instance from RGB values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
red
|
NUMERIC_STRICT
|
The red component of the color, typically in the range [0, 255]. |
required |
green
|
NUMERIC_STRICT
|
The green component of the color, typically in the range [0, 255]. |
required |
blue
|
NUMERIC_STRICT
|
The blue component of the color, typically in the range [0, 255]. |
required |
Returns:
| Type | Description |
|---|---|
Color | None
|
Color | None: A Color object with the appropriate color values in RGB and HSV, or None if the input values are invalid. |
Source code in src/pyvesync/utils/colors.py
hsv_to_rgb
staticmethod
↲
hsv_to_rgb(
hue: float, saturation: float, value: float
) -> RGB
Convert HSV to RGB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hue
|
float
|
The hue component of the color, in the range [0, 360). |
required |
saturation
|
float
|
The saturation component of the color, in the range [0, 1]. |
required |
value
|
float
|
The value (brightness) component of the color, in the range [0, 1]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
RGB |
RGB
|
An RGB dataclass with red, green, and blue components. |
Source code in src/pyvesync/utils/colors.py
rgb_to_hsv
staticmethod
↲
rgb_to_hsv(red: float, green: float, blue: float) -> HSV
Convert RGB to HSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
red
|
float
|
The red component of the color, in the range [0, 255]. |
required |
green
|
float
|
The green component of the color, in the range [0, 255]. |
required |
blue
|
float
|
The blue component of the color, in the range [0, 255]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
HSV |
HSV
|
An HSV dataclass with hue, saturation, and value components. |
Source code in src/pyvesync/utils/colors.py
pyvesync.utils.colors.HSV
dataclass
↲
HSV color space dataclass, for internal use in utils.colors.Color dataclass.
Does not perform any validation and should not be used directly, only
by the Color dataclass through the Color.from_hsv(hue, saturation, value)
classmethod or Color.rgb_to_hsv(red, green, blue) method.
Attributes:
| Name | Type | Description |
|---|---|---|
hue |
float
|
The hue component of the color, typically in the range [0, 360). |
saturation |
float
|
The saturation component of the color, typically in the range [0, 1]. |
value |
float
|
The value (brightness) component of the color, typically in the range [0, 1]. |
Source code in src/pyvesync/utils/colors.py
pyvesync.utils.colors.RGB
dataclass
↲
RGB color space dataclass, for internal use in utils.colors.Color dataclass.
Does not perform any validation, it should not be used directly. Used as an
attribute in the :obj:pyvesync.helpers.Color dataclass. This should only be
used through the :obj:Color dataclass with the Color.from_rgb(red, green, blue)
classmethod.
Attributes:
| Name | Type | Description |
|---|---|---|
red |
float
|
The red component of the RGB color. |
green |
float
|
The green component of the RGB color. |
blue |
float
|
The blue component of the RGB color. |
Source code in src/pyvesync/utils/colors.py
RGBNightlightColor class↲
Color helpers for devices with an RGB nightlight, such as the OasisMist 4.5L
(LUH-O451S-WEU) humidifier. The VeSync app drives the nightlight color from
an 8-color gradient slider and sends brightness-adjusted RGB values (brightness
applied via the HSV value component) rather than a raw color plus a separate
brightness. This class encapsulates that geometry: mapping an arbitrary RGB
color to the slider position (colorSliderLocation), applying brightness to a
color, and recovering the full-brightness base color from a dimmed one.
pyvesync.utils.colors.RGBNightlightColor ↲
Color helpers for RGB nightlight devices.
Encapsulates the 8-color gradient used by the VeSync app for the RGB nightlight color slider, along with the geometry needed to map an arbitrary RGB color to a slider position and to apply or recover brightness.
Source code in src/pyvesync/utils/colors.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
apply_brightness_to_rgb
staticmethod
↲
Apply brightness to RGB color using HSV color space.
The VeSync app applies brightness by converting to HSV, setting the V (value) component to brightness/100, then converting back to RGB.
From decompiled app: yv/p.java method b()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
red
|
int
|
Red value (0-255). |
required |
green
|
int
|
Green value (0-255). |
required |
blue
|
int
|
Blue value (0-255). |
required |
brightness
|
int
|
Brightness level (0-100). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[int, int, int]
|
Brightness-adjusted (red, green, blue) values. |
Source code in src/pyvesync/utils/colors.py
normalize_to_full_brightness
staticmethod
↲
Normalize brightness-adjusted RGB back to full brightness (100%).
Inverse of apply_brightness_to_rgb. Given RGB values that have been
dimmed, recover the original "full brightness" color by setting HSV
value to 1.0 while preserving hue and saturation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
red
|
int
|
Red value (0-255), brightness-adjusted. |
required |
green
|
int
|
Green value (0-255), brightness-adjusted. |
required |
blue
|
int
|
Blue value (0-255), brightness-adjusted. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[int, int, int]
|
Normalized (red, green, blue) values at full brightness. |
Source code in src/pyvesync/utils/colors.py
rgb_to_color_slider_location
classmethod
↲
Convert RGB values to colorSliderLocation (0-100).
The VeSync app uses an 8-color gradient for the color slider. This finds the closest position on that gradient by checking each segment and finding where the input color best fits.
Note: Input RGB should be at full brightness for accurate results. If the input has reduced brightness, first normalize it.
From decompiled app: yv/p.java (HumidifierColor.kt)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
red
|
int
|
Red value (0-255). |
required |
green
|
int
|
Green value (0-255). |
required |
blue
|
int
|
Blue value (0-255). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Color slider location (0-100). |