Repository: missionpinball/mpf
Issue: BCP encoding problem with monitor

`WARNING : BCPClientSocket.None : Failed to encode bcp_command monitored_event with args {'event_kwargs': {}, 'event_name': 'mode_base_started', 'registered_handlers': [RegisteredHandler(callback=<bound method LedPlayer.config_play_callback of ConfigPlayer.leds>, priority=100, kwargs={'calling_context': 'mode_base_started', 'settings': {<led.gi_right_front_led_30>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_27>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_2>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_32>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_39>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_10>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_14>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_9>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_33>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_0>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_8>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_11>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_10>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_34>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_11>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_0>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_23>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_29>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_22>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_13>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_19>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_16>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_1>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_35>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_36>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_13>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_26>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_33>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_28>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_48>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_37>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_36>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_24>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_3>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_38>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_40>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_46>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_12>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_32>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_12>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_49>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_31>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_23>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_38>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_43>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_25>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_18>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_42>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_39>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_17>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_48>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_45>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_41>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_20>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_17>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_18>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_14>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_42>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_2>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_37>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_19>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_1>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_43>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_46>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_3>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_20>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_29>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_34>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_22>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_44>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_41>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_4>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_16>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_21>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_35>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_45>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_27>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_5>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_44>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_26>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_24>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_6>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_5>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_49>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_25>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_front_led_47>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_28>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_47>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_21>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_7>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_40>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_6>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_15>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_30>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_8>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_7>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_right_back_led_31>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_15>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_front_led_4>: {'priority': 0, 'color': 'white', 'fade_ms': None}, <led.gi_left_back_led_9>: {'priority': 0, 'color': 'white', 'fade_ms': None}}, 'mode': <Mode.base>}, key=UUID('5fe27869-aa86-4d53-9588-f404e4373c21'), condition=None), RegisteredHandler(callback=<bound method BcpInterface.bcp_trigger of <BCP Interface>>, priority=1, kwargs={'name': 'mode_base_started'}, key=UUID('3b467fa7-c870-4b01-b4cc-dad31ae0c79c'), condition=None)], 'event_callback': <bound method Mode._mode_started_callback of <Mode.base>>, 'event_type': None}. keys must be a string`

Changed files:
mpf/core/bcp/bcp_interface.py, mpf/tests/test_BcpInterface.py, mpf/core/utility_functions.py

diff --git a/mpf/core/bcp/bcp_interface.py b/mpf/core/bcp/bcp_interface.py
index 4a3d45cf2..a7c7fecc6 100644
--- a/mpf/core/bcp/bcp_interface.py
+++ b/mpf/core/bcp/bcp_interface.py
@@ -166,8 +166,8 @@ class BcpInterface(object):
         self.machine.bcp.transport.add_handler_to_transport("_machine_vars", client)
 
     def _send_machine_vars(self, client):
-        self.machine.bcp.transport.send_to_client(client, bcp_command='settings',
-                                                  settings=self.machine.settings.get_settings())
+        self.machine.bcp.transport.send_to_client(
+            client, bcp_command='settings', settings=Util.convert_to_simply_type(self.machine.settings.get_settings()))
         for var_name, settings in self.machine.machine_vars.items():
             self.machine.bcp.transport.send_to_client(client, bcp_command='machine_variable',
                                                       name=var_name,
diff --git a/mpf/core/utility_functions.py b/mpf/core/utility_functions.py
index 43e179d93..8125485b8 100644
--- a/mpf/core/utility_functions.py
+++ b/mpf/core/utility_functions.py
@@ -17,7 +17,9 @@ class Util(object):
     def convert_to_simply_type(value):
         """Convert value to a simple type."""
         # keep simple types
-        if isinstance(value, (int, str, float)):
+        if value is None:
+            return None
+        elif isinstance(value, (int, str, float)):
             return value
 
         # for list repeat per entry
@@ -33,7 +35,7 @@ class Util(object):
 
         elif isinstance(value, tuple):
             # pylint: disable-msg=protected-access
-            return value
+            return tuple(Util.convert_to_simply_type(x) for x in value)
 
         # otherwise just cast to string
         return str(value)
diff --git a/mpf/tests/test_BcpInterface.py b/mpf/tests/test_BcpInterface.py
index 3abfa2083..138da41bb 100644
--- a/mpf/tests/test_BcpInterface.py
+++ b/mpf/tests/test_BcpInterface.py
@@ -1,8 +1,8 @@
 """Test the bcp interface."""
 from unittest import mock
 
-from mpf.tests.MpfBcpTestCase import MpfBcpTestCase
 from mpf.core.events import RegisteredHandler
+from mpf.tests.MpfBcpTestCase import MpfBcpTestCase
 
 
 class CallHandler:
@@ -53,7 +53,7 @@ class TestBcpInterface(MpfBcpTestCase):
         self.assertIn(
             ('monitored_event', dict(event_name='test2', event_type=None,
                                      event_callback=None, event_kwargs={},
-                                     registered_handlers=[RegisteredHandler(callback=handler, priority=1, kwargs={}, key='abc', condition=None)])),
+                                     registered_handlers=[RegisteredHandler(callback='handler', priority=1, kwargs={}, key='abc', condition=None)])),
             self._bcp_client.send_queue)
 
         self._bcp_client.send_queue.clear()