Skip to content

Commit

Permalink
implement named colors from config. fix #632
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdoa2 committed May 3, 2017
1 parent 379f5ee commit 5d3044b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions .landscape.yml
Expand Up @@ -20,6 +20,7 @@ pylint:
- pointless-string-statement # pointless statement, which is how our event docstrings are seen
- invalid-name # we got ms and dt as defaults for a lot of functions
- too-few-public-methods
- cyclic-import # remove when type checking is supported

options:
max-attributes: 12
Expand Down
2 changes: 2 additions & 0 deletions mpf/core/config_spec.py
Expand Up @@ -646,6 +646,8 @@
locked_ball_counting_strategy: single|enum(virtual_only,min_virtual_physical,physical_only,no_virtual)|virtual_only
reset_all_counts_events: dict|str:ms|None
reset_count_for_current_player_events: dict|str:ms|None
named_colors:
__valid_in__: machine
opp:
__valid_in__: machine
ports: list|str|
Expand Down
10 changes: 9 additions & 1 deletion mpf/core/light_controller.py
Expand Up @@ -5,7 +5,7 @@
from mpf.core.machine import MachineController
from mpf.core.settings_controller import SettingEntry

from mpf.core.rgb_color import RGBColorCorrectionProfile
from mpf.core.rgb_color import RGBColorCorrectionProfile, RGBColor

from mpf.core.mpf_controller import MpfController

Expand All @@ -26,6 +26,14 @@ def __init__(self, machine: MachineController) -> None:

self._monitor_update_task = None # type: asyncio.Task

if 'named_colors' in self.machine.config:
self._load_named_colors()

def _load_named_colors(self):
"""Load named colors from config."""
for name, color in self.machine.config['named_colors'].items():
RGBColor.add_color(name, color)

def initialise_light_subsystem(self):
"""Initialise the light subsystem."""
if self._initialised:
Expand Down
2 changes: 1 addition & 1 deletion mpf/core/rgb_color.py
Expand Up @@ -430,7 +430,7 @@ def string_to_rgb(value: str, default=rgb_min) -> Tuple[int, int, int]:
return rgb

@staticmethod
def add_color(name, color):
def add_color(name: str, color: Union["RGBColor", str, List[int], Tuple[int, int, int]]):
"""Add (or updates if it already exists) a color.
Note that this is not
Expand Down
5 changes: 3 additions & 2 deletions mpf/platforms/interfaces/driver_platform_interface.py
@@ -1,9 +1,10 @@
"""Interface for drivers."""
import abc
from collections import namedtuple
from typing import Any
from typing import Any, TYPE_CHECKING

from mpf.core.platform import DriverConfig
if TYPE_CHECKING:
from mpf.core.platform import DriverConfig

PulseSettings = namedtuple("PulseSettings", ["power", "duration"])
HoldSettings = namedtuple("HoldSettings", ["power"])
Expand Down
3 changes: 3 additions & 0 deletions mpf/tests/machine_files/led/config/led.yaml
Expand Up @@ -8,6 +8,9 @@ light_settings:
linear_slope: 0.75
linear_cutoff: 0.1

named_colors:
jans_red: [251, 23, 42]

lights:
led1:
number: 1
Expand Down
8 changes: 8 additions & 0 deletions mpf/tests/test_DeviceLED.py
Expand Up @@ -119,6 +119,14 @@ def test_color_and_stack(self):
self.assertEqual(RGBColor('green'), led1.stack[2]['color'])
self.assertEqual(RGBColor('orange'), led1.stack[3]['color'])

def test_named_colors(self):
led1 = self.machine.lights.led1
led1.color('jans_red')
self.machine_run()

self.assertLightColor(led1.name, "jans_red")
self.assertLightColor(led1.name, [251, 23, 42])

def test_fades(self):
led1 = self.machine.lights.led1

Expand Down

0 comments on commit 5d3044b

Please sign in to comment.