Skip to content

Commit

Permalink
Error type raise changed, to enable in external lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
riokuu committed Jul 1, 2022
1 parent c79ec52 commit fcef74e
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions blebox_uniapi/light.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from enum import IntEnum
from .feature import Feature
from .error import BadOnValueError
from typing import TYPE_CHECKING, Optional, Dict, Any, Union, Sequence

if TYPE_CHECKING:
Expand Down Expand Up @@ -256,24 +255,24 @@ def color_temp(self):
def evaluate_brightness_from_rgb(iterable: Sequence[int]) -> int:
"return brightness from 0 to 255 evaluated basing rgb"
if max(iterable) > 255:
raise BadOnValueError(
raise ValueError(
f"evaluate_brightness_from_rgb values out of range, max is {max(iterable)}."
)
elif min(iterable) < 0:
raise BadOnValueError(
raise ValueError(
f"evaluate_brightness_from_rgb values out of range, min is {min(iterable)}."
)
return int(max(iterable))

def apply_brightness(self, value: int, brightness: int) -> Any:
"""Return list of values with applied brightness."""
if not isinstance(brightness, int):
raise BadOnValueError(
raise ValueError(
f"adjust_brightness called with bad parameter ({brightness} is {type(brightness)} instead of int)"
)

if brightness > 255:
raise BadOnValueError(
raise ValueError(
f"adjust_brightness called with bad parameter ({brightness} is greater than 255)"
)

Expand Down Expand Up @@ -399,11 +398,11 @@ def normalise_elements_of_rgb(elements):
max_val = max(elements)
min_val = min(elements)
if 0 > max_val or max_val > 255:
raise BadOnValueError(
raise ValueError(
f"Max value in normalisation was outside range {max_val}."
)
elif min_val < 0:
raise BadOnValueError(
raise ValueError(
f"Min value in normalisation was outside range {min_val}."
)
elif max_val == 0:
Expand Down Expand Up @@ -457,7 +456,7 @@ def _set_last_on_value(self, alias, product, raw):
raw = self._default_on_value

if raw in (self._off_value, None):
raise BadOnValueError(raw)
raise ValueError(raw)
# TODO: store as custom value permanently (exposed by API consumer)
self._last_on_state = raw

Expand Down Expand Up @@ -581,7 +580,7 @@ async def async_on(self, value: Any) -> None:
)

if value == self._off_value:
raise BadOnValueError(f"turn_on called with invalid value ({value})")
raise ValueError(f"turn_on called with invalid value ({value})")

if self.mask is not None:
value = self.mask(value)
Expand Down

0 comments on commit fcef74e

Please sign in to comment.