Skip to content
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <contact@ravaka.dev>"]
license = "MIT"
Expand Down
8 changes: 8 additions & 0 deletions switchbot_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from switchbot_api.commands import (
AirConditionerCommands,
AirPurifierCommands,
ArtFrameCommands,
BatteryCirculatorFanCommands,
BlindTiltCommands,
BotCommands,
Expand All @@ -30,9 +31,11 @@
FanCommands,
HumidifierCommands,
HumidifierV2Commands,
KeyPadCommands,
LightCommands,
LockCommands,
LockV2Commands,
LockV3Commands,
OthersCommands,
RGBWLightCommands,
RGBWWLightCommands,
Expand All @@ -54,6 +57,7 @@
)
from switchbot_api.models import (
BatteryCirculatorFanMode,
BatteryLevel,
PowerState,
SmartRadiatorThermostatMode,
VacuumCleanMode,
Expand All @@ -64,8 +68,10 @@
__all__ = [
"AirConditionerCommands",
"AirPurifierCommands",
"ArtFrameCommands",
"BatteryCirculatorFanCommands",
"BatteryCirculatorFanMode",
"BatteryLevel",
"BlindTiltCommands",
"BotCommands",
"CeilingLightCommands",
Expand All @@ -78,9 +84,11 @@
"FanCommands",
"HumidifierCommands",
"HumidifierV2Commands",
"KeyPadCommands",
"LightCommands",
"LockCommands",
"LockV2Commands",
"LockV3Commands",
"OthersCommands",
"PowerState",
"RGBWLightCommands",
Expand Down
16 changes: 15 additions & 1 deletion switchbot_api/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions switchbot_api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ class SwitchBotAuthenticationError(SwitchBotError):

class SwitchBotDeviceOfflineError(SwitchBotError):
"""Device currently offline."""


class SwitchBotDeviceRequestError(SwitchBotError):
"""Device request error."""
28 changes: 28 additions & 0 deletions switchbot_api/utils.py
Original file line number Diff line number Diff line change
@@ -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 <AI Art Frame> 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
Loading