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

Move imports to top for pushetta #29332

Merged
merged 2 commits into from
Dec 3, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions homeassistant/components/pushetta/notify.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"""Pushetta platform for notify component."""
import logging

from pushetta import Pushetta, exceptions as PushettaExceptions
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved
import voluptuous as vol

from homeassistant.const import CONF_API_KEY
import homeassistant.helpers.config_validation as cv

from homeassistant.components.notify import (
ATTR_TITLE,
ATTR_TITLE_DEFAULT,
PLATFORM_SCHEMA,
BaseNotificationService,
)
from homeassistant.const import CONF_API_KEY
import homeassistant.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -44,7 +44,6 @@ class PushettaNotificationService(BaseNotificationService):

def __init__(self, api_key, channel_name, send_test_msg):
"""Initialize the service."""
from pushetta import Pushetta

self._api_key = api_key
self._channel_name = channel_name
Expand All @@ -56,15 +55,14 @@ def __init__(self, api_key, channel_name, send_test_msg):

def send_message(self, message="", **kwargs):
"""Send a message to a user."""
from pushetta import exceptions

title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)

try:
self.pushetta.pushMessage(self._channel_name, f"{title} {message}")
except exceptions.TokenValidationError:
except PushettaExceptions.TokenValidationError:
_LOGGER.error("Please check your access token")
self.is_valid = False
except exceptions.ChannelNotFoundError:
except PushettaExceptions.ChannelNotFoundError:
_LOGGER.error("Channel '%s' not found", self._channel_name)
self.is_valid = False