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
10 changes: 2 additions & 8 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ install:
build:
poetry build

format:pre_commit
poetry run black switchbot_api/
poetry run mypy switchbot_api/
poetry run ruff check --fix switchbot_api/__init__.py
poetry run ruff check --output-format=github .
format:
poetry run pre-commit run --all-files

clean:
rm -rf dist
Expand All @@ -19,6 +16,3 @@ test:test_update

test_update:
pytest --snapshot-update

pre_commit:
poetry run pre-commit run end-of-file-fixer --all-files
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.8.0"
version = "2.9.0"
description = "An asynchronous library to use Switchbot API"
authors = ["Ravaka Razafimanantsoa <contact@ravaka.dev>"]
license = "MIT"
Expand Down
66 changes: 50 additions & 16 deletions switchbot_api/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ class RGBWLightCommands(Commands):

# Supported Device list:
# Strip Light
# RGBIC Neon Rope Light
# RGBIC Neon Wire Rope Light
SET_BRIGHTNESS = "setBrightness"
SET_COLOR = "setColor"

@classmethod
def get_supported_devices(cls) -> list[str]:
"""Get supported devices."""
return ["Strip Light"]
return ["Strip Light", "RGBIC Neon Rope Light", "RGBIC Neon Wire Rope Light"]


class RGBWWLightCommands(Commands):
Expand All @@ -206,14 +208,48 @@ class RGBWWLightCommands(Commands):
# Floor Lamp
# Strip Light 3
# Color Bulb
# RGBICWW Floor Lamp
# RGBICWW Strip Light
SET_BRIGHTNESS = "setBrightness"
SET_COLOR = "setColor"
SET_COLOR_TEMPERATURE = "setColorTemperature"

@classmethod
def get_supported_devices(cls) -> list[str]:
"""Get supported devices."""
return ["Strip Light 3", "Floor Lamp", "Color Bulb"]
return [
"Strip Light 3",
"Floor Lamp",
"Color Bulb",
"RGBICWW Floor Lamp",
"RGBICWW Strip Light",
]


class CeilingLightCommands(Commands):
"""Ceiling light commands."""

# 1-100
SET_BRIGHTNESS = "setBrightness"
# 2700-6500
SET_COLOR_TEMPERATURE = "setColorTemperature"

@classmethod
def get_supported_devices(cls) -> list[str]:
"""Get supported devices."""
return ["Ceiling Light", "Ceiling Light Pro"]


class ArtFrameCommands(Commands):
"""AI Art Frame commands."""

PREVIOUS = "previous"
NEXT = "next"

@classmethod
def get_supported_devices(cls) -> list[str]:
"""Get supported devices."""
return ["AI Art Frame"]


class DoorBellCommands(Commands):
Expand Down Expand Up @@ -285,20 +321,6 @@ def get_supported_devices(cls) -> list[str]:
return ["Robot Vacuum Cleaner S10", "S20"]


class CeilingLightCommands(Commands):
"""Ceiling light commands."""

# 1-100
SET_BRIGHTNESS = "setBrightness"
# 2700-6500
SET_COLOR_TEMPERATURE = "setColorTemperature"

@classmethod
def get_supported_devices(cls) -> list[str]:
"""Get supported devices."""
return ["Ceiling Light", "Ceiling Light Pro"]


class BlindTiltCommands(Commands):
"""Blind Tilt commands."""

Expand Down Expand Up @@ -396,4 +418,16 @@ def get_supported_devices(cls) -> list[str]:
return ["Smart Radiator Thermostat"]


class KeyPadCommands(Commands):
"""Keypad commands."""

DELETE_KEY = "deleteKey"
CREATE_KEY = "createKey"

@classmethod
def get_supported_devices(cls) -> list[str]:
"""Get supported devices."""
return ["Keypad", "Keypad Touch", "Keypad Vision", "Keypad Vision pro"]


T = TypeVar("T", bound=CommonCommands)
23 changes: 23 additions & 0 deletions switchbot_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,26 @@ def get_all_modes(cls) -> list[SmartRadiatorThermostatMode]:
cls.COMFORT,
cls.FAST_HEATING,
]


class BatteryLevel(Enum):
"""Battery Level modes."""

High = "high"
Medium = "medium"
Low = "low"
Critical = "critical"
Unknown = "unknown"

@classmethod
def get_battery_level(cls, value: int) -> BatteryLevel:
"""Return a battery level."""
if 100 >= value >= 60:
return cls.High
if 60 > value >= 20:
return cls.Medium
if 20 > value >= 10:
return cls.Low
if 10 > value >= 0:
return cls.Critical
return cls.Unknown
Loading