Move constant to 'const.py' and use already defined ones (#10211)
This commit is contained in:
parent
6a9968ccb9
commit
690760404b
15 changed files with 113 additions and 120 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue