Add clicksend to strict typing (#79544)

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
This commit is contained in:
Yuval Aboulafia 2022-10-05 23:18:41 +03:00 committed by GitHub
parent 41d2ab5b37
commit 5674295b3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 9 deletions

View file

@ -78,6 +78,7 @@ homeassistant.components.camera.*
homeassistant.components.canary.* homeassistant.components.canary.*
homeassistant.components.cover.* homeassistant.components.cover.*
homeassistant.components.clickatell.* homeassistant.components.clickatell.*
homeassistant.components.clicksend.*
homeassistant.components.cpuspeed.* homeassistant.components.cpuspeed.*
homeassistant.components.crownstone.* homeassistant.components.crownstone.*
homeassistant.components.deconz.* homeassistant.components.deconz.*

View file

@ -1,7 +1,10 @@
"""Clicksend platform for notify component.""" """Clicksend platform for notify component."""
from __future__ import annotations
from http import HTTPStatus from http import HTTPStatus
import json import json
import logging import logging
from typing import Any
import requests import requests
import voluptuous as vol import voluptuous as vol
@ -14,7 +17,9 @@ from homeassistant.const import (
CONF_USERNAME, CONF_USERNAME,
CONTENT_TYPE_JSON, CONTENT_TYPE_JSON,
) )
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
_LOGGER = logging.getLogger(__name__) _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.""" """Get the ClickSend notification service."""
if not _authenticate(config): if not _authenticate(config):
_LOGGER.error("You are not authorized to access ClickSend") _LOGGER.error("You are not authorized to access ClickSend")
@ -52,16 +61,16 @@ def get_service(hass, config, discovery_info=None):
class ClicksendNotificationService(BaseNotificationService): class ClicksendNotificationService(BaseNotificationService):
"""Implementation of a notification service for the ClickSend service.""" """Implementation of a notification service for the ClickSend service."""
def __init__(self, config): def __init__(self, config: ConfigType) -> None:
"""Initialize the service.""" """Initialize the service."""
self.username = config[CONF_USERNAME] self.username: str = config[CONF_USERNAME]
self.api_key = config[CONF_API_KEY] self.api_key: str = config[CONF_API_KEY]
self.recipients = config[CONF_RECIPIENT] self.recipients: list[str] = config[CONF_RECIPIENT]
self.sender = config[CONF_SENDER] 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.""" """Send a message to a user."""
data = {"messages": []} data: dict[str, Any] = {"messages": []}
for recipient in self.recipients: for recipient in self.recipients:
data["messages"].append( data["messages"].append(
{ {
@ -91,7 +100,7 @@ class ClicksendNotificationService(BaseNotificationService):
) )
def _authenticate(config): def _authenticate(config: ConfigType) -> bool:
"""Authenticate with ClickSend.""" """Authenticate with ClickSend."""
api_url = f"{BASE_API_URL}/account" api_url = f"{BASE_API_URL}/account"
resp = requests.get( resp = requests.get(

View file

@ -532,6 +532,16 @@ disallow_untyped_defs = true
warn_return_any = true warn_return_any = true
warn_unreachable = 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.*] [mypy-homeassistant.components.cpuspeed.*]
check_untyped_defs = true check_untyped_defs = true
disallow_incomplete_defs = true disallow_incomplete_defs = true