Skip to content

Commit 267de41

Browse files
committed
refactor: Updated agile innovative blinkstick classes with a parameterized _claims classmethod
1 parent 1f75546 commit 267de41

File tree

6 files changed

+32
-49
lines changed

6 files changed

+32
-49
lines changed

src/busylight_core/vendors/agile_innovative/blinkstick_base.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ def vendor() -> str:
3434
"""Return the vendor name for this device."""
3535
return "Agile Innovative"
3636

37+
@classmethod
38+
def _claims(
39+
cls, hardware: Hardware, major: int, release_number: int | None = None
40+
) -> bool:
41+
"""Return True if the hardware matches the BlinkStick criteria."""
42+
43+
claim = super().claims(hardware)
44+
45+
try:
46+
major, _ = cls.get_version(hardware.serial_number)
47+
except ValueError:
48+
return False
49+
50+
if release_number is None:
51+
return claim and major == major
52+
53+
return claim and major == major and hardware.release_number == release_number
54+
3755
@property
3856
def state(self) -> State:
3957
"""BlinkStick state property."""

src/busylight_core/vendors/agile_innovative/blinkstick_flex.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,10 @@ class BlinkStickFlex(BlinkStickBase):
2525

2626
@classmethod
2727
def claims(cls, hardware: Hardware) -> bool:
28-
"""Check if the hardware describes a BlinkStick Flex."""
29-
claim = super().claims(hardware)
30-
31-
try:
32-
major, _ = cls.get_version(hardware.serial_number)
33-
except ValueError:
34-
return False
35-
36-
return claim and major == 3 and hardware.release_number == 0x203
28+
"""Return True if the hardware describes a BlinkStick Flex."""
29+
return cls._claims(hardware, 3, 0x203)
3730

3831
@cached_property
3932
def state(self) -> State:
40-
"""Get the current state of the BlinkStick Flex."""
33+
"""The state of the BlinkStick Flex."""
4134
return State.blinkstick_flex()

src/busylight_core/vendors/agile_innovative/blinkstick_nano.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,10 @@ class BlinkStickNano(BlinkStickBase):
2525

2626
@classmethod
2727
def claims(cls, hardware: Hardware) -> bool:
28-
"""Check if the hardware describes a BlinkStick Nano."""
29-
claim = super().claims(hardware)
30-
31-
try:
32-
major, _ = cls.get_version(hardware.serial_number)
33-
except ValueError:
34-
return False
35-
36-
return claim and major == 3 and hardware.release_number == 0x202
28+
"""Return True if the hardware describes a BlinkStick Nano."""
29+
return cls._claims(hardware, 3, 0x202)
3730

3831
@cached_property
3932
def state(self) -> State:
40-
"""Get the current state of the BlinkStick Nano."""
33+
"""The state of the BlinkStick Nano."""
4134
return State.blinkstick_nano()

src/busylight_core/vendors/agile_innovative/blinkstick_pro.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,10 @@ class BlinkStickPro(BlinkStickBase):
2525

2626
@classmethod
2727
def claims(cls, hardware: Hardware) -> bool:
28-
"""Check if the hardware describes a BlinkStick Pro."""
29-
claim = super().claims(hardware)
30-
31-
try:
32-
major, _ = cls.get_version(hardware.serial_number)
33-
except ValueError:
34-
return False
35-
36-
return claim and major == 2
28+
"""Return True if the hardware describes a BlinkStick Pro."""
29+
return cls._claims(hardware, 2)
3730

3831
@cached_property
3932
def state(self) -> State:
40-
"""Get the current state of the BlinkStick Pro."""
33+
"""The state of the BlinkStick Pro."""
4134
return State.blinkstick_pro()

src/busylight_core/vendors/agile_innovative/blinkstick_square.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,9 @@ class BlinkStickSquare(BlinkStickBase):
2626
@classmethod
2727
def claims(cls, hardware: Hardware) -> bool:
2828
"""Return True if the hardware describes a BlinkStick Square."""
29-
claim = super().claims(hardware)
30-
31-
try:
32-
major, _ = cls.get_version(hardware.serial_number)
33-
except ValueError:
34-
return False
35-
36-
return claim and major == 3 and hardware.release_number == 0x200
29+
return cls._claims(hardware, 3, 0x200)
3730

3831
@cached_property
3932
def state(self) -> State:
40-
"""Get the current state of the BlinkStick Square."""
33+
"""The state of the BlinkStick Square."""
4134
return State.blinkstick_square()

src/busylight_core/vendors/agile_innovative/blinkstick_strip.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,10 @@ class BlinkStickStrip(BlinkStickBase):
2525

2626
@classmethod
2727
def claims(cls, hardware: Hardware) -> bool:
28-
"""Check if the hardware describes a BlinkStick Strip."""
29-
claim = super().claims(hardware)
30-
31-
try:
32-
major, _ = cls.get_version(hardware.serial_number)
33-
except ValueError:
34-
return False
35-
36-
return claim and major == 3 and hardware.release_number == 0x201
28+
"""Return True if the hardware describes a BlinkStick Strip."""
29+
return cls._claims(hardware, 3, 0x201)
3730

3831
@cached_property
3932
def state(self) -> State:
40-
"""Get the current state of the BlinkStick Strip."""
33+
"""The state of the BlinkStick Strip."""
4134
return State.blinkstick_strip()

0 commit comments

Comments
 (0)