Skip to content

Commit

Permalink
Various Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
girlpunk authored Sep 4, 2018
1 parent f110583 commit ad16409
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions asterisk_ami.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
"""Astisk Component"""

import logging

import asterisk.manager
import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_USERNAME, CONF_PASSWORD
from homeassistant.const import (CONF_HOST, CONF_PASSWORD, CONF_PORT,
CONF_USERNAME)
from homeassistant.helpers.discovery import load_platform

DEFAULT_HOST = "127.0.0.1"
DEFAULT_PORT = 5038
DEFAULT_USERNAME = "manager"
DEFAULT_PASSWORD = "manager"
CONF_MONITOR = "monitor"
CONF_MAILBOX = "mailboxes"

DOMAIN = "asterisk_ami"
REQUIREMENTS = ['pyst2==0.5.0']
DATA_ASTERISK = 'asterisk'
DATA_MONITOR = 'asterisk-monitor'
DATA_MAILBOX = 'asterisk-mailbox'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_PORT): cv.port,
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_MONITOR): cv.ensure_list,
vol.Optional(CONF_MAILBOX): cv.ensure_list
})
}, extra=vol.ALLOW_EXTRA)

_LOGGER = logging.getLogger(__name__)
manager = asterisk.manager.Manager()


def setup(hass, config):
"""Your controller/hub specific code."""

import asterisk.manager
manager = asterisk.manager.Manager()

host = config[DOMAIN].get(CONF_HOST, DEFAULT_HOST)
port = config[DOMAIN].get(CONF_PORT, DEFAULT_PORT)
username = config[DOMAIN].get(CONF_USERNAME, DEFAULT_USERNAME)
Expand All @@ -41,15 +48,16 @@ def setup(hass, config):
try:
manager.connect(host, port)
login_status = manager.login(username=username, secret=password).get_header("Response")
except asterisk.manager.ManagerException as e:
_LOGGER.error("Error connecting to Asterisk: %s", e.args[1])
except asterisk.manager.ManagerException as exception:
_LOGGER.error("Error connecting to Asterisk: %s", exception.args[1])
return False

if "Success" not in login_status:
_LOGGER.error("Could not authenticate: %s", login_status)

hass.data[DATA_ASTERISK] = manager
hass.data[DATA_MONITOR] = config[DOMAIN].get(CONF_MONITOR, [])
hass.data[DATA_MAILBOX] = config[DOMAIN].get(CONF_MAILBOX, [])

load_platform(hass, 'sensor', DOMAIN)

Expand Down

0 comments on commit ad16409

Please sign in to comment.