Skip to content
Permalink
Browse files
Add clicksend to strict typing (#79544)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
  • Loading branch information
yuvalabou and cdce8p committed Oct 5, 2022
1 parent 41d2ab5 commit 5674295b3cd50536a18f08c6baa72d651b5dbd46
Show file tree
Hide file tree
Showing 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 @@
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 @@
)


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 @@ def send_message(self, message="", **kwargs):
)


def _authenticate(config):
def _authenticate(config: ConfigType) -> bool:
"""Authenticate with ClickSend."""
api_url = f"{BASE_API_URL}/account"
resp = requests.get(
@@ -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

0 comments on commit 5674295

Please sign in to comment.