Skip to content

Commit

Permalink
Vendor based refactoring (#134)
Browse files Browse the repository at this point in the history
* Enable Window support, Add fit StatUSB consumer

* Fix lint issue

* Switch to brandnew busylight exceptions

* Switch to serial based filtering

* Use acquire over is_pluggedin

* Use vendor namespacing for each consumer

* Fix name in test reporter

* Fix status

* Make it uniform

* Revert "Make it uniform"

This reverts commit b3bc1a8.

* Make it uniform

* Refactor producers aswell

* Fix CI

* Fix CI

* Fix CI

* Fix CI

* Fix CI
  • Loading branch information
henryruhs committed Oct 2, 2022
1 parent 46ca51f commit d56e543
Show file tree
Hide file tree
Showing 235 changed files with 1,061 additions and 571 deletions.
12 changes: 6 additions & 6 deletions .github/terminal-session.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ jobs:
- run: pytest tests
env:
APPVEYOR_TOKEN: ${{ secrets.APPVEYOR_TOKEN }}
BITBUCKET_USERNAME: ${{ secrets.BITBUCKET_USERNAME }}
BITBUCKET_PASSWORD: ${{ secrets.BITBUCKET_PASSWORD }}
ATLASSIAN_BITBUCKET_USERNAME: ${{ secrets.ATLASSIAN_BITBUCKET_USERNAME }}
ATLASSIAN_BITBUCKET_PASSWORD: ${{ secrets.ATLASSIAN_BITBUCKET_PASSWORD }}
CIRCLE_TOKEN: ${{ secrets.CIRCLE_TOKEN }}
CODESHIP_USERNAME: ${{ secrets.CODESHIP_USERNAME }}
CODESHIP_PASSWORD: ${{ secrets.CODESHIP_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CLOUDBEES_CODESHIP_USERNAME: ${{ secrets.CLOUDBEES_CODESHIP_USERNAME }}
CLOUDBEES_CODESHIP_PASSWORD: ${{ secrets.CLOUDBEES_CODESHIP_PASSWORD }}
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
HEROKU_TOKEN: ${{ secrets.HEROKU_TOKEN }}
JETBRAINS_TEAMCITY_TOKEN: ${{ secrets.JETBRAINS_TEAMCITY_TOKEN }}
MICROSOFT_GITHUB_TOKEN: ${{ secrets.MICROSOFT_GITHUB_TOKEN }}
NETLIFY_TOKEN: ${{ secrets.NETLIFY_TOKEN }}
TEAMCITY_TOKEN: ${{ secrets.TEAMCITY_TOKEN }}
TRAVIS_TOKEN: ${{ secrets.TRAVIS_TOKEN }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
report:
Expand All @@ -72,16 +72,16 @@ jobs:
- run: pytest tests --cov=chroma_feedback
env:
APPVEYOR_TOKEN: ${{ secrets.APPVEYOR_TOKEN }}
BITBUCKET_USERNAME: ${{ secrets.BITBUCKET_USERNAME }}
BITBUCKET_PASSWORD: ${{ secrets.BITBUCKET_PASSWORD }}
ATLASSIAN_BITBUCKET_USERNAME: ${{ secrets.ATLASSIAN_BITBUCKET_USERNAME }}
ATLASSIAN_BITBUCKET_PASSWORD: ${{ secrets.ATLASSIAN_BITBUCKET_PASSWORD }}
CIRCLE_TOKEN: ${{ secrets.CIRCLE_TOKEN }}
CODESHIP_USERNAME: ${{ secrets.CODESHIP_USERNAME }}
CODESHIP_PASSWORD: ${{ secrets.CODESHIP_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CLOUDBEES_CODESHIP_USERNAME: ${{ secrets.CLOUDBEES_CODESHIP_USERNAME }}
CLOUDBEES_CODESHIP_PASSWORD: ${{ secrets.CLOUDBEES_CODESHIP_PASSWORD }}
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
HEROKU_TOKEN: ${{ secrets.HEROKU_TOKEN }}
JETBRAINS_TEAMCITY_TOKEN: ${{ secrets.JETBRAINS_TEAMCITY_TOKEN }}
MICROSOFT_GITHUB_TOKEN: ${{ secrets.MICROSOFT_GITHUB_TOKEN }}
NETLIFY_TOKEN: ${{ secrets.NETLIFY_TOKEN }}
TEAMCITY_TOKEN: ${{ secrets.TEAMCITY_TOKEN }}
TRAVIS_TOKEN: ${{ secrets.TRAVIS_TOKEN }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
- run: coveralls --service=github
Expand Down
33 changes: 17 additions & 16 deletions chroma_feedback/consumer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
from .core import process

__all__ =\
[
'agile_innovative_blinkstick',
'elgato_streamdeck',
'embrava_blynclight',
'kuando_busylight',
'lifx_light',
'luxafor_flag',
'magic_hue',
'nanoleaf_light',
'philips_hue',
'razer_chroma',
'thingm_blink1',
'wiz_light',
'xiaomi_yeelight'
]
ALL = \
{
'agile_innovative.blinkstick': 'chroma_feedback.consumer.agile_innovative.blinkstick',
'compulab_fit.statusb': 'chroma_feedback.consumer.compulab_fit.statusb',
'elgato.streamdeck': 'chroma_feedback.consumer.elgato.streamdeck',
'embrava.blynclight': 'chroma_feedback.consumer.embrava.blynclight',
'kuando.busylight': 'chroma_feedback.consumer.kuando.busylight',
'lifx': 'chroma_feedback.consumer.lifx.lifx',
'luxafor.flag': 'chroma_feedback.consumer.luxafor.flag',
'magic.hue': 'chroma_feedback.consumer.magic.hue',
'nanoleaf': 'chroma_feedback.consumer.nanoleaf.nanoleaf',
'philips.hue': 'chroma_feedback.consumer.philips.hue',
'razer.chroma': 'chroma_feedback.consumer.razer.chroma',
'signify.wiz': 'chroma_feedback.consumer.signify.wiz',
'thingm.blink1': 'chroma_feedback.consumer.thingm.blink1',
'xiaomi.yeelight': 'chroma_feedback.consumer.xiaomi.yeelight'
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def get_api() -> Any:

def api_factory() -> Any:
try:
from busylight.lights import USBLightIOError, USBLightNotFound
from busylight.lights import NoLightsFound, LightUnavailable
from busylight.lights.agile_innovative import BlinkStick as api

try:
api.first_light().release()
except (USBLightIOError, USBLightNotFound):
logger.error(wording.get('connection_not_found').format('agile_innovative_blinkstick') + wording.get('exclamation_mark'))
api.first_light().acquire()
except (NoLightsFound, LightUnavailable):
logger.error(wording.get('connection_not_found').format('agile_innovative.blinkstick') + wording.get('exclamation_mark'))
sys.exit()
return api
except ImportError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def support() -> bool:
return helper.is_linux() is True or helper.is_mac() is True
return helper.is_linux() is True or helper.is_mac() is True or helper.is_windows() is True


def init(program : ArgumentParser) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def process_lights(lights : Any, producer_report : List[ProducerReport]) -> List
if set_light(light, color.get_by_status(status)):
result.append(
{
'name': 'agile_innovative_blinkstick',
'name': 'agile_innovative.blinkstick',
'type': 'light',
'description': helper.create_description(light.info['product_string'], light.info['serial_number']),
'status': status
Expand Down
30 changes: 30 additions & 0 deletions chroma_feedback/consumer/compulab_fit/statusb/api.py
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 NoLightsFound, LightUnavailable
from busylight.lights.compulap import Fit_StatUSB as api

try:
api.first_light().acquire()
except (NoLightsFound, LightUnavailable):
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()
30 changes: 30 additions & 0 deletions chroma_feedback/consumer/compulab_fit/statusb/core.py
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-serial', 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_serial)

if not light:
logger.error(wording.get('device_not_found') + wording.get('exclamation_mark'))
sys.exit()
return process_lights(light, producer_report)
48 changes: 48 additions & 0 deletions chroma_feedback/consumer/compulab_fit/statusb/light.py
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_serials : List[str]) -> Any:
if light_serials:
for light in copy.copy(lights):
if light.info['serial_number'] not in light_serials:
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.info['serial_number']),
'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

6 changes: 3 additions & 3 deletions chroma_feedback/consumer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from argparse import ArgumentParser
from typing import Any, List

from chroma_feedback import helper, logger, wording
from chroma_feedback import consumer, helper, logger, wording
from chroma_feedback.typing import Consumer, ProducerReport


Expand All @@ -29,7 +29,7 @@ def process(program : ArgumentParser, producer_report : List[ProducerReport]) ->

def load_consumer(consumer_name : str) -> Any:
try:
return importlib.import_module('chroma_feedback.consumer.' + consumer_name)
return importlib.import_module(consumer.ALL[consumer_name])
except ImportError:
logger.error(wording.get('consumer_not_found').format(consumer_name) + wording.get('exclamation_mark'))
logger.error(wording.get('consumer_not_found').format(consumer.ALL[consumer_name]) + wording.get('exclamation_mark'))
sys.exit()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def api_factory() -> Any:
api = DeviceManager()
api.enumerate()
except ProbeError:
logger.error(wording.get('connection_not_found').format('elgato_streamdeck') + wording.get('exclamation_mark'))
logger.error(wording.get('connection_not_found').format('elgato.streamdeck') + wording.get('exclamation_mark'))
sys.exit()
return api
except ImportError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def process_devices(devices : Any, producer_report : List[ProducerReport]) -> Li
if set_device(device, producer_report):
result.append(
{
'name': 'elgato_streamdeck',
'name': 'elgato.streamdeck',
'type': 'device',
'description': helper.create_description(device.deck_type(), device.id()),
'status': status
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def get_api() -> Any:

def api_factory() -> Any:
try:
from busylight.lights import USBLightIOError, USBLightNotFound
from busylight.lights import NoLightsFound, LightUnavailable
from busylight.lights.embrava import Blynclight as api

try:
api.first_light().release()
except (USBLightIOError, USBLightNotFound):
logger.error(wording.get('connection_not_found').format('embrava_blynclight') + wording.get('exclamation_mark'))
api.first_light().acquire()
except (NoLightsFound, LightUnavailable):
logger.error(wording.get('connection_not_found').format('embrava.blynclight') + wording.get('exclamation_mark'))
sys.exit()
return api
except ImportError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def support() -> bool:
return helper.is_linux() is True or helper.is_mac() is True
return helper.is_linux() is True or helper.is_mac() is True or helper.is_windows() is True


def init(program : ArgumentParser) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def process_lights(lights : Any, producer_report : List[ProducerReport]) -> List
if set_light(light, color.get_by_status(status)):
result.append(
{
'name': 'embrava_blynclight',
'name': 'embrava.blynclight',
'type': 'light',
'description': helper.create_description(light.info['product_string'], light.path),
'status': status
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def get_api() -> Any:

def api_factory() -> Any:
try:
from busylight.lights import USBLightIOError, USBLightNotFound
from busylight.lights import NoLightsFound, LightUnavailable
from busylight.lights.kuando import Busylight as api

try:
api.first_light().release()
except (USBLightIOError, USBLightNotFound):
logger.error(wording.get('connection_not_found').format('kuando_busylight') + wording.get('exclamation_mark'))
api.first_light().acquire()
except (NoLightsFound, LightUnavailable):
logger.error(wording.get('connection_not_found').format('kuando.busylight') + wording.get('exclamation_mark'))
sys.exit()
return api
except ImportError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def support() -> bool:
return helper.is_linux() is True or helper.is_mac() is True
return helper.is_linux() is True or helper.is_mac() is True or helper.is_windows() is True


def init(program : ArgumentParser) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def process_lights(lights : Any, producer_report : List[ProducerReport]) -> List
if set_light(light, color.get_by_status(status)):
result.append(
{
'name': 'kuando_busylight',
'name': 'kuando.busylight',
'type': 'light',
'description': helper.create_description(light.info['product_string'], light.path),
'status': status
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def api_factory() -> Any:
try:
api = LifxLAN()
except WorkflowException:
logger.error(wording.get('connection_not_found').format('lifx_light') + wording.get('exclamation_mark'))
logger.error(wording.get('connection_not_found').format('lifx') + wording.get('exclamation_mark'))
sys.exit()
return api
except ImportError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ def init(program : ArgumentParser) -> None:
global ARGS

if not ARGS:
program.add_argument('--lifx-light-group-name', action = 'append')
program.add_argument('--lifx-light-light-ip', action = 'append')
program.add_argument('--lifx-group-name', action = 'append')
program.add_argument('--lifx-light-ip', action = 'append')
ARGS = helper.get_first(program.parse_known_args())


def run(producer_report : List[ProducerReport]) -> List[Consumer]:
if ARGS.lifx_light_group_name:
groups = get_groups(ARGS.lifx_light_group_name)
groups = get_groups(ARGS.lifx_group_name)

if not groups:
logger.error(wording.get('group_not_found') + wording.get('exclamation_mark'))
Expand All @@ -34,7 +34,7 @@ def run(producer_report : List[ProducerReport]) -> List[Consumer]:

# fallback as needed

lights = filter_lights(get_lights(), ARGS.lifx_light_light_ip)
lights = filter_lights(get_lights(), ARGS.lifx_light_ip)

if not lights:
logger.error(wording.get('light_not_found') + wording.get('exclamation_mark'))
Expand Down
Loading

0 comments on commit d56e543

Please sign in to comment.