mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Added a command line notification platform that could be used for all kind of custom notifications
This commit is contained in:
parent
70a528c04b
commit
9521dad263
46
homeassistant/components/notify/command_line.py
Normal file
46
homeassistant/components/notify/command_line.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
"""
|
||||||
|
homeassistant.components.notify.command_line
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
command_line notification service.
|
||||||
|
|
||||||
|
For more details about this platform, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/notify.command_line/
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
import subprocess
|
||||||
|
import shlex
|
||||||
|
from homeassistant.helpers import validate_config
|
||||||
|
from homeassistant.components.notify import (
|
||||||
|
DOMAIN, BaseNotificationService)
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def get_service(hass, config):
|
||||||
|
""" Get the Command Line notification service. """
|
||||||
|
|
||||||
|
if not validate_config({DOMAIN: config},
|
||||||
|
{DOMAIN: ['command']},
|
||||||
|
_LOGGER):
|
||||||
|
return None
|
||||||
|
|
||||||
|
command = config['command']
|
||||||
|
|
||||||
|
return CommandLineNotificationService(command)
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
|
class CommandLineNotificationService(BaseNotificationService):
|
||||||
|
""" Implements notification service for the Command Line service. """
|
||||||
|
|
||||||
|
def __init__(self, command):
|
||||||
|
self.command = command
|
||||||
|
|
||||||
|
def send_message(self, message="", **kwargs):
|
||||||
|
""" Send a message to a command_line. """
|
||||||
|
try:
|
||||||
|
subprocess.call("{} \"{}\"".format(self.command,
|
||||||
|
shlex.quote(message)),
|
||||||
|
shell=True)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
_LOGGER.error('Command failed: %s', self.command)
|
Loading…
x
Reference in New Issue
Block a user