mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Don't redefine consts (#9086)
This commit is contained in:
parent
5a3a43cd5b
commit
252aea37d2
@ -8,12 +8,10 @@ import logging
|
|||||||
|
|
||||||
import voluptuous as vol
|
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
|
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']
|
REQUIREMENTS = ['hipnotify==1.0.8']
|
||||||
|
|
||||||
@ -23,30 +21,30 @@ CONF_COLOR = 'color'
|
|||||||
CONF_ROOM = 'room'
|
CONF_ROOM = 'room'
|
||||||
CONF_NOTIFY = 'notify'
|
CONF_NOTIFY = 'notify'
|
||||||
CONF_FORMAT = 'format'
|
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_COLORS = {'yellow', 'green', 'red', 'purple', 'gray', 'random'}
|
||||||
VALID_FORMATS = {'text', 'html'}
|
VALID_FORMATS = {'text', 'html'}
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_TOKEN): cv.string,
|
|
||||||
vol.Required(CONF_ROOM): vol.Coerce(int),
|
vol.Required(CONF_ROOM): vol.Coerce(int),
|
||||||
vol.Optional(CONF_COLOR, default='yellow'): vol.In(VALID_COLORS),
|
vol.Required(CONF_TOKEN): cv.string,
|
||||||
vol.Optional(CONF_NOTIFY, default=False): cv.boolean,
|
vol.Optional(CONF_COLOR, default=DEFAULT_COLOR): vol.In(VALID_COLORS),
|
||||||
vol.Optional(CONF_FORMAT, default='text'): vol.In(VALID_FORMATS),
|
vol.Optional(CONF_FORMAT, default=DEFAULT_FORMAT): vol.In(VALID_FORMATS),
|
||||||
vol.Optional(CONF_HOST, default='https://api.hipchat.com/'): cv.string,
|
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):
|
def get_service(hass, config, discovery_info=None):
|
||||||
"""Get the HipChat notification service."""
|
"""Get the HipChat notification service."""
|
||||||
return HipchatNotificationService(
|
return HipchatNotificationService(
|
||||||
config[CONF_TOKEN],
|
config[CONF_TOKEN], config[CONF_ROOM], config[CONF_COLOR],
|
||||||
config[CONF_ROOM],
|
config[CONF_NOTIFY], config[CONF_FORMAT], config[CONF_HOST])
|
||||||
config[CONF_COLOR],
|
|
||||||
config[CONF_NOTIFY],
|
|
||||||
config[CONF_FORMAT],
|
|
||||||
config[CONF_HOST])
|
|
||||||
|
|
||||||
|
|
||||||
class HipchatNotificationService(BaseNotificationService):
|
class HipchatNotificationService(BaseNotificationService):
|
||||||
@ -69,9 +67,8 @@ class HipchatNotificationService(BaseNotificationService):
|
|||||||
"""Get Room object, creating it if necessary."""
|
"""Get Room object, creating it if necessary."""
|
||||||
from hipnotify import Room
|
from hipnotify import Room
|
||||||
if room not in self._rooms:
|
if room not in self._rooms:
|
||||||
self._rooms[room] = Room(token=self._token,
|
self._rooms[room] = Room(
|
||||||
room_id=room,
|
token=self._token, room_id=room, endpoint_url=self._host)
|
||||||
endpoint_url=self._host)
|
|
||||||
return self._rooms[room]
|
return self._rooms[room]
|
||||||
|
|
||||||
def send_message(self, message="", **kwargs):
|
def send_message(self, message="", **kwargs):
|
||||||
@ -96,7 +93,5 @@ class HipchatNotificationService(BaseNotificationService):
|
|||||||
|
|
||||||
for target in targets:
|
for target in targets:
|
||||||
room = self._get_room(target)
|
room = self._get_room(target)
|
||||||
room.notify(msg=message,
|
room.notify(msg=message, color=color, notify=notify,
|
||||||
color=color,
|
|
||||||
notify=notify,
|
|
||||||
message_format=message_format)
|
message_format=message_format)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user