Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seo-4d696b75/switchbot_api_dio
A simple client of SwitchBotAPI v1.1 implemented by dio library
https://github.com/seo-4d696b75/switchbot_api_dio
Last synced: about 1 month ago
JSON representation
A simple client of SwitchBotAPI v1.1 implemented by dio library
- Host: GitHub
- URL: https://github.com/seo-4d696b75/switchbot_api_dio
- Owner: Seo-4d696b75
- License: bsd-3-clause
- Created: 2023-09-27T12:19:21.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-30T12:16:09.000Z (about 1 year ago)
- Last Synced: 2023-10-31T12:40:54.626Z (about 1 year ago)
- Language: Dart
- Size: 126 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# switchbot_api_dio
[![Pub](https://img.shields.io/pub/v/switchbot_api_dio.svg)](https://pub.dev/packages/switchbot_api_dio)
[![test](https://github.com/Seo-4d696b75/switchbot_api_dio/actions/workflows/test.yaml/badge.svg)](https://github.com/Seo-4d696b75/switchbot_api_dio/actions/workflows/test.yaml)A simple implementation of [SwitchBotAPI (v1.1)](https://github.com/OpenWonderLabs/SwitchBotAPI)
client with [dio library](https://pub.dev/packages/dio).**Note**: This is a 3rd party library
## Features
- ✅ Get device list
- ✅ Get device status
- ✅ Send device control command
- ✅ Get scene list
- ✅ Execute manual scenes
- ❌ WebhookDetails of each API endpoint are described
in [SwitchBotAPI docs](https://github.com/OpenWonderLabs/SwitchBotAPI/blob/main/README.md).## Getting started
Add `switchbot_api_dio` package to your pubspec dependencies.
## Usage
### Initialize client
User token and secret are required for api authorization.
These credentials are available in developer options of SwitchBot official app.
[Please follow the steps described in SwitchBotAPI docs.](https://github.com/OpenWonderLabs/SwitchBotAPI/tree/main#getting-started)```dart
import 'package:switchbot_api_dio/switchbot_api_dio.dart';final api = SwitchBotApi(
userToken: 'token',
userSecret: 'secret',
);
```### Get devices and send control command
```dart
void main() async {
final collection = await api.getDevices();
// A list of physical devices
print(collection.deviceList);
// A list of virtual infrared remote devices
print(collection.infraredRemoteList);// Almost all devices support 'turnOn' command
await api.controlVirtualDevice(
device: collection.infraredRemoteList[0],
command: VirtualDeviceCommand.turnOn(),
);
// Send 'press' command to physical device 'Bot'
await api.controlPhysicalDevice(
device: collection.deviceList[0],
command: PhysicalDeviceCommand.bot.press(),
);
}
```### Get manual scenes and execute
```dart
void main() async {
final scenes = await api.getScenes();
await api.executeScene(sceneId: scenes[0].id);
}
```### Error handling
```dart
void main() async {
try {
await api.getDevices();
} on SwitchBotException catch (e) {
// Depending on the type of error,
// each subclass of `SwitchBotException` will be thrown
print(e);
}
}
```