The Yonomi Platform SDK aims to lower the curve to getting an application connected to the Yonomi Platform and working with objects in the IoT domain. By simplifying the developer experience of the Platform API, the SDK will speed up development time for prototypes and full production solutions. It will make interacting with the platform a more enjoyable developer experience, and allow the developer to focus on problems specific to their application domain and not necessarily specific to the minutia of Yonomi’s implementation of GraphQL.
- Installing the SDK
- Setting up your environment
- Making requests to the platform
- Getting a list of all available integrations
- Retrieving all devices
- Trait-specific actions
- License
Open your pubspec.yaml
file and add the following entry under the dependencies
section:
dependencies:
yonomi_platform_sdk: ^5.2.1
Clone the latest source code to a directory of choice
git clone https://github.com/Yonomi/yonomi-sdk-dart.git
Build generated source files
cd yonomi-sdk-dart
flutter pub run build_runner build --delete-conflicting-outputs
Open your pubspec.yaml
file and add the following entry under the dependencies
section:
dependencies:
flutter:
sdk: flutter
yonomi_sdk_dart:
path: <checked_out_path>/yonomi-sdk-dart
You will be interacting with our platform using the following URL:
https://platform.yonomi.cloud/graphql
Pre-requisites: You will need to be set up with our platform
You will need a user ID, a tenant ID, and a private key to generate access tokens and make requests to the platform.
If you need guidance on obtaining any of these, please contact our sales team to help you get started using our platform.
Let's look at how we can leverage the Dart SDK to make requests to the platform.
Let's query our user info by following the steps below:
- Build Request object:
Request request = Request("YOUR-GRAPH-ENDPOINT-HERE",
{"Authorization": "Bearer YOUR-JWT-ACCESS-TOKEN-HERE"});
- Use UserRepository class to get our current user's information.
final userFromRequest = await UserRepository.getUserDetails(request);
- Now let's unwrap the
userFromRequest
object to display some useful data about our user:
print("My User ID: ${userFromRequest?.id}");
print("Date of my user's first activity: ${userFromRequest?.firstActivityAt}");
print("Date of my user's last activity: ${userFromRequest?.lastActivityAt}");
Pre-requisite: Make sure you've built a Request object (See step 1 in Making requests to the platform).
To get a list of all Integrations available in the platform:
final integrations = await AccountRepository.getAllIntegrations(request);
You will get a list of Integrations
{id: "INTEGRATION-ID-1", displayName: "An Integration"},
{id: "INTEGRATION-ID-2", displayName: "Another Integration"},
Pick an integration from the list that you are interested in and copy its ID.
We will add this integration into our account by generating a URL that lets us authenticate.
String generatedAccountUrl = await AccountRepository.generateAccountUrl("INTEGRATION-ID-1", request);
This call will return a String URL.
The app can navigate to this URL to authenticate and link the user's account.
Finally, to verify that the account was linked, we can retrieve a list of accounts that were authorized via the account linking flow:
AccountRepository.getLinkedAccounts(integrationId, request);
Verify that the account is in the list.
Pre-requisite: Make sure you've built a Request object (See step 1 in Making requests to the platform).
To retrieve a list of all available devices
DevicesRepository.getDevices(request);
You will get a list of devices, e.g.:
{
id: "DEVICE-ID-HERE",
displayName: "The device name",
description: "A description of this device",
manufacturerName: "The manufacturer of this device",
traits: [{
name: "THERMOSTAT_SETTING",
instance: "default",
...
}]
...
}
To get specific data for a particular device, use the getDeviceDetails
method:
DevicesRepository.getDeviceDetails(request, "DEVICE-ID-HERE");
If you have a device with a Thermostat
trait, you can use the getThermostatDetails
method to retrieve state data specific only to Thermostat devices, e.g.:
Device thermostatDevice = await DevicesRepository.getThermostatDetails(request, "DEVICE-ID-HERE");
To get the current target temperature, you can do the following:
print(thermostatDevice.traits.first.state.value);
To lock or unlock a device with a Lock trait, use the sendLockUnlockAction
method inside the LockRepository
class:
Example: If you wish to lock the device, set the last parameter to true
, otherwise, set it to false
.
LockRepository.sendLockUnlockAction(request, "YOUR-DEVICE-ID-HERE", true);
To set the Target Temperature of a device with the Thermostat trait, use the setPointThermostat
method inside the ThermostatRepository
class:
Example: Set the thermostat's target temperature to 23.0 C:
ThermostatRepository.setPointThermostat(request, "YOUR-DEVICE-ID-HERE", 23.0);
To set the Thermostat Mode of a device with the Thermostat trait, use the setMode
method:
Example: Set the Thermostat's Mode to AUTO:
ThermostatRepository.setMode(request, "YOUR-DEVICE-ID-HERE", ThermostatMode.auto);
You can pick from the following modes listed in the ThermostatMode enumerator:
{OFF, AUTO, HEAT, COOL, FANONLY, DEHUMIDIFY, AIRFLOW}
This application is released under the Apache license v2.0