Skip to content

Commit

Permalink
Enable ANN201 rule (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Feb 6, 2025
1 parent f810148 commit cf55bad
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 96 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ asyncio_mode = "auto"
[tool.ruff.lint]
ignore = [
"ANN401", # Opinioated warning on disallowing dynamically typed expressions
"ANN201",
"ANN204",
"ANN202",
"DTZ005",
Expand Down
2 changes: 1 addition & 1 deletion script/generate_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pysmartthings.capability import ATTRIBUTES


def main():
def main() -> None:
"""Run the script."""
attribs = list(ATTRIBUTES)
attribs.sort()
Expand Down
2 changes: 1 addition & 1 deletion script/generate_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pysmartthings.capability import CAPABILITIES


def main():
def main() -> None:
"""Run the script."""
capabilities = CAPABILITIES.copy()
capabilities.sort()
Expand Down
74 changes: 48 additions & 26 deletions src/pysmartthings/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ async def get_room(self, location_id: str, room_id: str) -> dict:
"""
return await self.get(API_ROOM.format(location_id=location_id, room_id=room_id))

async def create_room(self, location_id: str, data: dict):
async def create_room(self, location_id: str, data: dict) -> dict[str, Any] | None:
"""Create a room.
This API call is undocumented.
"""
return await self.post(API_ROOMS.format(location_id=location_id), data)

async def update_room(self, location_id: str, room_id: str, data: dict):
async def update_room(
self, location_id: str, room_id: str, data: dict
) -> dict[str, Any] | None:
"""Update a room.
This API call is undocumented.
Expand All @@ -93,7 +95,9 @@ async def update_room(self, location_id: str, room_id: str, data: dict):
API_ROOM.format(location_id=location_id, room_id=room_id), data
)

async def delete_room(self, location_id: str, room_id: str):
async def delete_room(
self, location_id: str, room_id: str
) -> dict[str, Any] | None:
"""Delete a room.
This API call is undocumented.
Expand All @@ -102,14 +106,14 @@ async def delete_room(self, location_id: str, room_id: str):
API_ROOM.format(location_id=location_id, room_id=room_id)
)

async def get_devices(self, params: Optional = None) -> dict:
async def get_devices(self, params: Optional = None) -> dict[str, Any] | None:
"""Get the device definitions.
https://smartthings.developer.samsung.com/docs/api-ref/st-api.html#operation/getDevices
"""
return await self.get_items(API_DEVICES, params=params)

async def get_device(self, device_id: str) -> dict:
async def get_device(self, device_id: str) -> dict[str, Any] | None:
"""Get as specific device.
https://smartthings.developer.samsung.com/docs/api-ref/st-api.html#operation/getDevice
Expand Down Expand Up @@ -174,42 +178,46 @@ async def update_app(self, app_id: str, data: dict) -> dict:
"""
return await self.put(API_APP.format(app_id=app_id), data)

async def delete_app(self, app_id: str):
async def delete_app(self, app_id: str) -> dict[str, Any] | None:
"""Delete an app.
https://smartthings.developer.samsung.com/develop/api-ref/st-api.html#operation/deleteApp
"""
return await self.delete(API_APP.format(app_id=app_id))

async def get_app_settings(self, app_id: str) -> dict:
async def get_app_settings(self, app_id: str) -> dict[str, Any] | None:
"""Get an app's settings.
https://smartthings.developer.samsung.com/docs/api-ref/st-api.html#operation/getAppSettings
"""
return await self.get(API_APP_SETTINGS.format(app_id=app_id))

async def update_app_settings(self, app_id: str, data: dict) -> dict:
async def update_app_settings(
self, app_id: str, data: dict
) -> dict[str, Any] | None:
"""Update an app's settings.
https://smartthings.developer.samsung.com/docs/api-ref/st-api.html#operation/updateAppSettings
"""
return await self.put(API_APP_SETTINGS.format(app_id=app_id), data)

async def get_app_oauth(self, app_id: str) -> dict:
async def get_app_oauth(self, app_id: str) -> dict[str, Any] | None:
"""Get an app's oauth settings.
https://smartthings.developer.samsung.com/develop/api-ref/st-api.html#operation/getAppOauth
"""
return await self.get(API_APP_OAUTH.format(app_id=app_id))

async def update_app_oauth(self, app_id: str, data: dict) -> dict:
async def update_app_oauth(self, app_id: str, data: dict) -> dict[str, Any] | None:
"""Update an app's oauth settings.
https://smartthings.developer.samsung.com/develop/api-ref/st-api.html#operation/updateAppOauth
"""
return await self.put(API_APP_OAUTH.format(app_id=app_id), data)

async def generate_app_oauth(self, app_id: str, data: dict) -> dict:
async def generate_app_oauth(
self, app_id: str, data: dict
) -> dict[str, Any] | None:
"""Generate a new app oauth client/secret.
https://smartthings.developer.samsung.com/docs/api-ref/st-api.html#operation/generateAppOauth
Expand All @@ -223,7 +231,7 @@ async def get_installed_apps(self, params: Optional = None) -> dict:
"""
return await self.get_items(API_INSTALLEDAPPS, params=params)

async def get_installed_app(self, installed_app_id: str) -> dict:
async def get_installed_app(self, installed_app_id: str) -> dict[str, Any] | None:
"""Get the details of the specific installedapp.
https://smartthings.developer.samsung.com/docs/api-ref/st-api.html#operation/getInstallation
Expand All @@ -232,7 +240,9 @@ async def get_installed_app(self, installed_app_id: str) -> dict:
API_INSTALLEDAPP.format(installed_app_id=installed_app_id)
)

