33import logging
44import warnings
55from array import array
6- from collections .abc import Callable , Collection
76from logging import DEBUG as LVL_DEBUG
87from math import ceil
9- from typing import TYPE_CHECKING , Any , Final , Literal , Union
8+ from typing import TYPE_CHECKING , Any , Final , Generator , Literal
109
10+ from typing_extensions import Self
11+
12+ from pyartnet .base .channel_fade import ChannelBoundFade
13+ from pyartnet .base .output_correction import OutputCorrection
1114from pyartnet .errors import (
1215 ChannelOutOfUniverseError ,
1316 ChannelValueOutOfBoundsError ,
1720from pyartnet .fades import FadeBase , LinearFade
1821from pyartnet .output_correction import linear
1922
20- from .channel_fade import ChannelBoundFade
21- from .output_correction import OutputCorrection
22-
2323
2424if TYPE_CHECKING :
25+ from collections .abc import Callable , Collection
26+
2527 from .universe import BaseUniverse
2628
2729
@@ -93,7 +95,7 @@ def __init__(self, universe: BaseUniverse,
9395 # Callbacks
9496 self .callback_fade_finished : Callable [[Channel ], Any ] | None = None
9597
96- def _apply_output_correction (self ):
98+ def _apply_output_correction (self ) -> None :
9799 # default correction is linear
98100 self ._correction_current = linear
99101
@@ -102,6 +104,7 @@ def _apply_output_correction(self):
102104 if obj ._correction_output is not None :
103105 self ._correction_current = obj ._correction_output
104106 return None
107+ return None
105108
106109 def get_values (self ) -> list [int ]:
107110 """Get the current (uncorrected) channel values
@@ -110,7 +113,7 @@ def get_values(self) -> list[int]:
110113 """
111114 return self ._values_raw .tolist ()
112115
113- def set_values (self , values : Collection [Union [ int , float ]]) :
116+ def set_values (self , values : Collection [int | float ]) -> Self :
114117 """Set values for a channel without a fade
115118
116119 :param values: Iterable of values with the same size as the channel width
@@ -141,7 +144,7 @@ def set_values(self, values: Collection[Union[int, float]]):
141144 self ._parent_universe .channel_changed (self )
142145 return self
143146
144- def to_buffer (self , buf : bytearray ):
147+ def to_buffer (self , buf : bytearray ) -> Self :
145148 byte_order = self ._byte_order
146149 byte_size = self ._byte_size
147150
@@ -151,15 +154,17 @@ def to_buffer(self, buf: bytearray):
151154 start += byte_size
152155 return self
153156
154- def add_fade (self , values : Collection [Union [ int , FadeBase ] ], duration_ms : int ,
155- fade_class : type [FadeBase ] = LinearFade ):
157+ def add_fade (self , values : Collection [int | FadeBase ], duration_ms : int ,
158+ fade_class : type [FadeBase ] = LinearFade ) -> Self :
156159 warnings .warn (
157- f'{ self .set_fade .__name__ :s} is deprecated, use { self .set_fade .__name__ :s} instead' , DeprecationWarning )
160+ f'{ self .set_fade .__name__ :s} is deprecated, use { self .set_fade .__name__ :s} instead' ,
161+ DeprecationWarning , stacklevel = 2
162+ )
158163 return self .set_fade (values , duration_ms , fade_class )
159164
160165 # noinspection PyProtectedMember
161- def set_fade (self , values : Collection [Union [ int , FadeBase ] ], duration_ms : int ,
162- fade_class : type [FadeBase ] = LinearFade ):
166+ def set_fade (self , values : Collection [int | FadeBase ], duration_ms : int ,
167+ fade_class : type [FadeBase ] = LinearFade ) -> Self :
163168 """Add and schedule a new fade for the channel
164169
165170 :param values: Target values for the fade
@@ -207,7 +212,7 @@ def set_fade(self, values: Collection[Union[int, FadeBase]], duration_ms: int,
207212 log .debug (f'CH { self ._start + i } : { fade .debug_initialize ():s} ' )
208213 return self
209214
210- def __await__ (self ):
215+ def __await__ (self ) -> Generator [ None , None , bool ] :
211216 if self ._current_fade is None :
212217 return False
213218 yield from self ._current_fade .event .wait ().__await__ ()
0 commit comments