yonomi_platform_sdk

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

yonomi platform sdk

Yonomi Dart SDK #




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.

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 #
From pub.dev
Open your pubspec.yaml file and add the following entry under the dependencies section:
dependencies:
flutter:
sdk: flutter

yonomi_sdk_dart: ^1.0.0
copied to clipboard
From source
Clone the latest source code to a directory of choice
git clone https://github.com/Yonomi/yonomi-sdk-dart.git
copied to clipboard
Build generated source files
cd yonomi-sdk-dart
flutter pub run build_runner build --delete-conflicting-outputs
copied to clipboard
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
copied to clipboard
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"});
copied to clipboard

Use UserRepository class to get our current user's information.

final userFromRequest = await UserRepository.getUserDetails(request);
copied to clipboard

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}");
copied to clipboard
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);
copied to clipboard
You will get a list of Integrations
{id: "INTEGRATION-ID-1", displayName: "An Integration"},
{id: "INTEGRATION-ID-2", displayName: "Another Integration"},
copied to clipboard
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);
copied to clipboard
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);
copied to clipboard
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);
copied to clipboard
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",
...
}]

...
}
copied to clipboard
To get specific data for a particular device, use the getDeviceDetails method:
DevicesRepository.getDeviceDetails(request, "DEVICE-ID-HERE");
copied to clipboard
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");
copied to clipboard
To get the current target temperature, you can do the following:
print(thermostatDevice.traits.first.state.value);

copied to clipboard
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);
copied to clipboard
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);
copied to clipboard
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);
copied to clipboard
You can pick from the following modes listed in the ThermostatMode enumerator:
{OFF, AUTO, HEAT, COOL, FANONLY, DEHUMIDIFY, AIRFLOW}
copied to clipboard
License #
This application is released under the Apache license v2.0

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files:

Customer Reviews

There are no reviews.