8000 Adding service for logbook by kennedyshead · Pull Request #1020 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adding service for logbook #1020

New issue 8000

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion homeassistant/components/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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
Expand All @@ -17,6 +18,7 @@
import homeassistant.util.dt as dt_util
from homeassistant.components import recorder, sun
from homeassistant.helpers.entity import split_entity_id
from homeassistant.util import template

DOMAIN = "logbook"
DEPENDENCIES = ['recorder', 'http']
Expand All @@ -27,6 +29,8 @@
SELECT * FROM events WHERE time_fired > ? AND time_fired < ?
"""

_LOGGER = logging.getLogger(__name__)

EVENT_LOGBOOK_ENTRY = 'logbook_entry'

GROUP_BY_MINUTES = 15
Expand All @@ -53,8 +57,22 @@ 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 log_message(service):
""" Handle sending notification message service calls. """
message = service.data.get(ATTR_MESSAGE)
name = service.data.get(ATTR_NAME)
domain = service.data.get(ATTR_DOMAIN, None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None is the default return value if not passed in.

entity_id = service.data.get(ATTR_ENTITY_ID, None)

if not message or not name:
return

message = template.render(hass, message)
log_entry(hass, name, message, domain, entity_id)

hass.http.register_path('GET', URL_LOGBOOK, _handle_get_logbook)
hass.services.register(DOMAIN, 'log', log_message)
return True


Expand Down
0