async def delete_installed_app(self, installed_app_id: str):
async def delete_installed_app(
self, installed_app_id: str
) -> dict[str, Any] | None:
"""Delete an app.
https://smartthings.developer.samsung.com/docs/api-ref/st-api.html#operation/deleteInstallation
Expand All @@ -241,7 +251,7 @@ async def delete_installed_app(self, installed_app_id: str):
API_INSTALLEDAPP.format(installed_app_id=installed_app_id)
)

async def get_subscriptions(self, installed_app_id: str) -> dict:
async def get_subscriptions(self, installed_app_id: str) -> dict[str, Any] | None:
"""Get installedapp's subscriptions.
https://smartthings.developer.samsung.com/develop/api-ref/st-api.html#operation/listSubscriptions
Expand All @@ -250,7 +260,9 @@ async def get_subscriptions(self, installed_app_id: str) -> dict:
API_SUBSCRIPTIONS.format(installed_app_id=installed_app_id)
)

async def create_subscription(self, installed_app_id: str, data: dict) -> dict:
async def create_subscription(
self, installed_app_id: str, data: dict
) -> dict[str, Any] | None:
"""Create a subscription for an installedapp.
https://smartthings.developer.samsung.com/develop/api-ref/st-api.html#operation/saveSubscription
Expand All @@ -259,7 +271,9 @@ async def create_subscription(self, installed_app_id: str, data: dict) -> dict:
API_SUBSCRIPTIONS.format(installed_app_id=installed_app_id), data
)

async def delete_all_subscriptions(self, installed_app_id: str) -> dict:
async def delete_all_subscriptions(
self, installed_app_id: str
) -> dict[str, Any] | None:
"""Delete all subscriptions for an installedapp.
https://smartthings.developer.samsung.com/develop/api-ref/st-api.html#operation/deleteAllSubscriptions
Expand All @@ -270,7 +284,7 @@ async def delete_all_subscriptions(self, installed_app_id: str) -> dict:

async def get_subscription(
self, installed_app_id: str, subscription_id: str
) -> dict:
) -> dict[str, Any] | None:
"""Get an individual subscription.
https://smartthings.developer.samsung.com/develop/api-ref/st-api.html#operation/getSubscription
Expand All @@ -281,7 +295,9 @@ async def get_subscription(
)
)

async def delete_subscription(self, installed_app_id: str, subscription_id: str):
async def delete_subscription(
self, installed_app_id: str, subscription_id: str
) -> dict[str, Any] | None:
"""Delete an individual subscription.
https://smartthings.developer.samsung.com/develop/api-ref/st-api.html#operation/deleteSubscription
Expand All @@ -292,7 +308,7 @@ async def delete_subscription(self, installed_app_id: str, subscription_id: str)
)
)

