Move constant to 'const.py' and use already defined ones (#10211)

This commit is contained in:
Fabian Affolter 2017-10-29 17:28:07 +01:00 committed by GitHub
parent 6a9968ccb9
commit 690760404b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 113 additions and 120 deletions

View file

@ -8,17 +8,14 @@ import logging
import voluptuous as vol
from homeassistant.const import (
CONF_URL, CONF_USERNAME, CONF_PASSWORD)
from homeassistant.components.notify import (
ATTR_DATA, PLATFORM_SCHEMA,
BaseNotificationService)
import homeassistant.helpers.config_validation as cv
from homeassistant.const import (
CONF_URL, CONF_USERNAME, CONF_PASSWORD, CONF_ROOM)
from homeassistant.components.notify import (
ATTR_DATA, PLATFORM_SCHEMA, BaseNotificationService)
REQUIREMENTS = ['rocketchat-API==0.6.1']
CONF_ROOM = 'room'
_LOGGER = logging.getLogger(__name__)
# pylint: disable=no-value-for-parameter
@ -44,11 +41,11 @@ def get_service(hass, config, discovery_info=None):
return RocketChatNotificationService(url, username, password, room)
except RocketConnectionException:
_LOGGER.warning(
"Unable to connect to Rocket.Chat server at %s.", url)
"Unable to connect to Rocket.Chat server at %s", url)
except RocketAuthenticationException:
_LOGGER.warning(
"Rocket.Chat authentication failed for user %s.", username)
_LOGGER.info("Please check your username/password.")
"Rocket.Chat authentication failed for user %s", username)
_LOGGER.info("Please check your username/password")
return None
@ -65,8 +62,8 @@ class RocketChatNotificationService(BaseNotificationService):
def send_message(self, message="", **kwargs):
"""Send a message to Rocket.Chat."""
data = kwargs.get(ATTR_DATA) or {}
resp = self._server.chat_post_message(message, channel=self._room,
**data)
resp = self._server.chat_post_message(
message, channel=self._room, **data)
if resp.status_code == 200:
success = resp.json()["success"]
if not success: