Move imports to top for matrix (#29392)

This commit is contained in:
springstan 2019-12-04 11:15:29 +01:00 committed by Fabian Affolter
parent c6fd8582a9
commit d79d9e0bfb
2 changed files with 11 additions and 16 deletions

View File

@ -1,22 +1,23 @@
"""The matrix bot component.""" """The matrix bot component."""
from functools import partial
import logging import logging
import os import os
from functools import partial
from matrix_client.client import MatrixClient, MatrixRequestError
import voluptuous as vol import voluptuous as vol
import homeassistant.helpers.config_validation as cv from homeassistant.components.notify import ATTR_MESSAGE, ATTR_TARGET
from homeassistant.components.notify import ATTR_TARGET, ATTR_MESSAGE
from homeassistant.const import ( from homeassistant.const import (
CONF_USERNAME,
CONF_PASSWORD,
CONF_VERIFY_SSL,
CONF_NAME, CONF_NAME,
EVENT_HOMEASSISTANT_STOP, CONF_PASSWORD,
CONF_USERNAME,
CONF_VERIFY_SSL,
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
) )
from homeassistant.util.json import load_json, save_json
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
import homeassistant.helpers.config_validation as cv
from homeassistant.util.json import load_json, save_json
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -76,7 +77,6 @@ SERVICE_SCHEMA_SEND_MESSAGE = vol.Schema(
def setup(hass, config): def setup(hass, config):
"""Set up the Matrix bot component.""" """Set up the Matrix bot component."""
from matrix_client.client import MatrixRequestError
config = config[DOMAIN] config = config[DOMAIN]
@ -249,7 +249,6 @@ class MatrixBot:
def _join_rooms(self): def _join_rooms(self):
"""Join the rooms that we listen for commands in.""" """Join the rooms that we listen for commands in."""
from matrix_client.client import MatrixRequestError
for room_id in self._listening_rooms: for room_id in self._listening_rooms:
try: try:
@ -287,7 +286,6 @@ class MatrixBot:
def _login(self): def _login(self):
"""Login to the matrix homeserver and return the client instance.""" """Login to the matrix homeserver and return the client instance."""
from matrix_client.client import MatrixRequestError
# Attempt to generate a valid client using either of the two possible # Attempt to generate a valid client using either of the two possible
# login methods: # login methods:
@ -328,7 +326,6 @@ class MatrixBot:
def _login_by_token(self): def _login_by_token(self):
"""Login using authentication token and return the client.""" """Login using authentication token and return the client."""
from matrix_client.client import MatrixClient
return MatrixClient( return MatrixClient(
base_url=self._homeserver, base_url=self._homeserver,
@ -339,7 +336,6 @@ class MatrixBot:
def _login_by_password(self): def _login_by_password(self):
"""Login using password authentication and return the client.""" """Login using password authentication and return the client."""
from matrix_client.client import MatrixClient
_client = MatrixClient( _client = MatrixClient(
base_url=self._homeserver, valid_cert_check=self._verify_tls base_url=self._homeserver, valid_cert_check=self._verify_tls
@ -353,7 +349,6 @@ class MatrixBot:
def _send_message(self, message, target_rooms): def _send_message(self, message, target_rooms):
"""Send the message to the matrix server.""" """Send the message to the matrix server."""
from matrix_client.client import MatrixRequestError
for target_room in target_rooms: for target_room in target_rooms:
try: try:

View File

@ -3,13 +3,13 @@ import logging
import voluptuous as vol import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.components.notify import ( from homeassistant.components.notify import (
ATTR_MESSAGE,
ATTR_TARGET, ATTR_TARGET,
PLATFORM_SCHEMA, PLATFORM_SCHEMA,
BaseNotificationService, BaseNotificationService,
ATTR_MESSAGE,
) )
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)