Skip to content

Commit

Permalink
Fix async calls from worker thread. Other minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
PhracturedBlue committed Sep 17, 2018
1 parent fc359dd commit 31b0f97
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions homeassistant/components/asterisk_mbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import (
async_dispatcher_connect, async_dispatcher_send)
async_dispatcher_send, dispatcher_connect)

REQUIREMENTS = ['asterisk_mbox==0.5.0']

Expand Down Expand Up @@ -55,19 +55,19 @@ class AsteriskData:
def __init__(self, hass, host, port, password, config):
"""Init the Asterisk data object."""
from asterisk_mbox import Client as asteriskClient

self.hass = hass
self.config = config
self.client = asteriskClient(host, port, password, self.handle_data)
self.messages = None
self.cdr = None

async_dispatcher_connect(
dispatcher_connect(
self.hass, SIGNAL_MESSAGE_REQUEST, self._request_messages)
async_dispatcher_connect(
dispatcher_connect(
self.hass, SIGNAL_CDR_REQUEST, self._request_cdr)
async_dispatcher_connect(
dispatcher_connect(
self.hass, SIGNAL_DISCOVER_PLATFORM, self._discover_platform)
# Only connect after signal connection to ensure we don't miss any
self.client = asteriskClient(host, port, password, self.handle_data)

@callback
def _discover_platform(self, component):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/mailbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def async_setup_platform(p_type, p_config=None, discovery_info=None):
mailbox = await \
platform.async_get_handler(hass, p_config, discovery_info)
elif hasattr(platform, 'get_handler'):
mailbox = await hass.async_add_job(
mailbox = await hass.async_add_executor_job(
platform.get_handler, hass, p_config, discovery_info)
else:
raise HomeAssistantError("Invalid mailbox platform.")
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/mailbox/asterisk_cdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
Asterisk CDR interface.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/mailbox.asteriskvm/
https://home-assistant.io/components/mailbox.asterisk_cdr/
"""
import logging
import hashlib
import datetime

from homeassistant.core import callback
from homeassistant.components.asterisk_mbox import SIGNAL_CDR_UPDATE
from homeassistant.components.asterisk_mbox import DOMAIN
from homeassistant.components.asterisk_mbox import DOMAIN as ASTERISK_DOMAIN
from homeassistant.components.mailbox import Mailbox
from homeassistant.helpers.dispatcher import async_dispatcher_connect

Expand Down Expand Up @@ -43,7 +43,7 @@ def _update_callback(self, msg):
def _build_message(self):
"""Build message structure."""
cdr = []
for entry in self.hass.data[DOMAIN].cdr:
for entry in self.hass.data[ASTERISK_DOMAIN].cdr:
timestamp = datetime.datetime.strptime(
entry['time'], "%Y-%m-%d %H:%M:%S").timestamp()
info = {
Expand Down

0 comments on commit 31b0f97

Please sign in to comment.