1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00
ha-core/homeassistant/components/circuit/notify.py
2020-05-25 15:51:41 +02:00

38 lines
1.1 KiB
Python

"""Unify Circuit platform for notify component."""
import logging
from circuit_webhook import Circuit
from homeassistant.components.notify import BaseNotificationService
from homeassistant.const import CONF_URL
_LOGGER = logging.getLogger(__name__)
def get_service(hass, config, discovery_info=None):
"""Get the Unify Circuit notification service."""
if discovery_info is None:
return None
return CircuitNotificationService(discovery_info)
class CircuitNotificationService(BaseNotificationService):
"""Implement the notification service for Unify Circuit."""
def __init__(self, config):
"""Initialize the service."""
self.webhook_url = config[CONF_URL]
def send_message(self, message=None, **kwargs):
"""Send a message to the webhook."""
webhook_url = self.webhook_url
if webhook_url and message:
try:
circuit_message = Circuit(url=webhook_url)
circuit_message.post(text=message)
except RuntimeError as err:
_LOGGER.error("Could not send notification. Error: %s", err)