コード例 #1
0
ファイル: notify.py プロジェクト: OpenPeerPower/core
    def send_message(self, message="", **kwargs):
        """Send a message mycroft to speak on instance."""

        text = message
        mycroft = MycroftAPI(self.mycroft_ip)
        if mycroft is not None:
            mycroft.speak_text(text)
        else:
            _LOGGER.log("Could not reach this instance of mycroft")
コード例 #2
0
ファイル: notify.py プロジェクト: fbradyirl/home-assistant
    def send_message(self, message="", **kwargs):
        """Send a message mycroft to speak on instance."""
        from mycroftapi import MycroftAPI

        text = message
        mycroft = MycroftAPI(self.mycroft_ip)
        if mycroft is not None:
            mycroft.speak_text(text)
        else:
            _LOGGER.log("Could not reach this instance of mycroft")
コード例 #3
0
 def test_squint_eyes(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
     mycroft_type = '"enclosure.eyes.narrow"'
     message = '{"type": ' + mycroft_type + '}'
     m.squint_eyes()
     self.assertEqual(message, mock_ws.message)
コード例 #4
0
 def test_eyes_look(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
     side = "u"
     mycroft_type = '"enclosure.eyes.look"'
     mycroft_data = '{"side": "%s"}, ' \
                    '"context": null' % side
     message = '{"type": ' + mycroft_type + \
               ', "data": ' + mycroft_data + '}'
     m.eyes_look(side)
     self.assertEqual(message, mock_ws.message)
コード例 #5
0
 def test_ws_connection(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
     text = 'hello brian'
     # Expected data to websocket
     mycroft_speak = ('"{}"'.format(text))
     mycroft_type = '"speak"'
     mycroft_data = '{"expect_response": false, "utterance": %s}, ' \
                    '"context": null' % mycroft_speak
     message = '{"type": ' + mycroft_type + \
               ', "data": ' + mycroft_data + '}'
     m.speak_text(text)
     self.assertEqual(message, mock_ws.message)
コード例 #6
0
    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}")
コード例 #7
0
 def test_os_error(self):
     self.assertRaises(OSError, MycroftAPI.__init__(self, mycroft_ip='1.1'))
コード例 #8
0
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."""