def test_eyes_color(self, mock_create_conn):
     # Create simple replacement websocket object and return it
     # when creating sockets
     mock_ws = MockWS()
     mock_create_conn.return_value = mock_ws
     # Test that init calls create_connection with correct param
     m = MycroftAPI('127.0.0.1')
     mock_create_conn.assert_called_with("ws://" + '127.0.0.1' +
                                         ":8181/core")
     # Check that message bus message looks like what we expect
     # Expected data to websocket
     r = 0
     g = 255
     b = 0
     mycroft_type = '"enclosure.eyes.color"'
     mycroft_data = '{"r": %s, "g": %s, "b": %s}, ' \
                    '"context": null' % (r, g, b)
     message = '{"type": ' + mycroft_type + \
               ', "data": ' + mycroft_data + '}'
     m.eyes_color(r, g, b)
     self.assertEqual(message, mock_ws.message)
class MycroftInstance(LightEntity):
    """Representation of a Mycrof instance."""

    def __init__(self, light):

        # Fixture configuration
        self._host = light.get(CONF_HOST)

        self._name = light.get(CONF_NAME)
        
        self._brightness = light.get(CONF_DEFAULT_LEVEL, 0)
        self._rgb = light.get(CONF_DEFAULT_COLOR, COLOR_MAP)

        # Brightness needs to be set to the maximum default RGB level, then
        # scale up the RGB values to what HA uses
        self._brightness = max(self._rgb) * (self._brightness/255)

        if self._brightness > 0:
            self._state = STATE_ON
        else:
            self._state = STATE_OFF

        # Create Mycroft API.
        self._mycroft = MycroftAPI(self._host)
        
        _LOGGER.debug(f"Intialized Mycroft {self._name}")
        
    @property
    def host(self):
        """Return the Mycroft host."""
        return self._host

    @property
    def name(self):
        """Return the display name of this Mycroft."""
        return self._name

    @property
    def brightness(self):
        """Return the brightness of Mycroft's eyes."""
        return self._brightness
    
    @property
    def rgb(self):
        """Return the RGB values of Mycroft's eyes."""
        return self._rgb

    @property
    def is_on(self):
        """Return true if light is on."""
        return self._state == STATE_ON

    @property
    def hs_color(self):
        """Return the HS color value."""
        if self._rgb:
            return color_util.color_RGB_to_hs(*self._rgb)
        else:
            return None

    @property
    def min_mireds(self):
        """Return the coldest color_temp that this light supports."""
        # Default to the Philips Hue value that HA has always assumed
        # https://developers.meethue.com/documentation/core-concepts
        return 192

    @property
    def max_mireds(self):
        """Return the warmest color_temp that this light supports."""
        # Default to the Philips Hue value that HA has always assumed
        # https://developers.meethue.com/documentation/core-concepts
        return 448

    @property
    def supported_features(self):
        """Flag supported features."""
        return (SUPPORT_BRIGHTNESS | SUPPORT_COLOR)

    @property
    def should_poll(self):
        return False

    @asyncio.coroutine
    def async_turn_on(self, **kwargs):
        """Instruct the light to turn on."""
        self._state = STATE_ON

        # Update state from service call
        if ATTR_BRIGHTNESS in kwargs:
            self._brightness = kwargs[ATTR_BRIGHTNESS]

        if self._brightness == 0:
            self._brightness = 255

        if ATTR_HS_COLOR in kwargs:
            self._rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])

        if self._mycroft is not None:
            self._mycroft.eyes_color(*scale_rgb_to_brightness(self._rgb, self._brightness))

        self.async_schedule_update_ha_state()
        
        _LOGGER.debug(f"Turned on Mycroft {self._name}")

    @asyncio.coroutine
    def async_turn_off(self, **kwargs):
        """Instruct the light to turn off."""
        self._state = STATE_OFF
        if self._mycroft is not None:
            self._mycroft.eyes_color(0, 0, 0)
        self.async_schedule_update_ha_state()
        _LOGGER.debug(f"Turned off Mycroft {self._name}")

    def update(self):
        """Fetch update state."""