Skip to content

Instantly share code, notes, and snippets.

@archef2000
Last active May 4, 2023 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save archef2000/c5eabede4563749acfd3a193c14edf1e to your computer and use it in GitHub Desktop.
Save archef2000/c5eabede4563749acfd3a193c14edf1e to your computer and use it in GitHub Desktop.
Home Assistant custom component for hello world auth test.
"""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)
{
"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