yonomi_platform_sdk 5.0.0 yonomi_platform_sdk: ^5.0.0 copied to clipboard
Flutter SDK for Yonomi Platform
Yonomi Dart SDK #
Flutter SDK for Yonomi Platform
Table of contents #
- 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
Getting Started #
Installing the SDK #
Open your pubspec.yaml
file and add the following entry under the dependencies
section:
dependencies:
flutter:
sdk: flutter
yonomi_sdk_dart: ^1.0.0
Setting up your environment #
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.
Making requests to the 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}");
Getting a list of all available Integrations #
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.
Retrieving all devices #
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);
Trait-specific actions #
Lock Trait
Action: Lock or Unlock
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);
Thermostat Trait
Action: Set Target Temperature
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);
Action: Set Thermostat Mode
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}
License #
This application is released under the Apache license v2.0