Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be more strict with Mypy #293

Merged
merged 6 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
[mypy]
check_untyped_defs = True
disallow_untyped_defs = True
disallow_any_generics = True
warn_no_return = True
follow_imports = normal
ignore_missing_imports = True
namespace_packages = True
show_error_codes = True
python_version = 3.8
show_error_codes = true
follow_imports = silent
ignore_missing_imports = true
strict_equality = true
warn_incomplete_stub = true
warn_redundant_casts = true
warn_unused_configs = true
warn_unused_ignores = true
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
#disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true

[mypy-tests.*]
ignore_errors = True
38 changes: 23 additions & 15 deletions pyoverkiz/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import urllib.parse
from json import JSONDecodeError
from types import TracebackType
from typing import Any, Dict, List, Union
from typing import Any, Dict, List, Union, cast

import backoff
import boto3
Expand Down Expand Up @@ -68,12 +68,21 @@ async def refresh_listener(invocation: dict[str, Any]) -> None:
class OverkizClient:
"""Interface class for the Overkiz API"""

username: str
password: str
server: OverkizServer
setup: Setup | None
devices: list[Device]
gateways: list[Gateway]
event_listener_id: str | None
session: ClientSession

def __init__(
self,
username: str,
password: str,
server: OverkizServer,
session: ClientSession = None,
session: ClientSession | None = None,
) -> None:
"""
Constructor
Expand Down Expand Up @@ -196,13 +205,9 @@ async def nexity_login(self) -> str:
loop = asyncio.get_event_loop()

# Request access token
client = await loop.run_in_executor(
None,
lambda: boto3.client(
"cognito-idp", config=Config(region_name=NEXITY_COGNITO_REGION)
),
client = boto3.client(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tetienne why did this one get removed? This is currently breaking Nexity login.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a typing error, and cannot found someone using our syntax, while this one yes :S

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I resolved it in a new PR :)

"cognito-idp", config=Config(region_name=NEXITY_COGNITO_REGION)
)

aws = WarrantLite(
username=self.username,
password=self.password,
Expand All @@ -229,7 +234,7 @@ async def nexity_login(self) -> str:
if "token" not in token:
raise NexityServiceException("No Nexity SSO token provided.")

return token["token"]
return cast(str, token["token"])

@backoff.on_exception(
backoff.expo,
Expand Down Expand Up @@ -337,7 +342,7 @@ async def get_device_definition(self, deviceurl: str) -> JSON | None:
"""
Retrieve a particular setup device definition
"""
response = await self.__get(
response: dict = await self.__get(
f"setup/devices/{urllib.parse.quote_plus(deviceurl)}"
)

Expand Down Expand Up @@ -377,7 +382,7 @@ async def register_event_listener(self) -> str:
API on a regular basis.
"""
response = await self.__post("events/register")
listener_id = response.get("id")
listener_id = cast(str, response.get("id"))
self.event_listener_id = listener_id

return listener_id
Expand Down Expand Up @@ -441,7 +446,10 @@ async def execute_command(
"""Send a command"""
if isinstance(command, str):
command = Command(command)
return await self.execute_commands(device_url, [command], label)

response: str = await self.execute_commands(device_url, [command], label)

return response

@backoff.on_exception(
backoff.expo, NotAuthenticatedException, max_tries=2, on_backoff=relogin
Expand All @@ -464,8 +472,8 @@ async def execute_commands(
"label": label,
"actions": [{"deviceURL": device_url, "commands": commands}],
}
response = await self.__post("exec/apply", payload)
return response["execId"]
response: dict = await self.__post("exec/apply", payload)
return cast(str, response["execId"])

@backoff.on_exception(
backoff.expo,
Expand Down Expand Up @@ -496,7 +504,7 @@ async def get_places(self) -> Place:
async def execute_scenario(self, oid: str) -> str:
"""Execute a scenario"""
response = await self.__post(f"exec/{oid}")
return response["execId"]
return cast(str, response["execId"])

async def __get(self, path: str) -> Any:
"""Make a GET request to the OverKiz API"""
Expand Down
4 changes: 3 additions & 1 deletion pyoverkiz/const.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from pyoverkiz.models import OverkizServer

COZYTOUCH_ATLANTIC_API = "https://api.groupe-atlantic.com"
Expand All @@ -10,7 +12,7 @@
NEXITY_COGNITO_USER_POOL = "eu-west-1_wj277ucoI"
NEXITY_COGNITO_REGION = "eu-west-1"

SUPPORTED_SERVERS = {
SUPPORTED_SERVERS: dict[str, OverkizServer] = {
"atlantic_cozytouch": OverkizServer(
name="Atlantic Cozytouch",
endpoint="https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/",
Expand Down
12 changes: 9 additions & 3 deletions pyoverkiz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,15 @@ def __len__(self) -> int:
class State:
name: str
type: DataType
value: str | None = None
value: None | int | float | str | bool
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tetienne I think this was the mistake that messed up the core PR...


def __init__(self, name: str, type: int, value: str | None = None, **_: Any):
def __init__(
self,
name: str,
type: int,
value: None | int | float | str | bool = None,
**_: Any,
):
self.name = name
self.value = value
self.type = DataType(type)
Expand Down Expand Up @@ -307,7 +313,7 @@ def __len__(self) -> int:
get = __getitem__


class Command(dict): # type: ignore
class Command(dict):
"""Represents an OverKiz Command."""

def __init__(self, name: str, parameters: list[str] | None = None, **_: Any):
Expand Down