-
-
Save archef2000/c5eabede4563749acfd3a193c14edf1e to your computer and use it in GitHub Desktop.
Home Assistant custom component for hello world auth test.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Custom Component""" | |
import asyncio | |
import logging | |
from homeassistant.components.http import KEY_AUTHENTICATED, KEY_HASS_USER, HomeAssistantView | |
_LOGGER = logging.getLogger(__name__) | |
DOMAIN = "my_component" | |
async def async_setup(hass, config): | |
"""Setup integration.""" | |
hass.http.register_view(HelloWorldView()) | |
return True | |
class HelloWorldView(HomeAssistantView): | |
url = "/api/my_component" | |
name = "api:my_component" | |
requires_auth = True | |
def get(self, request): | |
_LOGGER.debug(request[KEY_AUTHENTICATED]) | |
_LOGGER.debug(request[KEY_HASS_USER].id) | |
_LOGGER.debug(request[KEY_HASS_USER].is_admin) | |
return self.json({"message": "Hello, World!"}, status_code=200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"domain": "my_component", | |
"name": "My Component", | |
"dependencies": ["http"], | |
"requirements": [], | |
"config_flow": false, | |
"codeowners": [], | |
"iot_class": "local_polling", | |
"version": "1.0.0" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment