diff --git a/.strict-typing b/.strict-typing index 6820472085a..5703c82fe93 100644 --- a/.strict-typing +++ b/.strict-typing @@ -187,6 +187,7 @@ homeassistant.components.logger.* homeassistant.components.lookin.* homeassistant.components.luftdaten.* homeassistant.components.mailbox.* +homeassistant.components.mastodon.* homeassistant.components.matter.* homeassistant.components.media_player.* homeassistant.components.media_source.* diff --git a/homeassistant/components/mastodon/__init__.py b/homeassistant/components/mastodon/__init__.py index 123d23afb80..6a9f074a9ba 100644 --- a/homeassistant/components/mastodon/__init__.py +++ b/homeassistant/components/mastodon/__init__.py @@ -1 +1 @@ -"""The mastodon component.""" +"""The Mastodon integration.""" diff --git a/homeassistant/components/mastodon/const.py b/homeassistant/components/mastodon/const.py new file mode 100644 index 00000000000..6fe9552f991 --- /dev/null +++ b/homeassistant/components/mastodon/const.py @@ -0,0 +1,9 @@ +"""Constants for the Mastodon integration.""" + +import logging +from typing import Final + +LOGGER = logging.getLogger(__name__) + +CONF_BASE_URL: Final = "base_url" +DEFAULT_URL: Final = "https://mastodon.social" diff --git a/homeassistant/components/mastodon/notify.py b/homeassistant/components/mastodon/notify.py index 058137393f5..8f259bc3433 100644 --- a/homeassistant/components/mastodon/notify.py +++ b/homeassistant/components/mastodon/notify.py @@ -1,5 +1,7 @@ """Mastodon platform for notify component.""" -import logging +from __future__ import annotations + +from typing import Any from mastodon import Mastodon from mastodon.Mastodon import MastodonAPIError, MastodonUnauthorizedError @@ -7,13 +9,11 @@ import voluptuous as vol from homeassistant.components.notify import PLATFORM_SCHEMA, BaseNotificationService from homeassistant.const import CONF_ACCESS_TOKEN, CONF_CLIENT_ID, CONF_CLIENT_SECRET -import homeassistant.helpers.config_validation as cv +from homeassistant.core import HomeAssistant +from homeassistant.helpers import config_validation as cv +from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -_LOGGER = logging.getLogger(__name__) - -CONF_BASE_URL = "base_url" - -DEFAULT_URL = "https://mastodon.social" +from .const import CONF_BASE_URL, DEFAULT_URL, LOGGER PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { @@ -25,7 +25,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( ) -def get_service(hass, config, discovery_info=None): +def get_service( + hass: HomeAssistant, + config: ConfigType, + discovery_info: DiscoveryInfoType | None = None, +) -> MastodonNotificationService | None: """Get the Mastodon notification service.""" client_id = config.get(CONF_CLIENT_ID) client_secret = config.get(CONF_CLIENT_SECRET) @@ -41,7 +45,7 @@ def get_service(hass, config, discovery_info=None): ) mastodon.account_verify_credentials() except MastodonUnauthorizedError: - _LOGGER.warning("Authentication failed") + LOGGER.warning("Authentication failed") return None return MastodonNotificationService(mastodon) @@ -50,13 +54,13 @@ def get_service(hass, config, discovery_info=None): class MastodonNotificationService(BaseNotificationService): """Implement the notification service for Mastodon.""" - def __init__(self, api): + def __init__(self, api: Mastodon) -> None: """Initialize the service.""" self._api = api - def send_message(self, message="", **kwargs): + def send_message(self, message: str = "", **kwargs: Any) -> None: """Send a message to a user.""" try: self._api.toot(message) except MastodonAPIError: - _LOGGER.error("Unable to send message") + LOGGER.error("Unable to send message") diff --git a/mypy.ini b/mypy.ini index 1076f4d5e63..3f439f18839 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1624,6 +1624,16 @@ disallow_untyped_defs = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.mastodon.*] +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.matter.*] check_untyped_defs = true disallow_incomplete_defs = true