mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Improve view registration comments
Clarify that HomeAssistantWSGI.register_view() can handle either instantiated or uninstantiated view classes.
This commit is contained in:
parent
15e329a588
commit
54ecab7590
@ -127,14 +127,16 @@ class HomeAssistantWSGI(object):
|
|||||||
def register_view(self, view):
|
def register_view(self, view):
|
||||||
"""Register a view with the WSGI server.
|
"""Register a view with the WSGI server.
|
||||||
|
|
||||||
The view argument must inherit from the HomeAssistantView class, and
|
The view argument must be a class that inherits from HomeAssistantView.
|
||||||
it must have (globally unique) 'url' and 'name' attributes.
|
It is optional to instantiate it before registering; this method will
|
||||||
|
handle it either way.
|
||||||
"""
|
"""
|
||||||
from werkzeug.routing import Rule
|
from werkzeug.routing import Rule
|
||||||
|
|
||||||
if view.name in self.views:
|
if view.name in self.views:
|
||||||
_LOGGER.warning("View '%s' is being overwritten", view.name)
|
_LOGGER.warning("View '%s' is being overwritten", view.name)
|
||||||
if isinstance(view, type):
|
if isinstance(view, type):
|
||||||
|
# Instantiate the view, if needed
|
||||||
view = view(self.hass)
|
view = view(self.hass)
|
||||||
|
|
||||||
self.views[view.name] = view
|
self.views[view.name] = view
|
||||||
|
Loading…
x
Reference in New Issue
Block a user