-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from robberwick/device-major-version-variant
Device major version variant
- Loading branch information
Showing
16 changed files
with
200 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,2 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
|
||
VENDOR_ID = 0x20A0 | ||
PRODUCT_ID = 0x41E5 | ||
|
||
|
||
class BlinkStickVariant(Enum): | ||
UNKNOWN = (0, "Unknown") | ||
BLINKSTICK = (1, "BlinkStick") | ||
BLINKSTICK_PRO = (2, "BlinkStick Pro") | ||
BLINKSTICK_STRIP = (3, "BlinkStick Strip") | ||
BLINKSTICK_SQUARE = (4, "BlinkStick Square") | ||
BLINKSTICK_NANO = (5, "BlinkStick Nano") | ||
BLINKSTICK_FLEX = (6, "BlinkStick Flex") | ||
|
||
@property | ||
def value(self) -> int: | ||
return self._value_[0] | ||
|
||
@property | ||
def description(self) -> str: | ||
return self._value_[1] | ||
|
||
@staticmethod | ||
def identify( | ||
major_version: int, version_attribute: int | None | ||
) -> "BlinkStickVariant": | ||
if major_version == 1: | ||
return BlinkStickVariant.BLINKSTICK | ||
elif major_version == 2: | ||
return BlinkStickVariant.BLINKSTICK_PRO | ||
elif major_version == 3: | ||
if version_attribute == 0x200: | ||
return BlinkStickVariant.BLINKSTICK_SQUARE | ||
elif version_attribute == 0x201: | ||
return BlinkStickVariant.BLINKSTICK_STRIP | ||
elif version_attribute == 0x202: | ||
return BlinkStickVariant.BLINKSTICK_NANO | ||
elif version_attribute == 0x203: | ||
return BlinkStickVariant.BLINKSTICK_FLEX | ||
return BlinkStickVariant.UNKNOWN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
|
||
|
||
class BlinkStickVariant(Enum): | ||
UNKNOWN = (0, "Unknown") | ||
BLINKSTICK = (1, "BlinkStick") | ||
BLINKSTICK_PRO = (2, "BlinkStick Pro") | ||
BLINKSTICK_STRIP = (3, "BlinkStick Strip") | ||
BLINKSTICK_SQUARE = (4, "BlinkStick Square") | ||
BLINKSTICK_NANO = (5, "BlinkStick Nano") | ||
BLINKSTICK_FLEX = (6, "BlinkStick Flex") | ||
|
||
@property | ||
def value(self) -> int: | ||
return self._value_[0] | ||
|
||
@property | ||
def description(self) -> str: | ||
return self._value_[1] | ||
|
||
@staticmethod | ||
def from_version_attrs( | ||
major_version: int, version_attribute: int | None | ||
) -> "BlinkStickVariant": | ||
if major_version == 1: | ||
return BlinkStickVariant.BLINKSTICK | ||
elif major_version == 2: | ||
return BlinkStickVariant.BLINKSTICK_PRO | ||
elif major_version == 3: | ||
if version_attribute == 0x200: | ||
return BlinkStickVariant.BLINKSTICK_SQUARE | ||
elif version_attribute == 0x201: | ||
return BlinkStickVariant.BLINKSTICK_STRIP | ||
elif version_attribute == 0x202: | ||
return BlinkStickVariant.BLINKSTICK_NANO | ||
elif version_attribute == 0x203: | ||
return BlinkStickVariant.BLINKSTICK_FLEX | ||
return BlinkStickVariant.UNKNOWN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import re | ||
from dataclasses import dataclass, field | ||
|
||
|
||
@dataclass(frozen=True) | ||
class SerialDetails: | ||
""" | ||
A BlinkStick serial number representation. | ||
BSnnnnnn-1.0 | ||
|| | | |- Software minor version | ||
|| | |--- Software major version | ||
|| |-------- Denotes sequential number | ||
||----------- Denotes BlinkStick backend | ||
""" | ||
|
||
serial: str | ||
major_version: int = field(init=False) | ||
minor_version: int = field(init=False) | ||
sequence_number: int = field(init=False) | ||
|
||
def __post_init__(self): | ||
serial_number_regex = r"BS(\d+)-(\d+)\.(\d+)" | ||
match = re.match(serial_number_regex, self.serial) | ||
if not match: | ||
raise ValueError(f"Invalid serial number: {self.serial}") | ||
|
||
object.__setattr__(self, "sequence_number", int(match.group(1))) | ||
object.__setattr__(self, "major_version", int(match.group(2))) | ||
object.__setattr__(self, "minor_version", int(match.group(3))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.