Skip to content

Commit b205e66

Browse files
committed
allow overriding of the platform detect
1 parent 3f3ae47 commit b205e66

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

adafruit_platformdetect/board.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Detect boards."""
2+
import os
23
import adafruit_platformdetect.chip as ap_chip
34

45
# Allow for aligned constant definitions:
@@ -175,6 +176,12 @@ def __init__(self, detector):
175176
@property
176177
def id(self):
177178
"""Return a unique id for the detected board, if any."""
179+
# There are some times we want to trick the platform detection
180+
# say if a raspberry pi doesn't have the right ID, or for testing
181+
try:
182+
return os.environ['BLINKA_FORCEBOARD']
183+
except KeyError: # no forced board, continue with testing!
184+
pass
178185

179186
chip_id = self.detector.chip.id
180187
board_id = None

adafruit_platformdetect/chip.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ def __init__(self, detector):
1919
self.detector = detector
2020

2121
@property
22-
# pylint: disable=invalid-name
23-
def id(self):
22+
def id(self): # pylint: disable=invalid-name,too-many-branches,too-many-return-statements
2423
"""Return a unique id for the detected chip, if any."""
24+
# There are some times we want to trick the platform detection
25+
# say if a raspberry pi doesn't have the right ID, or for testing
26+
try:
27+
return os.environ['BLINKA_FORCECHIP']
28+
except KeyError: # no forced chip, continue with testing!
29+
pass
30+
2531
platform = sys.platform
2632
if platform == "linux":
2733
return self._linux_id()

0 commit comments

Comments
 (0)