mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Add hints to get_service in rest (#86703)
This commit is contained in:
parent
ff91fb7d74
commit
ca8cc284ed
@ -1,8 +1,11 @@
|
|||||||
"""RESTful platform for notify component."""
|
"""RESTful platform for notify component."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
from requests.auth import AuthBase, HTTPBasicAuth, HTTPDigestAuth
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
@ -26,8 +29,10 @@ from homeassistant.const import (
|
|||||||
HTTP_BASIC_AUTHENTICATION,
|
HTTP_BASIC_AUTHENTICATION,
|
||||||
HTTP_DIGEST_AUTHENTICATION,
|
HTTP_DIGEST_AUTHENTICATION,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.template import Template
|
from homeassistant.helpers.template import Template
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
CONF_DATA = "data"
|
CONF_DATA = "data"
|
||||||
CONF_DATA_TEMPLATE = "data_template"
|
CONF_DATA_TEMPLATE = "data_template"
|
||||||
@ -66,7 +71,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def get_service(hass, config, discovery_info=None):
|
def get_service(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config: ConfigType,
|
||||||
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
|
) -> RestNotificationService:
|
||||||
"""Get the RESTful notification service."""
|
"""Get the RESTful notification service."""
|
||||||
resource = config.get(CONF_RESOURCE)
|
resource = config.get(CONF_RESOURCE)
|
||||||
method = config.get(CONF_METHOD)
|
method = config.get(CONF_METHOD)
|
||||||
@ -81,13 +90,12 @@ def get_service(hass, config, discovery_info=None):
|
|||||||
password = config.get(CONF_PASSWORD)
|
password = config.get(CONF_PASSWORD)
|
||||||
verify_ssl = config.get(CONF_VERIFY_SSL)
|
verify_ssl = config.get(CONF_VERIFY_SSL)
|
||||||
|
|
||||||
|
auth: AuthBase | None = None
|
||||||
if username and password:
|
if username and password:
|
||||||
if config.get(CONF_AUTHENTICATION) == HTTP_DIGEST_AUTHENTICATION:
|
if config.get(CONF_AUTHENTICATION) == HTTP_DIGEST_AUTHENTICATION:
|
||||||
auth = requests.auth.HTTPDigestAuth(username, password)
|
auth = HTTPDigestAuth(username, password)
|
||||||
else:
|
else:
|
||||||
auth = requests.auth.HTTPBasicAuth(username, password)
|
auth = HTTPBasicAuth(username, password)
|
||||||
else:
|
|
||||||
auth = None
|
|
||||||
|
|
||||||
return RestNotificationService(
|
return RestNotificationService(
|
||||||
hass,
|
hass,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user