Logbook service
parent
c750f16275
commit
c31522eea9
|
@ -6,9 +6,11 @@ Parses events and generates a human log.
|
|||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/logbook/
|
||||
"""
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
from itertools import groupby
|
||||
import re
|
||||
from functools import partial
|
||||
|
||||
from homeassistant.core import State, DOMAIN as HA_DOMAIN
|
||||
from homeassistant.const import (
|
||||
|
@ -36,6 +38,22 @@ ATTR_MESSAGE = 'message'
|
|||
ATTR_DOMAIN = 'domain'
|
||||
ATTR_ENTITY_ID = 'entity_id'
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class LogbookService(object):
|
||||
""" Implements logging service for Logbook. """
|
||||
|
||||
def __init__(self, hass, name):
|
||||
self.hass = hass
|
||||
self.name = name
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
""" Adds an entry to the logbook. """
|
||||
_LOGGER.error("IM HERE")
|
||||
log_entry(self.hass, self.name, message, DOMAIN)
|
||||
|
||||
|
||||
def log_entry(hass, name, message, domain=None, entity_id=None):
|
||||
""" Adds an entry to the logbook. """
|
||||
|
@ -53,8 +71,19 @@ def log_entry(hass, name, message, domain=None, entity_id=None):
|
|||
|
||||
def setup(hass, config):
|
||||
""" Listens for download events to download files. """
|
||||
hass.http.register_path('GET', URL_LOGBOOK, _handle_get_logbook)
|
||||
# create service handler
|
||||
def notify_message(notify_service, call):
|
||||
""" Handle sending notification message service calls. """
|
||||
message = call.data.get(ATTR_MESSAGE)
|
||||
|
||||
if message is None:
|
||||
return
|
||||
|
||||
notify_service.send_message(message)
|
||||
|
||||
service = LogbookService(hass, config.get(ATTR_NAME, None))
|
||||
hass.http.register_path('GET', URL_LOGBOOK, _handle_get_logbook)
|
||||
hass.services.register(DOMAIN, DOMAIN, partial(notify_message, service))
|
||||
return True
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue