Add clicksend to strict typing (#79544)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
This commit is contained in:
parent
41d2ab5b37
commit
5674295b3c
3 changed files with 29 additions and 9 deletions
|
@ -78,6 +78,7 @@ homeassistant.components.camera.*
|
|||
homeassistant.components.canary.*
|
||||
homeassistant.components.cover.*
|
||||
homeassistant.components.clickatell.*
|
||||
homeassistant.components.clicksend.*
|
||||
homeassistant.components.cpuspeed.*
|
||||
homeassistant.components.crownstone.*
|
||||
homeassistant.components.deconz.*
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
"""Clicksend platform for notify component."""
|
||||
from __future__ import annotations
|
||||
|
||||
from http import HTTPStatus
|
||||
import json
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import requests
|
||||
import voluptuous as vol
|
||||
|
@ -14,7 +17,9 @@ from homeassistant.const import (
|
|||
CONF_USERNAME,
|
||||
CONTENT_TYPE_JSON,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -41,7 +46,11 @@ PLATFORM_SCHEMA = vol.Schema(
|
|||
)
|
||||
|
||||
|
||||
def get_service(hass, config, discovery_info=None):
|
||||
def get_service(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> ClicksendNotificationService | None:
|
||||
"""Get the ClickSend notification service."""
|
||||
if not _authenticate(config):
|
||||
_LOGGER.error("You are not authorized to access ClickSend")
|
||||
|
@ -52,16 +61,16 @@ def get_service(hass, config, discovery_info=None):
|
|||
class ClicksendNotificationService(BaseNotificationService):
|
||||
"""Implementation of a notification service for the ClickSend service."""
|
||||
|
||||
def __init__(self, config):
|
||||
def __init__(self, config: ConfigType) -> None:
|
||||
"""Initialize the service."""
|
||||
self.username = config[CONF_USERNAME]
|
||||
self.api_key = config[CONF_API_KEY]
|
||||
self.recipients = config[CONF_RECIPIENT]
|
||||
self.sender = config[CONF_SENDER]
|
||||
self.username: str = config[CONF_USERNAME]
|
||||
self.api_key: str = config[CONF_API_KEY]
|
||||
self.recipients: list[str] = config[CONF_RECIPIENT]
|
||||
self.sender: str = config[CONF_SENDER]
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
def send_message(self, message: str = "", **kwargs: Any) -> None:
|
||||
"""Send a message to a user."""
|
||||
data = {"messages": []}
|
||||
data: dict[str, Any] = {"messages": []}
|
||||
for recipient in self.recipients:
|
||||
data["messages"].append(
|
||||
{
|
||||
|
@ -91,7 +100,7 @@ class ClicksendNotificationService(BaseNotificationService):
|
|||
)
|
||||
|
||||
|
||||
def _authenticate(config):
|
||||
def _authenticate(config: ConfigType) -> bool:
|
||||
"""Authenticate with ClickSend."""
|
||||
api_url = f"{BASE_API_URL}/account"
|
||||
resp = requests.get(
|
||||
|
|
10
mypy.ini
10
mypy.ini
|
@ -532,6 +532,16 @@ disallow_untyped_defs = true
|
|||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.clicksend.*]
|
||||
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.cpuspeed.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
|
Loading…
Add table
Reference in a new issue