Upgrade matrix-client to 0.0.6 (#6808)
This commit is contained in:
parent
f4f72e420a
commit
be04ef7be1
2 changed files with 13 additions and 24 deletions
|
@ -15,7 +15,9 @@ from homeassistant.components.notify import (
|
||||||
ATTR_TARGET, PLATFORM_SCHEMA, BaseNotificationService)
|
ATTR_TARGET, PLATFORM_SCHEMA, BaseNotificationService)
|
||||||
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_VERIFY_SSL
|
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_VERIFY_SSL
|
||||||
|
|
||||||
REQUIREMENTS = ['matrix-client==0.0.5']
|
REQUIREMENTS = ['matrix-client==0.0.6']
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SESSION_FILE = 'matrix.conf'
|
SESSION_FILE = 'matrix.conf'
|
||||||
AUTH_TOKENS = dict()
|
AUTH_TOKENS = dict()
|
||||||
|
@ -31,8 +33,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_DEFAULT_ROOM): cv.string,
|
vol.Required(CONF_DEFAULT_ROOM): cv.string,
|
||||||
})
|
})
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def get_service(hass, config, discovery_info=None):
|
def get_service(hass, config, discovery_info=None):
|
||||||
"""Get the Matrix notification service."""
|
"""Get the Matrix notification service."""
|
||||||
|
@ -49,7 +49,7 @@ def get_service(hass, config, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class MatrixNotificationService(BaseNotificationService):
|
class MatrixNotificationService(BaseNotificationService):
|
||||||
"""Wrapper for the MatrixNotificationClient."""
|
"""Wrapper for the Matrix Notification Client."""
|
||||||
|
|
||||||
def __init__(self, homeserver, default_room, verify_ssl,
|
def __init__(self, homeserver, default_room, verify_ssl,
|
||||||
username, password):
|
username, password):
|
||||||
|
@ -107,32 +107,23 @@ def send_message(message, homeserver, target_rooms, verify_tls,
|
||||||
valid_cert_check=verify_tls
|
valid_cert_check=verify_tls
|
||||||
)
|
)
|
||||||
except MatrixRequestError as ex:
|
except MatrixRequestError as ex:
|
||||||
_LOGGER.info(
|
_LOGGER.info("login_by_token: (%d) %s", ex.code, ex.content)
|
||||||
'login_by_token: (%d) %s', ex.code, ex.content
|
|
||||||
)
|
|
||||||
|
|
||||||
def login_by_password():
|
def login_by_password():
|
||||||
"""Login using password authentication."""
|
"""Login using password authentication."""
|
||||||
try:
|
try:
|
||||||
_client = MatrixClient(
|
_client = MatrixClient(
|
||||||
base_url=homeserver,
|
base_url=homeserver, valid_cert_check=verify_tls)
|
||||||
valid_cert_check=verify_tls
|
|
||||||
)
|
|
||||||
_client.login_with_password(username, password)
|
_client.login_with_password(username, password)
|
||||||
store_token(mx_id, _client.token)
|
store_token(mx_id, _client.token)
|
||||||
return _client
|
return _client
|
||||||
except MatrixRequestError as ex:
|
except MatrixRequestError as ex:
|
||||||
_LOGGER.error(
|
_LOGGER.error("login_by_password: (%d) %s", ex.code, ex.content)
|
||||||
'login_by_password: (%d) %s', ex.code, ex.content
|
|
||||||
)
|
|
||||||
|
|
||||||
# this is as close as we can get to the mx_id, since there is no
|
# This is as close as we can get to the mx_id, since there is no
|
||||||
# homeserver discovery protocol we have to fall back to the homeserver url
|
# homeserver discovery protocol we have to fall back to the homeserver url
|
||||||
# instead of the actual domain it serves.
|
# instead of the actual domain it serves.
|
||||||
mx_id = "{user}@{homeserver}".format(
|
mx_id = "{user}@{homeserver}".format(user=username, homeserver=homeserver)
|
||||||
user=username,
|
|
||||||
homeserver=homeserver
|
|
||||||
)
|
|
||||||
|
|
||||||
if mx_id in AUTH_TOKENS:
|
if mx_id in AUTH_TOKENS:
|
||||||
client = login_by_token()
|
client = login_by_token()
|
||||||
|
@ -140,14 +131,12 @@ def send_message(message, homeserver, target_rooms, verify_tls,
|
||||||
client = login_by_password()
|
client = login_by_password()
|
||||||
if not client:
|
if not client:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
'login failed, both token and username/password '
|
"Login failed, both token and username/password invalid")
|
||||||
'invalid'
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
client = login_by_password()
|
client = login_by_password()
|
||||||
if not client:
|
if not client:
|
||||||
_LOGGER.error('login failed, username/password invalid')
|
_LOGGER.error("Login failed, username/password invalid")
|
||||||
return
|
return
|
||||||
|
|
||||||
rooms = client.get_rooms()
|
rooms = client.get_rooms()
|
||||||
|
@ -161,6 +150,6 @@ def send_message(message, homeserver, target_rooms, verify_tls,
|
||||||
_LOGGER.debug(room.send_text(message))
|
_LOGGER.debug(room.send_text(message))
|
||||||
except MatrixRequestError as ex:
|
except MatrixRequestError as ex:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
'Unable to deliver message to room \'%s\': (%d): %s',
|
"Unable to deliver message to room '%s': (%d): %s",
|
||||||
target_room, ex.code, ex.content
|
target_room, ex.code, ex.content
|
||||||
)
|
)
|
||||||
|
|
|
@ -360,7 +360,7 @@ liveboxplaytv==1.4.9
|
||||||
lyft_rides==0.1.0b0
|
lyft_rides==0.1.0b0
|
||||||
|
|
||||||
# homeassistant.components.notify.matrix
|
# homeassistant.components.notify.matrix
|
||||||
matrix-client==0.0.5
|
matrix-client==0.0.6
|
||||||
|
|
||||||
# homeassistant.components.maxcube
|
# homeassistant.components.maxcube
|
||||||
maxcube-api==0.1.0
|
maxcube-api==0.1.0
|
||||||
|
|
Loading…
Add table
Reference in a new issue