Complete remember the milk typing (#139123)

This commit is contained in:
Martin Hjelmare 2025-02-23 19:59:10 +01:00 committed by GitHub
parent 6ad6e82a23
commit 8f9f9bc8e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 41 additions and 11 deletions

View File

@ -407,6 +407,7 @@ homeassistant.components.raspberry_pi.*
homeassistant.components.rdw.* homeassistant.components.rdw.*
homeassistant.components.recollect_waste.* homeassistant.components.recollect_waste.*
homeassistant.components.recorder.* homeassistant.components.recorder.*
homeassistant.components.remember_the_milk.*
homeassistant.components.remote.* homeassistant.components.remote.*
homeassistant.components.renault.* homeassistant.components.renault.*
homeassistant.components.reolink.* homeassistant.components.reolink.*

View File

@ -75,8 +75,14 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
def _create_instance( def _create_instance(
hass, account_name, api_key, shared_secret, token, stored_rtm_config, component hass: HomeAssistant,
): account_name: str,
api_key: str,
shared_secret: str,
token: str,
stored_rtm_config: RememberTheMilkConfiguration,
component: EntityComponent[RememberTheMilkEntity],
) -> None:
entity = RememberTheMilkEntity( entity = RememberTheMilkEntity(
account_name, api_key, shared_secret, token, stored_rtm_config account_name, api_key, shared_secret, token, stored_rtm_config
) )
@ -96,9 +102,13 @@ def _create_instance(
def _register_new_account( def _register_new_account(
hass, account_name, api_key, shared_secret, stored_rtm_config, component hass: HomeAssistant,
): account_name: str,
request_id = None api_key: str,
shared_secret: str,
stored_rtm_config: RememberTheMilkConfiguration,
component: EntityComponent[RememberTheMilkEntity],
) -> None:
api = Rtm(api_key, shared_secret, "write", None) api = Rtm(api_key, shared_secret, "write", None)
url, frob = api.authenticate_desktop() url, frob = api.authenticate_desktop()
LOGGER.debug("Sent authentication request to server") LOGGER.debug("Sent authentication request to server")

View File

@ -7,12 +7,20 @@ from homeassistant.core import ServiceCall
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from .const import LOGGER from .const import LOGGER
from .storage import RememberTheMilkConfiguration
class RememberTheMilkEntity(Entity): class RememberTheMilkEntity(Entity):
"""Representation of an interface to Remember The Milk.""" """Representation of an interface to Remember The Milk."""
def __init__(self, name, api_key, shared_secret, token, rtm_config): def __init__(
self,
name: str,
api_key: str,
shared_secret: str,
token: str,
rtm_config: RememberTheMilkConfiguration,
) -> None:
"""Create new instance of Remember The Milk component.""" """Create new instance of Remember The Milk component."""
self._name = name self._name = name
self._api_key = api_key self._api_key = api_key
@ -20,11 +28,11 @@ class RememberTheMilkEntity(Entity):
self._token = token self._token = token
self._rtm_config = rtm_config self._rtm_config = rtm_config
self._rtm_api = Rtm(api_key, shared_secret, "delete", token) self._rtm_api = Rtm(api_key, shared_secret, "delete", token)
self._token_valid = None self._token_valid = False
self._check_token() self._check_token()
LOGGER.debug("Instance created for account %s", self._name) LOGGER.debug("Instance created for account %s", self._name)
def _check_token(self): def _check_token(self) -> bool:
"""Check if the API token is still valid. """Check if the API token is still valid.
If it is not valid any more, delete it from the configuration. This If it is not valid any more, delete it from the configuration. This
@ -127,12 +135,12 @@ class RememberTheMilkEntity(Entity):
) )
@property @property
def name(self): def name(self) -> str:
"""Return the name of the device.""" """Return the name of the device."""
return self._name return self._name
@property @property
def state(self): def state(self) -> str:
"""Return the state of the device.""" """Return the state of the device."""
if not self._token_valid: if not self._token_valid:
return "API token invalid" return "API token invalid"

View File

@ -4,6 +4,7 @@ from __future__ import annotations
import json import json
from pathlib import Path from pathlib import Path
from typing import cast
from homeassistant.const import CONF_TOKEN from homeassistant.const import CONF_TOKEN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -51,7 +52,7 @@ class RememberTheMilkConfiguration:
def get_token(self, profile_name: str) -> str | None: def get_token(self, profile_name: str) -> str | None:
"""Get the server token for a profile.""" """Get the server token for a profile."""
if profile_name in self._config: if profile_name in self._config:
return self._config[profile_name][CONF_TOKEN] return cast(str, self._config[profile_name][CONF_TOKEN])
return None return None
def set_token(self, profile_name: str, token: str) -> None: def set_token(self, profile_name: str, token: str) -> None:

10
mypy.ini generated
View File

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