Enable strict typing for webhook (#107946)
This commit is contained in:
parent
ca421d4f86
commit
9221f5da10
4 changed files with 19 additions and 5 deletions
|
@ -439,6 +439,7 @@ homeassistant.components.waqi.*
|
||||||
homeassistant.components.water_heater.*
|
homeassistant.components.water_heater.*
|
||||||
homeassistant.components.watttime.*
|
homeassistant.components.watttime.*
|
||||||
homeassistant.components.weather.*
|
homeassistant.components.weather.*
|
||||||
|
homeassistant.components.webhook.*
|
||||||
homeassistant.components.webostv.*
|
homeassistant.components.webostv.*
|
||||||
homeassistant.components.websocket_api.*
|
homeassistant.components.websocket_api.*
|
||||||
homeassistant.components.wemo.*
|
homeassistant.components.wemo.*
|
||||||
|
|
|
@ -174,7 +174,7 @@ async def async_handle_webhook(
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = await webhook["handler"](hass, webhook_id, request)
|
response: Response | None = await webhook["handler"](hass, webhook_id, request)
|
||||||
if response is None:
|
if response is None:
|
||||||
response = Response(status=HTTPStatus.OK)
|
response = Response(status=HTTPStatus.OK)
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -3,8 +3,9 @@ from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from aiohttp import hdrs
|
from aiohttp import hdrs, web
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_PLATFORM, CONF_WEBHOOK_ID
|
from homeassistant.const import CONF_PLATFORM, CONF_WEBHOOK_ID
|
||||||
|
@ -57,9 +58,11 @@ class TriggerInstance:
|
||||||
job: HassJob
|
job: HassJob
|
||||||
|
|
||||||
|
|
||||||
async def _handle_webhook(hass, webhook_id, request):
|
async def _handle_webhook(
|
||||||
|
hass: HomeAssistant, webhook_id: str, request: web.Request
|
||||||
|
) -> None:
|
||||||
"""Handle incoming webhook."""
|
"""Handle incoming webhook."""
|
||||||
base_result = {"platform": "webhook", "webhook_id": webhook_id}
|
base_result: dict[str, Any] = {"platform": "webhook", "webhook_id": webhook_id}
|
||||||
|
|
||||||
if "json" in request.headers.get(hdrs.CONTENT_TYPE, ""):
|
if "json" in request.headers.get(hdrs.CONTENT_TYPE, ""):
|
||||||
base_result["json"] = await request.json()
|
base_result["json"] = await request.json()
|
||||||
|
@ -133,7 +136,7 @@ async def async_attach_trigger(
|
||||||
triggers[webhook_id].append(trigger_instance)
|
triggers[webhook_id].append(trigger_instance)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def unregister():
|
def unregister() -> None:
|
||||||
"""Unregister webhook."""
|
"""Unregister webhook."""
|
||||||
if issue_id:
|
if issue_id:
|
||||||
async_delete_issue(hass, DOMAIN, issue_id)
|
async_delete_issue(hass, DOMAIN, issue_id)
|
||||||
|
|
10
mypy.ini
10
mypy.ini
|
@ -4153,6 +4153,16 @@ disallow_untyped_defs = true
|
||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = true
|
warn_unreachable = true
|
||||||
|
|
||||||
|
[mypy-homeassistant.components.webhook.*]
|
||||||
|
check_untyped_defs = true
|
||||||
|
disallow_incomplete_defs = true
|
||||||
|
disallow_subclassing_any = true
|
||||||
|
disallow_untyped_calls = true
|
||||||
|
disallow_untyped_decorators = true
|
||||||
|
disallow_untyped_defs = true
|
||||||
|
warn_return_any = true
|
||||||
|
warn_unreachable = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.webostv.*]
|
[mypy-homeassistant.components.webostv.*]
|
||||||
check_untyped_defs = true
|
check_untyped_defs = true
|
||||||
disallow_incomplete_defs = true
|
disallow_incomplete_defs = true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue