Friendlier exceptions for misconfigured views

If a view is missing a url or name attribute, this will result
in a more actionable exception being raised.
This commit is contained in:
Josh Wright 2016-05-14 20:46:49 -04:00 committed by Paulus Schoutsen
parent 1096232e17
commit aa34fe15b2

View file

@ -244,6 +244,18 @@ class HomeAssistantView(object):
"""Initilalize the base view."""
from werkzeug.wrappers import Response
if not hasattr(self, 'url'):
class_name = self.__class__.__name__
raise AttributeError(
'{0} missing required attribute "url"'.format(class_name)
)
if not hasattr(self, 'name'):
class_name = self.__class__.__name__
raise AttributeError(
'{0} missing required attribute "name"'.format(class_name)
)
self.hass = hass
# pylint: disable=invalid-name
self.Response = Response