Skip to content

Commit

Permalink
Add method to fetch capability schema (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Feb 15, 2025
1 parent 31c7055 commit 2c1e177
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/pysmartthings/smartthings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from aiohttp.hdrs import METH_DELETE, METH_GET, METH_POST, METH_PUT
from yarl import URL

from . import SmartThingsAuthenticationFailedError
from .const import API_BASE
from .exceptions import SmartThingsCommandError, SmartThingsConnectionError
from .models import (
Expand Down Expand Up @@ -97,6 +98,10 @@ async def _request(

text = await response.text()

if response.status == 401:
msg = "Authentication failed with SmartThings"
raise SmartThingsAuthenticationFailedError(msg)

if response.status == 422:
raise SmartThingsCommandError(ErrorResponse.from_json(text))

Expand Down Expand Up @@ -195,6 +200,10 @@ async def get_device_status(
resp = await self._get(f"devices/{device_id}/status")
return DeviceStatus.from_json(resp).components

async def get_capability(self, capability: Capability | str) -> str:
"""Retrieve the capability schema."""
return await self._get(f"capabilities/{capability}/1")

async def execute_device_command(
self,
device_id: str,
Expand Down

0 comments on commit 2c1e177

Please sign in to comment.