Allow for overriding the DoorBird push notification URL in configuration (#13268)

* Allow for overriding the DoorBird push notification URL in configuration

* rename override config key
This commit is contained in:
Andy Castille 2018-03-29 22:00:26 -05:00 committed by Paulus Schoutsen
parent 507c658fe9
commit 170763ef2f

View file

@ -22,6 +22,7 @@ DOMAIN = 'doorbird'
API_URL = '/api/{}'.format(DOMAIN)
CONF_DOORBELL_EVENTS = 'doorbell_events'
CONF_CUSTOM_URL = 'hass_url_override'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
@ -29,6 +30,7 @@ CONFIG_SCHEMA = vol.Schema({
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_DOORBELL_EVENTS): cv.boolean,
vol.Optional(CONF_CUSTOM_URL): cv.string,
})
}, extra=vol.ALLOW_EXTRA)
@ -61,9 +63,17 @@ def setup(hass, config):
# Provide an endpoint for the device to call to trigger events
hass.http.register_view(DoorbirdRequestView())
# Get the URL of this server
hass_url = hass.config.api.base_url
# Override it if another is specified in the component configuration
if config[DOMAIN].get(CONF_CUSTOM_URL):
hass_url = config[DOMAIN].get(CONF_CUSTOM_URL)
_LOGGER.info("DoorBird will connect to this instance via %s",
hass_url)
# This will make HA the only service that gets doorbell events
url = '{}{}/{}'.format(
hass.config.api.base_url, API_URL, SENSOR_DOORBELL)
url = '{}{}/{}'.format(hass_url, API_URL, SENSOR_DOORBELL)
device.reset_notifications()
device.subscribe_notification(SENSOR_DOORBELL, url)