Skip to content

Commit

Permalink
Merge branch 'dev' into refactor-displays
Browse files Browse the repository at this point in the history
  • Loading branch information
qcapen committed Jun 8, 2017
2 parents 7cf5912 + 77043cf commit d5faea7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
18 changes: 9 additions & 9 deletions mpf/core/logging.py
Expand Up @@ -8,16 +8,16 @@ class LogMixin(object):

unit_test = False

def __init__(self):
def __init__(self) -> None:
"""Initialise Log Mixin."""
self.log = None
self._info_to_console = False
self._debug_to_console = False
self._info_to_file = False
self._debug_to_file = False

def configure_logging(self, logger, console_level='basic',
file_level='basic'):
def configure_logging(self, logger: str, console_level: str='basic',
file_level: str='basic'):
"""Configure logging.
Args:
Expand Down Expand Up @@ -49,7 +49,7 @@ def configure_logging(self, logger, console_level='basic',
if self.unit_test:
self._info_to_console = True

def debug_log(self, msg: str, *args, **kwargs):
def debug_log(self, msg: str, *args, **kwargs) -> None:
"""Log a message at the debug level.
Note that whether this message shows up in the console or log file is
Expand All @@ -63,7 +63,7 @@ def debug_log(self, msg: str, *args, **kwargs):
elif self._debug_to_file:
self.log.log(11, msg, *args, **kwargs)

def info_log(self, msg: str, *args, **kwargs):
def info_log(self, msg: str, *args, **kwargs) -> None:
"""Log a message at the info level.
Whether this message shows up in the console or log file is controlled
Expand All @@ -77,7 +77,7 @@ def info_log(self, msg: str, *args, **kwargs):
elif self._info_to_file or self._debug_to_file:
self.log.log(11, msg, *args, **kwargs)

def warning_log(self, msg: str, *args, **kwargs):
def warning_log(self, msg: str, *args, **kwargs) -> None:
"""Log a message at the warning level.
These messages will always be shown in the console and the log file.
Expand All @@ -87,7 +87,7 @@ def warning_log(self, msg: str, *args, **kwargs):

self.log.log(30, 'WARNING: {}'.format(msg), *args, **kwargs)

def error_log(self, msg, *args, **kwargs):
def error_log(self, msg: str, *args, **kwargs) -> None:
"""Log a message at the error level.
These messages will always be shown in the console and the log file.
Expand All @@ -97,7 +97,7 @@ def error_log(self, msg, *args, **kwargs):

self.log.log(40, 'ERROR: {}'.format(msg), *args, **kwargs)

def ignorable_runtime_exception(self, msg):
def ignorable_runtime_exception(self, msg: str) -> None:
"""Handle ignorable runtime exception.
During development or tests raise an exception for easier debugging. Log an error during production.
Expand All @@ -107,7 +107,7 @@ def ignorable_runtime_exception(self, msg):
else:
self.error_log(msg)

def _logging_not_configured(self):
def _logging_not_configured(self) -> None:
raise RuntimeError(
"Logging has not been configured for the {} module. You must call "
"configure_logging() before you can post a log message".
Expand Down
11 changes: 6 additions & 5 deletions mpf/core/platform.py
Expand Up @@ -5,10 +5,11 @@

from typing import Optional, TYPE_CHECKING

from mpf.platforms.interfaces.light_platform_interface import LightPlatformInterface

if TYPE_CHECKING: # pragma: no cover
from mpf.devices.switch import Switch
from mpf.platforms.interfaces.driver_platform_interface import DriverPlatformInterface
from mpf.platforms.interfaces.switch_platform_interface import SwitchPlatformInterface
from mpf.platforms.interfaces.light_platform_interface import LightPlatformInterface


class BasePlatform(metaclass=abc.ABCMeta):
Expand Down Expand Up @@ -223,7 +224,7 @@ def light_sync(self):
pass

@abc.abstractmethod
def configure_light(self, number, subtype, platform_settings) -> LightPlatformInterface:
def configure_light(self, number: str, subtype: str, platform_settings: dict) -> "LightPlatformInterface":
"""Subclass this method in a platform module to configure a light.
This method should return a reference to the light
Expand All @@ -245,7 +246,7 @@ def __init__(self, machine):
self.features['has_switches'] = True

@abc.abstractmethod
def configure_switch(self, number: str, config: SwitchConfig, platform_config: dict):
def configure_switch(self, number: str, config: SwitchConfig, platform_config: dict) -> "SwitchPlatformInterface":
"""Subclass this method in a platform module to configure a switch.
This method should return a reference to the switch's platform interface
Expand Down Expand Up @@ -317,7 +318,7 @@ def __init__(self, machine):
self.features['max_pulse'] = 255

@abc.abstractmethod
def configure_driver(self, config: DriverConfig, number: str, platform_settings: dict):
def configure_driver(self, config: DriverConfig, number: str, platform_settings: dict) -> "DriverPlatformInterface":
"""Subclass this method in a platform module to configure a driver.
This method should return a reference to the driver's platform interface
Expand Down
2 changes: 2 additions & 0 deletions mpf/platforms/interfaces/light_platform_interface.py
Expand Up @@ -10,6 +10,7 @@ class LightPlatformInterface(metaclass=abc.ABCMeta):

"""Interface for a light in hardware platforms."""

@abc.abstractmethod
def set_fade(self, color_and_fade_callback: Callable[[int], Tuple[float, int]]):
"""Perform a fade to a brightness.
Expand Down Expand Up @@ -96,6 +97,7 @@ def set_brightness_and_fade(self, brightness: float, fade_ms: int):
assert fade_ms == 0
self.set_brightness(brightness)

@abc.abstractmethod
def set_brightness(self, brightness: float):
"""Set the light to the specified brightness.
Expand Down
7 changes: 4 additions & 3 deletions mpf/platforms/interfaces/switch_platform_interface.py
@@ -1,8 +1,9 @@
"""Interface for switches."""
import abc
from typing import Any
from typing import Any, TYPE_CHECKING

from mpf.core.platform import SwitchConfig
if TYPE_CHECKING: # pragma: no cover
from mpf.core.platform import SwitchConfig


class SwitchPlatformInterface(metaclass=abc.ABCMeta):
Expand All @@ -14,7 +15,7 @@ class SwitchPlatformInterface(metaclass=abc.ABCMeta):
methods are implemented to support switch operations in MPF.
"""

def __init__(self, config: SwitchConfig, number: Any) -> None:
def __init__(self, config: "SwitchConfig", number: Any) -> None:
"""Initialise default attributes for switches."""
self.config = config
self.number = number

0 comments on commit d5faea7

Please sign in to comment.