Home Assistant Unofficial Reference 2024.12.1
notify.py
Go to the documentation of this file.
1 """Mycroft AI notification platform."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from mycroftapi import MycroftAPI
8 
9 from homeassistant.components.notify import BaseNotificationService
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
12 
13 _LOGGER = logging.getLogger(__name__)
14 
15 
17  hass: HomeAssistant,
18  config: ConfigType,
19  discovery_info: DiscoveryInfoType | None = None,
20 ) -> MycroftNotificationService:
21  """Get the Mycroft notification service."""
22  return MycroftNotificationService(hass.data["mycroft"])
23 
24 
25 class MycroftNotificationService(BaseNotificationService):
26  """The Mycroft Notification Service."""
27 
28  def __init__(self, mycroft_ip):
29  """Initialize the service."""
30  self.mycroft_ipmycroft_ip = mycroft_ip
31 
32  def send_message(self, message="", **kwargs):
33  """Send a message mycroft to speak on instance."""
34 
35  text = message
36  mycroft = MycroftAPI(self.mycroft_ipmycroft_ip)
37  if mycroft is not None:
38  mycroft.speak_text(text)
39  else:
40  _LOGGER.log("Could not reach this instance of mycroft")
MycroftNotificationService get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)
Definition: notify.py:20