Skip to content

Commit

Permalink
Fix blink1 crash in background-run
Browse files Browse the repository at this point in the history
  • Loading branch information
redaxmedia committed Jan 3, 2020
1 parent fcfcce2 commit 6e3ebfe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions chroma_feedback/consumer/thingm_blink/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ def get_api() -> Any:
global API

if not API:
API = api_factory(None)
API = api_factory()
return API


def api_factory(device : str) -> Any:
def api_factory() -> Any:
api = None

try:
from blink1.blink1 import Blink1, Blink1ConnectionFailed

try:
api = Blink1(device)
api = Blink1()
except Blink1ConnectionFailed:
exit(wording.get('connection_no').format('THINGM BLINK') + wording.get('exclamation_mark'))
return api
Expand Down
1 change: 0 additions & 1 deletion chroma_feedback/consumer/thingm_blink/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def init(program : ArgumentParser) -> None:
def run(status : str) -> List[Dict[str, Any]]:
api = get_api()
devices = get_devices(api.list(), ARGS.thingm_blink_device)
api.close()

if not devices:
exit(wording.get('device_no') + wording.get('exclamation_mark'))
Expand Down
14 changes: 7 additions & 7 deletions chroma_feedback/consumer/thingm_blink/device.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Dict, List
import copy
from chroma_feedback import color
from .api import api_factory
from .api import get_api


def get_devices(devices : Any, device_names : List[str]) -> Any:
Expand All @@ -24,7 +24,7 @@ def process_devices(devices : Any, status : str) -> List[Dict[str, Any]]:
'consumer': 'thingm_blink',
'type': 'device',
'name': device,
'active': static_device(device, color.get_passed()),
'active': static_device(color.get_passed()),
'status': status
})
if status == 'process':
Expand All @@ -33,7 +33,7 @@ def process_devices(devices : Any, status : str) -> List[Dict[str, Any]]:
'consumer': 'thingm_blink',
'type': 'device',
'name': device,
'active': static_device(device, color.get_process()),
'active': static_device(color.get_process()),
'status': status
})
if status == 'errored':
Expand All @@ -42,7 +42,7 @@ def process_devices(devices : Any, status : str) -> List[Dict[str, Any]]:
'consumer': 'thingm_blink',
'type': 'device',
'name': device,
'active': static_device(device, color.get_errored()),
'active': static_device(color.get_errored()),
'status': status
})
if status == 'failed':
Expand All @@ -51,13 +51,13 @@ def process_devices(devices : Any, status : str) -> List[Dict[str, Any]]:
'consumer': 'thingm_blink',
'type': 'device',
'name': device,
'active': static_device(device, color.get_failed()),
'active': static_device(color.get_failed()),
'status': status
})
return result


def static_device(device : Any, state : Dict[str, Any]) -> bool:
api = api_factory(device)
def static_device(state : Dict[str, Any]) -> bool:
api = get_api()

return api is not None and api.fade_to_rgb(0, state['rgb'][0], state['rgb'][1], state['rgb'][2]) is None

0 comments on commit 6e3ebfe

Please sign in to comment.