Skip to content

Commit

Permalink
small code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdoa2 committed Mar 6, 2017
1 parent bde4f19 commit f391c90
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
9 changes: 5 additions & 4 deletions mpf/core/light_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ def __init__(self, machine):
"""Initialise lights controller."""
super().__init__(machine)

# Generate and add color correction profiles to the machine
self.light_color_correction_profiles = dict()

self.lights_to_update = set()
self._initialised = False
self._updater_task = None

def initialise_light_subsystem(self):
"""Initialise the light subsystem."""
Expand All @@ -28,9 +32,6 @@ def initialise_light_subsystem(self):
self.machine.config['light_settings']['color_correction_profiles'] = (
dict())

# Generate and add color correction profiles to the machine
self.light_color_correction_profiles = dict()

# Create the default color correction profile and add it to the machine
default_profile = RGBColorCorrectionProfile.default()
self.light_color_correction_profiles['default'] = default_profile
Expand Down Expand Up @@ -78,4 +79,4 @@ def _update_lights(self, dt):
light.write_color_to_hw_driver()
if light.fade_in_progress:
new_lights_to_update.add(light)
self.lights_to_update = new_lights_to_update
self.lights_to_update = new_lights_to_update
10 changes: 4 additions & 6 deletions mpf/core/platform.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Contains the parent class for all platforms."""
import abc

from typing import Optional

from mpf.devices.switch import Switch
from mpf.platforms.interfaces.light_platform_interface import LightPlatformInterface

Expand Down Expand Up @@ -214,10 +216,6 @@ def configure_light(self, number, subtype, platform_settings) -> LightPlatformIn
This method should return a reference to the light
object which will be called to access the hardware.
Args:
config (dict): Config of light.
"""
raise NotImplementedError

Expand Down Expand Up @@ -245,7 +243,7 @@ def configure_switch(self, config):
raise NotImplementedError

@classmethod
def get_switch_config_section(cls):
def get_switch_config_section(cls) -> Optional[str]:
"""Return config section for additional switch config items."""
return None

Expand Down Expand Up @@ -340,7 +338,7 @@ def clear_hw_rule(self, switch, coil):
raise NotImplementedError

@classmethod
def get_coil_config_section(cls):
def get_coil_config_section(cls) -> Optional[str]:
"""Return addition config section for coils."""
return None

Expand Down
8 changes: 3 additions & 5 deletions mpf/devices/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
from operator import itemgetter

from mpf.core.device_monitor import DeviceMonitor
from mpf.core.machine import MachineController
from mpf.core.rgb_color import RGBColor
from mpf.core.rgb_color import RGBColorCorrectionProfile
from mpf.core.settings_controller import SettingEntry
from mpf.core.system_wide_device import SystemWideDevice
from mpf.devices.driver import ReconfiguredDriver
from mpf.platforms.interfaces.light_platform_interface import LightPlatformInterface
Expand Down Expand Up @@ -414,8 +411,6 @@ def get_color(self):
self.debug_log("Fade, ratio: %s", ratio)

if ratio >= 1.0: # fade is done
self.fade_in_progress = False
color_settings['dest_time'] = 0
return color_settings['dest_color']
else:
return RGBColor.blend(color_settings['start_color'], color_settings['dest_color'], ratio)
Expand All @@ -429,6 +424,9 @@ def write_color_to_hw_driver(self):
This method is automatically called whenever a color change has been
made (including when fades are active).
"""
if self.fade_in_progress and self.stack and self.stack[0]['dest_time'] < self.machine.clock.get_time():
self.fade_in_progress = False

color = self.get_color()
corrected_color = self.gamma_correct(color)
corrected_color = self.color_correct(corrected_color)
Expand Down
4 changes: 4 additions & 0 deletions mpf/platforms/interfaces/light_platform_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def get_max_fade_ms(self):
"""Return maximum fade_ms for this light."""
return 0

def mark_dirty(self):
"""Mark light dirty."""
return

@abc.abstractmethod
def set_brightness(self, brightness: float, fade_ms: int):
"""Set the light to the specified brightness.
Expand Down
1 change: 0 additions & 1 deletion mpf/tests/test_DeviceLED.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ def test_fades(self):
self.assertFalse(led1.fade_in_progress)
self.assertEqual(color_setting['priority'], 0)
self.assertEqual(color_setting['start_color'], RGBColor('off'))
self.assertEqual(color_setting['dest_time'], 0)
self.assertEqual(color_setting['dest_color'], RGBColor('red'))
self.assertEqual(led1.get_color(), RGBColor('red'))
self.assertIsNone(color_setting['key'])
Expand Down

0 comments on commit f391c90

Please sign in to comment.