diff --git a/pyproject.toml b/pyproject.toml index 15694e0..ba55e8b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "switchbot_api" -version = "2.9.0" +version = "2.10.0" description = "An asynchronous library to use Switchbot API" authors = ["Ravaka Razafimanantsoa "] license = "MIT" diff --git a/switchbot_api/__init__.py b/switchbot_api/__init__.py index 3717f77..a3b869e 100644 --- a/switchbot_api/__init__.py +++ b/switchbot_api/__init__.py @@ -18,6 +18,7 @@ from switchbot_api.commands import ( AirConditionerCommands, AirPurifierCommands, + ArtFrameCommands, BatteryCirculatorFanCommands, BlindTiltCommands, BotCommands, @@ -30,9 +31,11 @@ FanCommands, HumidifierCommands, HumidifierV2Commands, + KeyPadCommands, LightCommands, LockCommands, LockV2Commands, + LockV3Commands, OthersCommands, RGBWLightCommands, RGBWWLightCommands, @@ -54,6 +57,7 @@ ) from switchbot_api.models import ( BatteryCirculatorFanMode, + BatteryLevel, PowerState, SmartRadiatorThermostatMode, VacuumCleanMode, @@ -64,8 +68,10 @@ __all__ = [ "AirConditionerCommands", "AirPurifierCommands", + "ArtFrameCommands", "BatteryCirculatorFanCommands", "BatteryCirculatorFanMode", + "BatteryLevel", "BlindTiltCommands", "BotCommands", "CeilingLightCommands", @@ -78,9 +84,11 @@ "FanCommands", "HumidifierCommands", "HumidifierV2Commands", + "KeyPadCommands", "LightCommands", "LockCommands", "LockV2Commands", + "LockV3Commands", "OthersCommands", "PowerState", "RGBWLightCommands", diff --git a/switchbot_api/commands.py b/switchbot_api/commands.py index f2f25e5..7747498 100644 --- a/switchbot_api/commands.py +++ b/switchbot_api/commands.py @@ -93,7 +93,21 @@ class LockV2Commands(Commands): @classmethod def get_supported_devices(cls) -> list[str]: """Get supported devices.""" - return ["Smart Lock", "Smart Lock Pro", "Smart Lock Ultra"] + return ["Smart Lock", "Smart Lock Pro", "Smart Lock Ultra", "Smart Lock Vision"] + + +class LockV3Commands(Commands): + """Lock commands.""" + + LOCK = "lock" + UNLOCK = "unlock" + DEADBOLT = "deadbolt" + NIGHT_LATCH_UNLOCK = "nightLatchUnlock" + + @classmethod + def get_supported_devices(cls) -> list[str]: + """Get supported devices.""" + return ["Smart Lock Vision Pro"] class HumidifierCommands(Commands): diff --git a/switchbot_api/exceptions.py b/switchbot_api/exceptions.py index 5de28b8..bd91ec9 100644 --- a/switchbot_api/exceptions.py +++ b/switchbot_api/exceptions.py @@ -15,3 +15,7 @@ class SwitchBotAuthenticationError(SwitchBotError): class SwitchBotDeviceOfflineError(SwitchBotError): """Device currently offline.""" + + +class SwitchBotDeviceRequestError(SwitchBotError): + """Device request error.""" diff --git a/switchbot_api/utils.py b/switchbot_api/utils.py new file mode 100644 index 0000000..f8e068b --- /dev/null +++ b/switchbot_api/utils.py @@ -0,0 +1,28 @@ +"""util for SwitchBot API.""" + +import aiohttp +from aiohttp import ClientResponse + +from .exceptions import SwitchBotDeviceRequestError + + +def check_response_status(response: ClientResponse) -> None: + """Check https response status.""" + if response.status != 200: + msg = f"status code != 200 (actual: {response.status})" + raise SwitchBotDeviceRequestError(msg) + + +async def get_file_stream_from_cloud(url: str, timeout: float = 5) -> bytes: + """Get file stream from cloud.""" + # now only for download Picture + try: + async with ( + aiohttp.ClientSession() as session, + session.get(url, timeout=aiohttp.ClientTimeout(total=timeout)) as response, + ): + check_response_status(response) + return await response.read() + except Exception as e: + msg = f"{e}" + raise SwitchBotDeviceRequestError(msg) from e