Skip to content
New issue

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

Add Call Data Log platform. Mailboxes no longer require media #16579

Merged
merged 12 commits into from Sep 21, 2018

Conversation

PhracturedBlue
Copy link
Contributor

@PhracturedBlue PhracturedBlue commented Sep 12, 2018

Description:

This patch adds the asterisk_cdr mailbox platform to view call activity. It also makes it possible to dynamically create mailbox platforms (needed in case CDR isn't supplied by the server). Additionally, mailboxes without media are now supported, as are read-only messages, making the mailbox platform more generic. Lastly all asycio.coroutines have been migrated to async/await.
This pull request requires a matching frontend change

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#6264
Pull request in home-assistant-polymer for frontend updates: home-assistant/frontend#1660

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New files were added to .coveragerc.

@@ -21,8 +20,7 @@
SIGNAL_MESSAGE_UPDATE = 'asterisk_mbox.message_updated'


@asyncio.coroutine
def async_get_handler(hass, config, async_add_entities, discovery_info=None):
async def async_get_handler(hass, config, async_add_entities, discovery_info=None):

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

DOMAIN = "asterisk_cdr"


async def async_get_handler(hass, config, async_add_devices, discovery_info=None):

Choose a reason for hiding this comment

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

line too long (82 > 79 characters)


DEPENDENCIES = ['asterisk_mbox']
_LOGGER = logging.getLogger(__name__)
DOMAIN = "asterisk_cdr"
Copy link
Member

Choose a reason for hiding this comment

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

Please don't call it DOMAIN as platforms don't have domains.

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

Ok to merge when variable renamed.

@PhracturedBlue
Copy link
Contributor Author

Thanks, should be better now


async_dispatcher_connect(
self.hass, SIGNAL_MESSAGE_REQUEST, self._request_messages)
async_dispatcher_connect(
Copy link
Member

Choose a reason for hiding this comment

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

This must be called from within the event loop but it's called from setup ie from a worker thread. Change to use the sync version.

platform.async_get_handler(hass, p_config, discovery_info)
elif hasattr(platform, 'get_handler'):
mailbox = yield from hass.async_add_job(
mailbox = await hass.async_add_job(
Copy link
Member

Choose a reason for hiding this comment

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

Use hass.async_add_executor_job.

Asterisk CDR interface.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/mailbox.asteriskvm/
Copy link
Member

Choose a reason for hiding this comment

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

The url is wrong.


from homeassistant.core import callback
from homeassistant.components.asterisk_mbox import SIGNAL_CDR_UPDATE
from homeassistant.components.asterisk_mbox import DOMAIN
Copy link
Member

Choose a reason for hiding this comment

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

This platform belongs to the mailbox domain. Import the asterix_mbox domain as another name.

from homeassistant.components.asterisk_mbox import DOMAIN as ASTERIX_MBOX_DOMAIN

@PhracturedBlue
Copy link
Contributor Author

@MartinHjelmare Thanks for the review. Moving those async calls to sync uncovered a real race condition. Is there any way to detect async calls made from the wrong thread to help prevent these types of errors?

I believe I have resolved all of your concerns.

@@ -4,7 +4,6 @@
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/mailbox.asteriskvm/
"""
import asyncio
import logging

from homeassistant.components.asterisk_mbox import DOMAIN
Copy link
Member

Choose a reason for hiding this comment

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

Please import this as another name too.

@@ -18,8 +17,7 @@
DOMAIN = "DemoMailbox"
Copy link
Member

Choose a reason for hiding this comment

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

Please rename the constant. The string is ok.

@MartinHjelmare
Copy link
Member

Not sure how to debug that.

Maybe by timing callbacks?

https://pymotw.com/3/asyncio/debugging.html

@PhracturedBlue
Copy link
Contributor Author

Not sure how to debug that.

Maybe by timing callbacks?

https://pymotw.com/3/asyncio/debugging.html

Sorry, I wasn't clear. I meant that changing to using the sync versions uncovered a timing race which I have already fixed. I was just wondering in general about checkers to help find these types of issues before I submit patches

@MartinHjelmare
Copy link
Member

Yes, that was what I was answering.

@PhracturedBlue
Copy link
Contributor Author

Thanks, hopefully I've addressed your concerns now. Please let me know if you see anything else

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Looks good! I'll let @balloob merge since this depends on a frontend PR.

@balloob balloob merged commit 98b92c7 into home-assistant:dev Sep 21, 2018
@ghost ghost removed the in progress label Sep 21, 2018
@balloob balloob mentioned this pull request Sep 28, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants