1 """Kodi notification service."""
3 from __future__
import annotations
9 import voluptuous
as vol
15 PLATFORM_SCHEMA
as NOTIFY_PLATFORM_SCHEMA,
16 BaseNotificationService,
31 _LOGGER = logging.getLogger(__name__)
34 DEFAULT_PROXY_SSL =
False
37 PLATFORM_SCHEMA = NOTIFY_PLATFORM_SCHEMA.extend(
39 vol.Required(CONF_HOST): cv.string,
40 vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
41 vol.Optional(CONF_PROXY_SSL, default=DEFAULT_PROXY_SSL): cv.boolean,
42 vol.Inclusive(CONF_USERNAME,
"auth"): cv.string,
43 vol.Inclusive(CONF_PASSWORD,
"auth"): cv.string,
47 ATTR_DISPLAYTIME =
"displaytime"
53 discovery_info: DiscoveryInfoType |
None =
None,
54 ) -> KodiNotificationService:
55 """Return the notify service."""
56 username: str |
None = config.get(CONF_USERNAME)
57 password: str |
None = config.get(CONF_PASSWORD)
59 host: str = config[CONF_HOST]
60 port: int = config[CONF_PORT]
61 encryption = config.get(CONF_PROXY_SSL)
63 if host.startswith((
"http://",
"https://")):
64 host = host[host.index(
"://") + 3 :]
66 "Kodi host name should no longer contain http:// See updated "
68 "https://www.home-assistant.io/integrations/kodi/"
71 http_protocol =
"https" if encryption
else "http"
72 url = f
"{http_protocol}://{host}:{port}/jsonrpc"
74 if username
is not None and password
is not None:
75 auth = aiohttp.BasicAuth(username, password)
83 """Implement the notification service for Kodi."""
86 """Initialize the service."""
94 self.
_server_server = jsonrpc_async.Server(self.
_url_url, **kwargs)
97 """Send a message to Kodi."""
99 data = kwargs.get(ATTR_DATA)
or {}
101 displaytime =
int(data.get(ATTR_DISPLAYTIME, 10000))
102 icon = data.get(ATTR_ICON,
"info")
103 title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
104 await self.
_server_server.GUI.ShowNotification(title, message, icon, displaytime)
106 except jsonrpc_async.TransportError:
107 _LOGGER.warning(
"Unable to fetch Kodi data. Is Kodi online?")
def async_send_message(self, message="", **kwargs)
def __init__(self, hass, url, auth=None)
KodiNotificationService async_get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)