8000 tellduslive: Fix exception when starting by molobrakos · Pull Request #7618 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

tellduslive: Fix exception when starting #7618

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

Merged
merged 1 commit into from
Jun 2, 2017
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
8 changes: 5 additions & 3 deletions homeassistant/components/tellduslive.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from datetime import datetime, timedelta
import logging

from homeassistant.const import ATTR_BATTERY_LEVEL, DEVICE_DEFAULT_NAME
from homeassistant.const import (
ATTR_BATTERY_LEVEL, DEVICE_DEFAULT_NAME, EVENT_HOMEASSISTANT_START)
from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
Expand Down Expand Up @@ -56,7 +57,8 @@ def setup(hass, config):
return False

hass.data[DOMAIN] = client
client.update(utcnow())

hass.bus.listen(EVENT_HOMEASSISTANT_START, client.update)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of this, move self._client.entities.append(self) from TelldusEntity __init__ to a new method on that class:

@asyncio.coroutine
def async_added_to_hass(self):
    """Entity has been added to hass."""
    self._client.entities.append(self)

When async_added_to_hass gets called, hass is set so updating the client will not result in entities without hass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, but with this change, the periodically polling of the server never starts, since update() reschedules itself after each run of sync. Should I make your change, in addition to keeping the hass.bus.listen-stuff?

Copy link
Member

Choose a reason for hiding this comment

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

Good point. Keep the start listener and start polling on START event. Append in added_to_hass hook


return True

Expand Down Expand Up @@ -91,7 +93,7 @@ def validate_session(self):
response = self._client.request_user()
return response and 'email' in response

def update(self, now):
def update(self, *args):
"""Periodically poll the servers for current state."""
_LOGGER.debug("Updating")
try:
Expand Down
0