Don't redefine consts (#9086)

pull/9094/head
Fabian Affolter 2017-08-22 13:12:01 +02:00 committed by GitHub
parent 5a3a43cd5b
commit 252aea37d2
1 changed files with 18 additions and 23 deletions

View File

@ -8,12 +8,10 @@ import logging
import voluptuous as vol
from homeassistant.components.notify import (
ATTR_TARGET, ATTR_DATA,
PLATFORM_SCHEMA, BaseNotificationService)
from homeassistant.const import (
CONF_TOKEN)
import homeassistant.helpers.config_validation as cv
from homeassistant.components.notify import (
ATTR_TARGET, ATTR_DATA, PLATFORM_SCHEMA, BaseNotificationService)
from homeassistant.const import CONF_TOKEN, CONF_HOST
REQUIREMENTS = ['hipnotify==1.0.8']
@ -23,30 +21,30 @@ CONF_COLOR = 'color'
CONF_ROOM = 'room'
CONF_NOTIFY = 'notify'
CONF_FORMAT = 'format'
CONF_HOST = 'host'
DEFAULT_COLOR = 'yellow'
DEFAULT_FORMAT = 'text'
DEFAULT_HOST = 'https://api.hipchat.com/'
DEFAULT_NOTIFY = False
VALID_COLORS = {'yellow', 'green', 'red', 'purple', 'gray', 'random'}
VALID_FORMATS = {'text', 'html'}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_TOKEN): cv.string,
vol.Required(CONF_ROOM): vol.Coerce(int),
vol.Optional(CONF_COLOR, default='yellow'): vol.In(VALID_COLORS),
vol.Optional(CONF_NOTIFY, default=False): cv.boolean,
vol.Optional(CONF_FORMAT, default='text'): vol.In(VALID_FORMATS),
vol.Optional(CONF_HOST, default='https://api.hipchat.com/'): cv.string,
vol.Required(CONF_TOKEN): cv.string,
vol.Optional(CONF_COLOR, default=DEFAULT_COLOR): vol.In(VALID_COLORS),
vol.Optional(CONF_FORMAT, default=DEFAULT_FORMAT): vol.In(VALID_FORMATS),
vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
vol.Optional(CONF_NOTIFY, default=DEFAULT_NOTIFY): cv.boolean,
})
def get_service(hass, config, discovery_info=None):
"""Get the HipChat notification service."""
return HipchatNotificationService(
config[CONF_TOKEN],
config[CONF_ROOM],
config[CONF_COLOR],
config[CONF_NOTIFY],
config[CONF_FORMAT],
config[CONF_HOST])
config[CONF_TOKEN], config[CONF_ROOM], config[CONF_COLOR],
config[CONF_NOTIFY], config[CONF_FORMAT], config[CONF_HOST])
class HipchatNotificationService(BaseNotificationService):
@ -69,9 +67,8 @@ class HipchatNotificationService(BaseNotificationService):
"""Get Room object, creating it if necessary."""
from hipnotify import Room
if room not in self._rooms:
self._rooms[room] = Room(token=self._token,
room_id=room,
endpoint_url=self._host)
self._rooms[room] = Room(
token=self._token, room_id=room, endpoint_url=self._host)
return self._rooms[room]
def send_message(self, message="", **kwargs):
@ -96,7 +93,5 @@ class HipchatNotificationService(BaseNotificationService):
for target in targets:
room = self._get_room(target)
room.notify(msg=message,
color=color,
notify=notify,
room.notify(msg=message, color=color, notify=notify,
message_format=message_format)