Add Sentry component (#30422)
This commit is contained in:
parent
bb55606d29
commit
3033dbd86c
15 changed files with 254 additions and 1 deletions
18
homeassistant/components/sentry/.translations/en.json
Normal file
18
homeassistant/components/sentry/.translations/en.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"config": {
|
||||
"title": "Sentry",
|
||||
"step": {
|
||||
"user": {
|
||||
"title": "Sentry",
|
||||
"description": "Enter your Sentry DSN"
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"unknown": "Unexpected error",
|
||||
"bad_dsn": "Invalid DSN"
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "Sentry is already configured"
|
||||
}
|
||||
}
|
||||
}
|
56
homeassistant/components/sentry/__init__.py
Normal file
56
homeassistant/components/sentry/__init__.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
"""The sentry integration."""
|
||||
import logging
|
||||
|
||||
import sentry_sdk
|
||||
from sentry_sdk.integrations.logging import LoggingIntegration
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
|
||||
from .const import CONF_DSN, CONF_ENVIRONMENT, DOMAIN
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
{vol.Required(CONF_DSN): cv.string, CONF_ENVIRONMENT: cv.string}
|
||||
)
|
||||
},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: dict):
|
||||
"""Set up the Sentry component."""
|
||||
conf = config.get(DOMAIN)
|
||||
if conf is not None:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}
|
||||
)
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
"""Set up Sentry from a config entry."""
|
||||
conf = entry.data
|
||||
|
||||
hass.data[DOMAIN] = conf
|
||||
|
||||
# https://docs.sentry.io/platforms/python/logging/
|
||||
sentry_logging = LoggingIntegration(
|
||||
level=logging.INFO, # Capture info and above as breadcrumbs
|
||||
event_level=logging.ERROR, # Send errors as events
|
||||
)
|
||||
|
||||
sentry_sdk.init(
|
||||
dsn=conf.get(CONF_DSN),
|
||||
environment=conf.get(CONF_ENVIRONMENT),
|
||||
integrations=[sentry_logging],
|
||||
)
|
||||
|
||||
return True
|
56
homeassistant/components/sentry/config_flow.py
Normal file
56
homeassistant/components/sentry/config_flow.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
"""Config flow for sentry integration."""
|
||||
import logging
|
||||
|
||||
from sentry_sdk.utils import BadDsn, Dsn
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries, core
|
||||
|
||||
from .const import CONF_DSN, DOMAIN # pylint: disable=unused-import
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DATA_SCHEMA = vol.Schema({vol.Required(CONF_DSN): str})
|
||||
|
||||
|
||||
async def validate_input(hass: core.HomeAssistant, data):
|
||||
"""Validate the DSN input allows us to connect.
|
||||
|
||||
Data has the keys from DATA_SCHEMA with values provided by the user.
|
||||
"""
|
||||
# validate the dsn
|
||||
Dsn(data["dsn"])
|
||||
|
||||
return {"title": "Sentry"}
|
||||
|
||||
|
||||
class DomainConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a Sentry config flow."""
|
||||
|
||||
VERSION = 1
|
||||
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Handle a user config flow."""
|
||||
if self._async_current_entries():
|
||||
return self.async_abort(reason="already_configured")
|
||||
|
||||
errors = {}
|
||||
if user_input is not None:
|
||||
try:
|
||||
info = await validate_input(self.hass, user_input)
|
||||
|
||||
return self.async_create_entry(title=info["title"], data=user_input)
|
||||
except BadDsn:
|
||||
errors["base"] = "bad_dsn"
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
errors["base"] = "unknown"
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=DATA_SCHEMA, errors=errors
|
||||
)
|
||||
|
||||
async def async_step_import(self, import_config):
|
||||
"""Import a config entry from configuration.yaml."""
|
||||
return await self.async_step_user(import_config)
|
6
homeassistant/components/sentry/const.py
Normal file
6
homeassistant/components/sentry/const.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
"""Constants for the sentry integration."""
|
||||
|
||||
DOMAIN = "sentry"
|
||||
|
||||
CONF_DSN = "dsn"
|
||||
CONF_ENVIRONMENT = "environment"
|
12
homeassistant/components/sentry/manifest.json
Normal file
12
homeassistant/components/sentry/manifest.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"domain": "sentry",
|
||||
"name": "Sentry",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/sentry",
|
||||
"requirements": ["sentry-sdk==0.13.5"],
|
||||
"ssdp": [],
|
||||
"zeroconf": [],
|
||||
"homekit": {},
|
||||
"dependencies": [],
|
||||
"codeowners": ["@dcramer"]
|
||||
}
|
18
homeassistant/components/sentry/strings.json
Normal file
18
homeassistant/components/sentry/strings.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"config": {
|
||||
"title": "Sentry",
|
||||
"step": {
|
||||
"user": {
|
||||
"title": "Sentry",
|
||||
"description": "Enter your Sentry DSN"
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"unknown": "Unexpected error",
|
||||
"bad_dsn": "Invalid DSN"
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "Sentry is already configured"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue