From bd039b8c5332e9225ef2bd8291c9fd12309bebd9 Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Sun, 27 Aug 2017 16:53:20 -0400 Subject: [PATCH] Mycroft notify/component (#9173) * working mycroft notification platform * Update mycroft.py * Update mycroft.py * Update mycroft.py * Update mycroft.py * updating to use new api updating code to use new api. * updating changes updating files * updating typos fixing some typos * Update mycroft.py adding text * fixing pep issues fixing pep issues * adding new mycroft component adding mycroft component * updating updating code * updating typo fixing typo * updating file adding updates * updating notify updating notify component for new changes * Update mycroft.py * Update mycroft.py * Update mycroft.py * updating for tox updating to pass tox tests * updating for tox fixing tox errors * fixing tox issues fixing tox issues * fixing tox issues fixing more tox issues * updating requirement adding requirement for component * fixed typo fixed typo * updating requirements updating requirements * updating code updating code * updating files updating * updating * adding logging adding in logging * fixing typo fixing typo * updating debugs * updating files updating files * updating dependencies updating dependencies * updating to load notification updating to load notification * cleaning up whitespace * updating requirements_all.txt * adding requirement adding requirement * Update mycroft.py * Update .coveragerc updated .coveragerc --- .coveragerc | 2 ++ homeassistant/components/mycroft.py | 35 +++++++++++++++++++ homeassistant/components/notify/mycroft.py | 40 ++++++++++++++++++++++ requirements_all.txt | 3 ++ 4 files changed, 80 insertions(+) create mode 100644 homeassistant/components/mycroft.py create mode 100644 homeassistant/components/notify/mycroft.py diff --git a/.coveragerc b/.coveragerc index 9a03544c1bb..93a422d6d5b 100644 --- a/.coveragerc +++ b/.coveragerc @@ -381,6 +381,7 @@ omit = homeassistant/components/media_player/vlc.py homeassistant/components/media_player/volumio.py homeassistant/components/media_player/yamaha.py + homeassistant/components/mycroft.py homeassistant/components/notify/aws_lambda.py homeassistant/components/notify/aws_sns.py homeassistant/components/notify/aws_sqs.py @@ -398,6 +399,7 @@ omit = homeassistant/components/notify/llamalab_automate.py homeassistant/components/notify/matrix.py homeassistant/components/notify/message_bird.py + homeassistant/components/notify/mycroft.py homeassistant/components/notify/nfandroidtv.py homeassistant/components/notify/nma.py homeassistant/components/notify/prowl.py diff --git a/homeassistant/components/mycroft.py b/homeassistant/components/mycroft.py new file mode 100644 index 00000000000..c8179c280c8 --- /dev/null +++ b/homeassistant/components/mycroft.py @@ -0,0 +1,35 @@ +""" +Support for Mycroft AI. + +For more details about this component, please refer to the documentation at +https://home-assistant.io/components/mycroft +""" + +import logging + +import voluptuous as vol + +from homeassistant.const import CONF_HOST +from homeassistant.helpers import discovery +import homeassistant.helpers.config_validation as cv + +REQUIREMENTS = ['mycroftapi==0.1.2'] + +_LOGGER = logging.getLogger(__name__) + + +DOMAIN = 'mycroft' + + +CONFIG_SCHEMA = vol.Schema({ + DOMAIN: vol.Schema({ + vol.Required(CONF_HOST): cv.string + }) +}, extra=vol.ALLOW_EXTRA) + + +def setup(hass, config): + """Set up the Mycroft component.""" + hass.data[DOMAIN] = config[DOMAIN][CONF_HOST] + discovery.load_platform(hass, 'notify', DOMAIN, {}, config) + return True diff --git a/homeassistant/components/notify/mycroft.py b/homeassistant/components/notify/mycroft.py new file mode 100644 index 00000000000..1fd22c5c42b --- /dev/null +++ b/homeassistant/components/notify/mycroft.py @@ -0,0 +1,40 @@ +""" +Mycroft AI notification platform. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/notify.mycroft/ +""" +import logging + + +from homeassistant.components.notify import BaseNotificationService + +DEPENDENCIES = ['mycroft'] + + +_LOGGER = logging.getLogger(__name__) + + +def get_service(hass, config, discovery_info=None): + """Get the Mycroft notification service.""" + return MycroftNotificationService( + hass.data['mycroft']) + + +class MycroftNotificationService(BaseNotificationService): + """The Mycroft Notification Service.""" + + def __init__(self, mycroft_ip): + """Initialize the service.""" + self.mycroft_ip = mycroft_ip + + 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") diff --git a/requirements_all.txt b/requirements_all.txt index 883e2cf9e43..f054e9beb85 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -415,6 +415,9 @@ miniupnpc==1.9 # homeassistant.components.tts mutagen==1.38 +# homeassistant.components.mycroft +mycroftapi==0.1.2 + # homeassistant.components.usps myusps==1.1.3