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 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
105 106 107 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 |
|
__repr__ ↲
as_dict ↲
Return color values as dict.
Source code in src\pyvesync\utils\colors.py
from_hsv
classmethod
↲
from_hsv(
hue: NUMERIC_STRICT,
saturation: NUMERIC_STRICT,
value: NUMERIC_STRICT,
) -> Color | None
Create Color instance from HSV values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hue
|
NUMERIC_STRICT
|
The hue component of the color, in the range [0, 360). |
required |
saturation
|
NUMERIC_STRICT
|
The saturation component of the color, typically in the range [0, 1]. |
required |
value
|
NUMERIC_STRICT
|
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: NUMERIC_STRICT,
green: NUMERIC_STRICT,
blue: NUMERIC_STRICT,
) -> 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. |