async def get_scenes(self, params: Optional = None):
async def get_scenes(self, params: Optional = None) -> dict[str, Any] | None:
"""Get scenes.
https://smartthings.developer.samsung.com/develop/api-ref/st-api.html#operation/listScenes
Expand Down Expand Up @@ -332,7 +348,7 @@ async def request(
url: str,
params: dict | None = None,
data: dict | None = None,
):
) -> dict[str, Any] | None:
"""Perform a request against the specified parameters."""
async with self._session.request(
method,
Expand All @@ -358,11 +374,15 @@ async def request(
resp.raise_for_status()
return None

async def get(self, resource: str, *, params: dict | None = None):
async def get(
self, resource: str, *, params: dict | None = None
) -> dict[str, Any] | None:
"""Get a resource."""
return await self.request("get", self._api_base + resource, params)

async def get_items(self, resource: str, *, params: dict | None = None):
async def get_items(
self, resource: str, *, params: dict | None = None
) -> dict[str, Any] | None:
"""Perform requests for a list of items that may have pages."""
resp = await self.request("get", self._api_base + resource, params, None)
items = resp.get("items", [])
Expand All @@ -373,21 +393,23 @@ async def get_items(self, resource: str, *, params: dict | None = None):
next_link = Api._get_next_link(resp)
return items

async def post(self, resource: str, data: Sequence | None):
async def post(self, resource: str, data: Sequence | None) -> dict[str, Any] | None:
"""Perform a post request."""
return await self.request("post", self._api_base + resource, data=data)

async def put(self, resource: str, data: Sequence | None):
async def put(self, resource: str, data: Sequence | None) -> dict[str, Any] | None:
"""Perform a put request."""
return await self.request("put", self._api_base + resource, data=data)

async def delete(self, resource: str, *, params: dict | None = None):
async def delete(
self, resource: str, *, params: dict | None = None
) -> dict[str, Any] | None:
"""Delete a resource."""
return await self.request("delete", self._api_base + resource, params)

async def generate_tokens(
self, client_id: str, client_secret: str, refresh_token: str
):
) -> dict[str, Any] | None:
"""Obtain a new access and refresh token."""
payload = {"grant_type": "refresh_token", "refresh_token": refresh_token}
async with self._session.request(
Expand Down
22 changes: 11 additions & 11 deletions src/pysmartthings/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self):
self._created_date = None
self._last_updated_date = None

def apply_data(self, data: dict):
def apply_data(self, data: dict) -> None:
"""Set the states of the app with the supplied data."""
self._app_name = data["appName"]
self._app_id = data["appId"]
Expand Down Expand Up @@ -74,12 +74,12 @@ def app_id(self) -> str:
return self._app_id

@property
def created_date(self):
def created_date(self) -> str:
"""Get the created date of the app."""
return self._created_date

@property
def last_updated_date(self):
def last_updated_date(self) -> str:
"""Get the last updated date of the app."""
return self._last_updated_date

Expand Down Expand Up @@ -117,7 +117,7 @@ def display_name(self) -> str:
return self._display_name

@display_name.setter
def display_name(self, value: str):
def display_name(self, value: str) -> None:
"""Set the display name."""
if not value:
msg = "value cannot be None or zero length."
Expand Down Expand Up @@ -219,7 +219,7 @@ def __init__(self, app_id: str):
self._app_id = app_id
self._settings = {}

def apply_data(self, data: dict):
def apply_data(self, data: dict) -> None:
"""Set the states of the app with the supplied data."""
self._settings = data.get("settings", {})

Expand All @@ -228,7 +228,7 @@ def to_data(self) -> dict:
return {"settings": self._settings}

@property
def app_id(self):
def app_id(self) -> str:
"""Get the associated app id."""
return self._app_id

Expand Down Expand Up @@ -285,7 +285,7 @@ def to_data(self) -> dict:
"""Get a data representation of the instance."""
return {"clientName": self._client_name, "scope": self._scope}

def apply_data(self, data: dict):
def apply_data(self, data: dict) -> None:
"""Load the data of the instance."""
self._client_name = data["clientName"]
self._scope = data.get("scope", self._scope)
Expand Down Expand Up @@ -380,18 +380,18 @@ def __init__(self, data: dict | None):
if data:
self.apply_data(data)

def apply_data(self, data: dict):
def apply_data(self, data: dict) -> None:
"""Apply the given data to the entity."""
self._client_id = data["oauthClientId"]
self._client_secret = data["oauthClientSecret"]

@property
def client_id(self):
def client_id(self) -> str:
"""Get the client id."""
return self._client_id

@property
def client_secret(self):
def client_secret(self) -> str:
"""Get the client secret."""
return self._client_secret

Expand All @@ -404,7 +404,7 @@ def __init__(self, api: Api, app_id: str, data: dict | None):
self._client_details = AppOAuthEntity(api, app_id, None)
super().__init__(data)

def apply_data(self, data: dict):
def apply_data(self, data: dict) -> None:
"""Apply the given data to the entity."""
super().apply_data(data)
self._client_details.apply_data(data["oauthClientDetails"])
Expand Down
Loading

0 comments on commit cf55bad

Please sign in to comment.