diff --git a/homeassistant/components/alexa.py b/homeassistant/components/alexa.py index ee90266d7c7cc0..3093b0eb12f4b6 100644 --- a/homeassistant/components/alexa.py +++ b/homeassistant/components/alexa.py @@ -104,8 +104,8 @@ def setup(hass, config): intents = config[DOMAIN].get(CONF_INTENTS, {}) flash_briefings = config[DOMAIN].get(CONF_FLASH_BRIEFINGS, {}) - hass.wsgi.register_view(AlexaIntentsView(hass, intents)) - hass.wsgi.register_view(AlexaFlashBriefingView(hass, flash_briefings)) + hass.http.register_view(AlexaIntentsView(hass, intents)) + hass.http.register_view(AlexaFlashBriefingView(hass, flash_briefings)) return True diff --git a/homeassistant/components/api.py b/homeassistant/components/api.py index 5670b60c73a6f7..40ceab555f3df9 100644 --- a/homeassistant/components/api.py +++ b/homeassistant/components/api.py @@ -38,20 +38,20 @@ def setup(hass, config): """Register the API with the HTTP interface.""" - hass.wsgi.register_view(APIStatusView) - hass.wsgi.register_view(APIEventStream) - hass.wsgi.register_view(APIConfigView) - hass.wsgi.register_view(APIDiscoveryView) - hass.wsgi.register_view(APIStatesView) - hass.wsgi.register_view(APIEntityStateView) - hass.wsgi.register_view(APIEventListenersView) - hass.wsgi.register_view(APIEventView) - hass.wsgi.register_view(APIServicesView) - hass.wsgi.register_view(APIDomainServicesView) - hass.wsgi.register_view(APIEventForwardingView) - hass.wsgi.register_view(APIComponentsView) - hass.wsgi.register_view(APIErrorLogView) - hass.wsgi.register_view(APITemplateView) + hass.http.register_view(APIStatusView) + hass.http.register_view(APIEventStream) + hass.http.register_view(APIConfigView) + hass.http.register_view(APIDiscoveryView) + hass.http.register_view(APIStatesView) + hass.http.register_view(APIEntityStateView) + hass.http.register_view(APIEventListenersView) + hass.http.register_view(APIEventView) + hass.http.register_view(APIServicesView) + hass.http.register_view(APIDomainServicesView) + hass.http.register_view(APIEventForwardingView) + hass.http.register_view(APIComponentsView) + hass.http.register_view(APIErrorLogView) + hass.http.register_view(APITemplateView) return True diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index 1b256447f50091..ce811780856d1a 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -33,8 +33,8 @@ def setup(hass, config): component = EntityComponent( logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL) - hass.wsgi.register_view(CameraImageView(hass, component.entities)) - hass.wsgi.register_view(CameraMjpegStream(hass, component.entities)) + hass.http.register_view(CameraImageView(hass, component.entities)) + hass.http.register_view(CameraMjpegStream(hass, component.entities)) component.setup(config) diff --git a/homeassistant/components/device_tracker/locative.py b/homeassistant/components/device_tracker/locative.py index a6a28dce6e350f..adbd1dd13d4ce6 100644 --- a/homeassistant/components/device_tracker/locative.py +++ b/homeassistant/components/device_tracker/locative.py @@ -21,7 +21,7 @@ def setup_scanner(hass, config, see): """Setup an endpoint for the Locative application.""" - hass.wsgi.register_view(LocativeView(hass, see)) + hass.http.register_view(LocativeView(hass, see)) return True diff --git a/homeassistant/components/foursquare.py b/homeassistant/components/foursquare.py index 99bfc063bad562..e12ae943af4e5b 100644 --- a/homeassistant/components/foursquare.py +++ b/homeassistant/components/foursquare.py @@ -76,7 +76,7 @@ def checkin_user(call): descriptions[DOMAIN][SERVICE_CHECKIN], schema=CHECKIN_SERVICE_SCHEMA) - hass.wsgi.register_view(FoursquarePushReceiver( + hass.http.register_view(FoursquarePushReceiver( hass, config[CONF_PUSH_SECRET])) return True diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index a5bdd5d39fee8c..43223f89932ebb 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -43,7 +43,7 @@ def register_built_in_panel(hass, component_name, sidebar_title=None, # pylint: disable=too-many-arguments path = 'panels/ha-panel-{}.html'.format(component_name) - if hass.wsgi.development: + if hass.http.development: url = ('/static/home-assistant-polymer/panels/' '{0}/ha-panel-{0}.html'.format(component_name)) else: @@ -102,7 +102,7 @@ def register_panel(hass, component_name, path, md5=None, sidebar_title=None, url = URL_PANEL_COMPONENT.format(component_name) if url not in _REGISTERED_COMPONENTS: - hass.wsgi.register_static_path(url, path) + hass.http.register_static_path(url, path) _REGISTERED_COMPONENTS.add(url) fprinted_url = URL_PANEL_COMPONENT_FP.format(component_name, md5) @@ -118,23 +118,23 @@ def add_manifest_json_key(key, val): def setup(hass, config): """Setup serving the frontend.""" - hass.wsgi.register_view(BootstrapView) - hass.wsgi.register_view(ManifestJSONView) + hass.http.register_view(BootstrapView) + hass.http.register_view(ManifestJSONView) - if hass.wsgi.development: + if hass.http.development: sw_path = "home-assistant-polymer/build/service_worker.js" else: sw_path = "service_worker.js" - hass.wsgi.register_static_path("/service_worker.js", + hass.http.register_static_path("/service_worker.js", os.path.join(STATIC_PATH, sw_path), 0) - hass.wsgi.register_static_path("/robots.txt", + hass.http.register_static_path("/robots.txt", os.path.join(STATIC_PATH, "robots.txt")) - hass.wsgi.register_static_path("/static", STATIC_PATH) + hass.http.register_static_path("/static", STATIC_PATH) local = hass.config.path('www') if os.path.isdir(local): - hass.wsgi.register_static_path("/local", local) + hass.http.register_static_path("/local", local) register_built_in_panel(hass, 'map', 'Map', 'mdi:account-location') @@ -147,7 +147,7 @@ def register_frontend_index(event): Done when Home Assistant is started so that all panels are known. """ - hass.wsgi.register_view(IndexView( + hass.http.register_view(IndexView( hass, ['/{}'.format(name) for name in PANELS])) hass.bus.listen_once(EVENT_HOMEASSISTANT_START, register_frontend_index) @@ -204,7 +204,7 @@ def __init__(self, hass, extra_urls): @asyncio.coroutine def get(self, request, entity_id=None): """Serve the index view.""" - if self.hass.wsgi.development: + if self.hass.http.development: core_url = '/static/home-assistant-polymer/build/core.js' ui_url = '/static/home-assistant-polymer/src/home-assistant.html' else: @@ -224,8 +224,8 @@ def get(self, request, entity_id=None): if self.hass.config.api.api_password: # require password if set no_auth = 'false' - if self.hass.wsgi.is_trusted_ip( - self.hass.wsgi.get_real_ip(request)): + if self.hass.http.is_trusted_ip( + self.hass.http.get_real_ip(request)): # bypass for trusted networks no_auth = 'true' diff --git a/homeassistant/components/history.py b/homeassistant/components/history.py index cabcd28aa0a892..c8230386aa0688 100644 --- a/homeassistant/components/history.py +++ b/homeassistant/components/history.py @@ -184,8 +184,8 @@ def setup(hass, config): filters.included_entities = include[CONF_ENTITIES] filters.included_domains = include[CONF_DOMAINS] - hass.wsgi.register_view(Last5StatesView(hass)) - hass.wsgi.register_view(HistoryPeriodView(hass, filters)) + hass.http.register_view(Last5StatesView(hass)) + hass.http.register_view(HistoryPeriodView(hass, filters)) register_built_in_panel(hass, 'history', 'History', 'mdi:poll-box') return True diff --git a/homeassistant/components/http.py b/homeassistant/components/http.py index 9544b1e38f44fb..8c85bf5c24f45b 100644 --- a/homeassistant/components/http.py +++ b/homeassistant/components/http.py @@ -105,10 +105,10 @@ def __init__(self, hass): def filter(self, record): """Hide sensitive data in messages.""" - if self.hass.wsgi.api_password is None: + if self.hass.http.api_password is None: return True - record.msg = record.msg.replace(self.hass.wsgi.api_password, '*******') + record.msg = record.msg.replace(self.hass.http.api_password, '*******') return True @@ -155,7 +155,7 @@ def start_server(event): hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_server) - hass.wsgi = server + hass.http = server hass.config.api = rem.API(server_host if server_host != '0.0.0.0' else util.get_local_ip(), api_password, server_port, @@ -378,12 +378,13 @@ def get_real_ip(request): def is_trusted_ip(self, remote_addr): """Match an ip address against trusted CIDR networks.""" return any(ip_address(remote_addr) in trusted_network - for trusted_network in self.hass.wsgi.trusted_networks) + for trusted_network in self.hass.http.trusted_networks) class HomeAssistantView(object): """Base view for all views.""" + url = None extra_urls = [] requires_auth = True # Views inheriting from this class can override this @@ -421,6 +422,7 @@ def file(self, request, fil): # pylint: disable=no-self-use def register(self, router): """Register the view with a router.""" + assert self.url is not None, 'No url set for view' urls = [self.url] + self.extra_urls for method in ('get', 'post', 'delete', 'put'): @@ -454,19 +456,19 @@ def handle(request): # Auth code verbose on purpose authenticated = False - if view.hass.wsgi.api_password is None: + if view.hass.http.api_password is None: authenticated = True - elif view.hass.wsgi.is_trusted_ip(remote_addr): + elif view.hass.http.is_trusted_ip(remote_addr): authenticated = True elif hmac.compare_digest(request.headers.get(HTTP_HEADER_HA_AUTH, ''), - view.hass.wsgi.api_password): + view.hass.http.api_password): # A valid auth header has been set authenticated = True elif hmac.compare_digest(request.GET.get(DATA_API_PASSWORD, ''), - view.hass.wsgi.api_password): + view.hass.http.api_password): authenticated = True if view.requires_auth and not authenticated: diff --git a/homeassistant/components/ios.py b/homeassistant/components/ios.py index 0793417fab3c47..a5858b62d9932f 100644 --- a/homeassistant/components/ios.py +++ b/homeassistant/components/ios.py @@ -266,13 +266,13 @@ def setup(hass, config): discovery.load_platform(hass, "sensor", DOMAIN, {}, config) - hass.wsgi.register_view(iOSIdentifyDeviceView(hass)) + hass.http.register_view(iOSIdentifyDeviceView(hass)) if config.get(DOMAIN) is not None: app_config = config[DOMAIN] if app_config.get(CONF_PUSH) is not None: push_config = app_config[CONF_PUSH] - hass.wsgi.register_view(iOSPushConfigView(hass, push_config)) + hass.http.register_view(iOSPushConfigView(hass, push_config)) return True diff --git a/homeassistant/components/logbook.py b/homeassistant/components/logbook.py index 775c323edb8d38..9d9936bd474962 100644 --- a/homeassistant/components/logbook.py +++ b/homeassistant/components/logbook.py @@ -101,7 +101,7 @@ def log_message(service): message = message.async_render() async_log_entry(hass, name, message, domain, entity_id) - hass.wsgi.register_view(LogbookView(hass, config)) + hass.http.register_view(LogbookView(hass, config)) register_built_in_panel(hass, 'logbook', 'Logbook', 'mdi:format-list-bulleted-type') diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index ebd3625912f099..838202fdcab13e 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -293,7 +293,7 @@ def setup(hass, config): component = EntityComponent( logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL) - hass.wsgi.register_view(MediaPlayerImageView(hass, component.entities)) + hass.http.register_view(MediaPlayerImageView(hass, component.entities)) component.setup(config) diff --git a/homeassistant/components/notify/html5.py b/homeassistant/components/notify/html5.py index 0241169b4df5cd..4ded65ba3ed4da 100644 --- a/homeassistant/components/notify/html5.py +++ b/homeassistant/components/notify/html5.py @@ -108,9 +108,9 @@ def get_service(hass, config): if registrations is None: return None - hass.wsgi.register_view( + hass.http.register_view( HTML5PushRegistrationView(hass, registrations, json_path)) - hass.wsgi.register_view(HTML5PushCallbackView(hass, registrations)) + hass.http.register_view(HTML5PushCallbackView(hass, registrations)) gcm_api_key = config.get(ATTR_GCM_API_KEY) gcm_sender_id = config.get(ATTR_GCM_SENDER_ID) diff --git a/homeassistant/components/sensor/fitbit.py b/homeassistant/components/sensor/fitbit.py index eac1b45ad3d71c..2c73bb764fb81c 100644 --- a/homeassistant/components/sensor/fitbit.py +++ b/homeassistant/components/sensor/fitbit.py @@ -274,8 +274,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): scope=['activity', 'heartrate', 'nutrition', 'profile', 'settings', 'sleep', 'weight']) - hass.wsgi.register_redirect(FITBIT_AUTH_START, fitbit_auth_start_url) - hass.wsgi.register_view(FitbitAuthCallbackView( + hass.http.register_redirect(FITBIT_AUTH_START, fitbit_auth_start_url) + hass.http.register_view(FitbitAuthCallbackView( hass, config, add_devices, oauth)) request_oauth_completion(hass) diff --git a/homeassistant/components/sensor/torque.py b/homeassistant/components/sensor/torque.py index dcb53b605035dc..1961c4cd6bed5e 100644 --- a/homeassistant/components/sensor/torque.py +++ b/homeassistant/components/sensor/torque.py @@ -58,7 +58,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): email = config.get(CONF_EMAIL) sensors = {} - hass.wsgi.register_view(TorqueReceiveDataView( + hass.http.register_view(TorqueReceiveDataView( hass, email, vehicle, sensors, add_devices)) return True diff --git a/homeassistant/components/switch/netio.py b/homeassistant/components/switch/netio.py index 28e71af87b31ef..dde7b791d90401 100644 --- a/homeassistant/components/switch/netio.py +++ b/homeassistant/components/switch/netio.py @@ -62,7 +62,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): port = config.get(CONF_PORT) if len(DEVICES) == 0: - hass.wsgi.register_view(NetioApiView) + hass.http.register_view(NetioApiView) dev = Netio(host, port, username, password) diff --git a/tests/common.py b/tests/common.py index 071bc4dbb8c2a2..b73af5fc4c5a02 100644 --- a/tests/common.py +++ b/tests/common.py @@ -198,9 +198,9 @@ def mock_state_change_event(hass, new_state, old_state=None): def mock_http_component(hass): """Mock the HTTP component.""" - hass.wsgi = mock.MagicMock() + hass.http = mock.MagicMock() hass.config.components.append('http') - hass.wsgi.views = {} + hass.http.views = {} def mock_register_view(view): """Store registered view.""" @@ -208,9 +208,9 @@ def mock_register_view(view): # Instantiate the view, if needed view = view(hass) - hass.wsgi.views[view.name] = view + hass.http.views[view.name] = view - hass.wsgi.register_view = mock_register_view + hass.http.register_view = mock_register_view def mock_mqtt_component(hass): diff --git a/tests/components/camera/test_generic.py b/tests/components/camera/test_generic.py index c91ce0253f978a..e2ce9c159360dd 100644 --- a/tests/components/camera/test_generic.py +++ b/tests/components/camera/test_generic.py @@ -23,7 +23,7 @@ def setup_platform(): yield from hass.loop.run_in_executor(None, setup_platform) - client = yield from test_client(hass.wsgi.app) + client = yield from test_client(hass.http.app) resp = yield from client.get('/api/camera_proxy/camera.config_test') @@ -57,7 +57,7 @@ def setup_platform(): yield from hass.loop.run_in_executor(None, setup_platform) - client = yield from test_client(hass.wsgi.app) + client = yield from test_client(hass.http.app) resp = yield from client.get('/api/camera_proxy/camera.config_test') diff --git a/tests/components/camera/test_local_file.py b/tests/components/camera/test_local_file.py index f498f6d02298b6..ede6ab39033513 100644 --- a/tests/components/camera/test_local_file.py +++ b/tests/components/camera/test_local_file.py @@ -25,7 +25,7 @@ def setup_platform(): yield from hass.loop.run_in_executor(None, setup_platform) - client = yield from test_client(hass.wsgi.app) + client = yield from test_client(hass.http.app) m_open = mock.mock_open(read_data=test_string.encode('utf-8')) with mock.patch( diff --git a/tests/components/camera/test_uvc.py b/tests/components/camera/test_uvc.py index 5addb3266c3ef9..41b272c15eb258 100644 --- a/tests/components/camera/test_uvc.py +++ b/tests/components/camera/test_uvc.py @@ -18,7 +18,7 @@ class TestUVCSetup(unittest.TestCase): def setUp(self): """Setup things to be run when tests are started.""" self.hass = get_test_home_assistant() - self.hass.wsgi = mock.MagicMock() + self.hass.http = mock.MagicMock() self.hass.config.components = ['http'] def tearDown(self): diff --git a/tests/components/test_http.py b/tests/components/test_http.py index 379a1a2f9ce7bb..5ef26d5d5ab34a 100644 --- a/tests/components/test_http.py +++ b/tests/components/test_http.py @@ -56,7 +56,7 @@ def setUpModule(): bootstrap.setup_component(hass, 'api') - hass.wsgi.trusted_networks = [ + hass.http.trusted_networks = [ ip_network(trusted_network) for trusted_network in TRUSTED_NETWORKS]