-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
248 additions
and
11 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from .core import init, run, support |
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,30 @@ | ||
import sys | ||
from typing import Any | ||
|
||
from chroma_feedback import logger, wording | ||
|
||
API = None | ||
|
||
|
||
def get_api() -> Any: | ||
global API | ||
|
||
if not API: | ||
API = api_factory() | ||
return API | ||
|
||
|
||
def api_factory() -> Any: | ||
try: | ||
from busylight.lights import USBLightIOError, USBLightNotFound | ||
from busylight.lights.compulap import Fit_StatUSB as api | ||
|
||
try: | ||
api.first_light().release() | ||
except (USBLightIOError, USBLightNotFound): | ||
logger.error(wording.get('connection_not_found').format('compulab_fit_statusb') + wording.get('exclamation_mark')) | ||
sys.exit() | ||
return api | ||
except ImportError: | ||
logger.error(wording.get('package_not_found').format('busylight-for-humans') + wording.get('exclamation_mark')) | ||
sys.exit() |
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,30 @@ | ||
import sys | ||
from argparse import ArgumentParser | ||
from typing import List | ||
|
||
from chroma_feedback import helper, logger, wording | ||
from chroma_feedback.typing import Consumer, ProducerReport | ||
from .light import filter_lights, get_lights, process_lights | ||
|
||
ARGS = None | ||
|
||
|
||
def support() -> bool: | ||
return helper.is_linux() is True or helper.is_mac() is True or helper.is_windows() is True | ||
|
||
|
||
def init(program : ArgumentParser) -> None: | ||
global ARGS | ||
|
||
if not ARGS: | ||
program.add_argument('--compulab-fit-statusb-light-id', action = 'append') | ||
ARGS = helper.get_first(program.parse_known_args()) | ||
|
||
|
||
def run(producer_report : List[ProducerReport]) -> List[Consumer]: | ||
light = filter_lights(get_lights(), ARGS.compulab_fit_statusb_light_id) | ||
|
||
if not light: | ||
logger.error(wording.get('device_not_found') + wording.get('exclamation_mark')) | ||
sys.exit() | ||
return process_lights(light, producer_report) |
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,48 @@ | ||
import copy | ||
from typing import Any, List | ||
|
||
from chroma_feedback import color, helper, reporter | ||
from chroma_feedback.typing import Color, Consumer, ProducerReport, Status | ||
from .api import get_api | ||
|
||
LIGHTS = None | ||
|
||
|
||
def get_lights() -> Any: | ||
global LIGHTS | ||
|
||
if not LIGHTS: | ||
LIGHTS = get_api().all_lights() | ||
return LIGHTS | ||
|
||
|
||
def filter_lights(lights : Any, light_ids : List[str]) -> Any: | ||
if light_ids: | ||
for light in copy.copy(lights): | ||
if light.path not in light_ids: | ||
lights.remove(light) | ||
return lights | ||
|
||
|
||
def process_lights(lights : Any, producer_report : List[ProducerReport]) -> List[Consumer]: | ||
result : List[Consumer] = [] | ||
status : Status = reporter.resolve_report_status(producer_report) | ||
|
||
# process lights | ||
|
||
for light in lights: | ||
if set_light(light, color.get_by_status(status)): | ||
result.append( | ||
{ | ||
'name': 'compulab_fit_statusb', | ||
'type': 'light', | ||
'description': helper.create_description(light.info['product_string'], light.path), | ||
'status': status | ||
}) | ||
return result | ||
|
||
|
||
def set_light(light : Any, color_config : Color) -> bool: | ||
light.on(tuple(color_config['rgb'])) | ||
return light.is_on is True | ||
|
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
Empty file.
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,126 @@ | ||
import pytest | ||
from unittest.mock import MagicMock | ||
|
||
from chroma_feedback.consumer.compulab_fit_statusb.light import process_lights | ||
|
||
MOCK = MagicMock() | ||
|
||
|
||
def test_process_passed() -> None: | ||
try: | ||
result = process_lights( | ||
{ | ||
MOCK | ||
}, | ||
[ | ||
{ | ||
'name': 'github', | ||
'symbol': None, | ||
'message': None, | ||
'url': 'https://github.com/henryruhs/chroma-feedback/actions/runs/1', | ||
'status': 'passed' | ||
} | ||
]) | ||
|
||
assert result[0]['name'] == 'compulab_fit_statusb' | ||
assert result[0]['type'] == 'device' | ||
assert result[0]['description'] | ||
assert result[0]['status'] == 'passed' | ||
except: | ||
pytest.skip() | ||
|
||
|
||
def test_process_started() -> None: | ||
try: | ||
result = process_lights( | ||
{ | ||
MOCK | ||
}, | ||
[ | ||
{ | ||
'name': 'github', | ||
'symbol': None, | ||
'message': None, | ||
'url': 'https://github.com/henryruhs/chroma-feedback/actions/runs/1', | ||
'status': 'started' | ||
} | ||
]) | ||
|
||
assert result[0]['name'] == 'compulab_fit_statusb' | ||
assert result[0]['type'] == 'device' | ||
assert result[0]['description'] | ||
assert result[0]['status'] == 'started' | ||
except: | ||
pytest.skip() | ||
|
||
|
||
def test_process_errored() -> None: | ||
try: | ||
result = process_lights( | ||
{ | ||
MOCK | ||
}, | ||
[ | ||
{ | ||
'name': 'github', | ||
'symbol': None, | ||
'message': None, | ||
'url': 'https://github.com/henryruhs/chroma-feedback/actions/runs/1', | ||
'status': 'errored' | ||
} | ||
]) | ||
|
||
assert result[0]['name'] == 'compulab_fit_statusb' | ||
assert result[0]['type'] == 'device' | ||
assert result[0]['description'] | ||
assert result[0]['status'] == 'errored' | ||
except: | ||
pytest.skip() | ||
|
||
|
||
def test_process_warned() -> None: | ||
try: | ||
result = process_lights( | ||
{ | ||
MOCK | ||
}, | ||
[ | ||
{ | ||
'name': 'github', | ||
'symbol': None, | ||
'message': None, | ||
'url': 'https://github.com/henryruhs/chroma-feedback/actions/runs/1', | ||
'status': 'warned' | ||
} | ||
]) | ||
|
||
assert result[0]['name'] == 'compulab_fit_statusb' | ||
assert result[0]['type'] == 'device' | ||
assert result[0]['description'] | ||
assert result[0]['status'] == 'warned' | ||
except: | ||
pytest.skip() | ||
|
||
|
||
def test_process_failed() -> None: | ||
try: | ||
result = process_lights( | ||
{ | ||
MOCK | ||
}, | ||
[ | ||
{ | ||
'name': 'github', | ||
'symbol': None, | ||
'message': None, | ||
'url': 'https://github.com/henryruhs/chroma-feedback/actions/runs/1', | ||
'status': 'failed' | ||
} | ||
]) | ||
|
||
assert result[0]['name'] == 'compulab_fit_statusb' | ||
assert result[0]['type'] == 'device' | ||
assert result[0]['description'] | ||
assert result[0]['status'] == 'failed' | ||
except: | ||
pytest.skip() |