-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
3,967 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Src/.vs/SmartMeApiClient/v16/.suo | ||
Src/.vs/ | ||
Src/Example/bin/ | ||
Src/Example/obj/ | ||
Src/packages/ | ||
.vs/ | ||
Src/SmartMeApiClient/bin/ | ||
Src/SmartMeApiClient/obj/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,20 @@ | ||
# smartme-api-client-library-dotnet | ||
A .Net client library for accessing the smart-me API | ||
# ![smart-me logo](Doc/icons/logo.png) Api Client Library for .Net | ||
|
||
The smart-me Api Client Library enables you to integrate smart-me API functionality into your .Net application. It makes HTTP requests to the smart-me REST API ([see here](https://smart-me.com/swagger)). All HTTP request and response bodies are mapped to .Net classes. | ||
|
||
## Examples | ||
|
||
See the Example project in [`Src/Example`](Src/Example). You need a smart-me login which you can create [here](https://web.smart-me.com/login/). Set your username and password in [`Credentials.json`](Src/Example/Credentials.json). Please keep your username and password private. | ||
|
||
## Requirements | ||
|
||
.Net Framework 4.7.2+ | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
- [Documentation](https://www.newtonsoft.com/json/help) | ||
- [NuGet Package](https://www.nuget.org/packages/Newtonsoft.Json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#region License | ||
// Copyright (c) 2019 smart-me AG https://web.smart-me.com/ | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
|
||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
|
||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
#endregion | ||
|
||
using SmartMeApiClient; | ||
using SmartMeApiClient.Containers; | ||
using SmartMeApiClient.Enumerations; | ||
using SmartMeApiClient.Helpers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Example | ||
{ | ||
public class ActionsExamples | ||
{ | ||
public static async Task ActionsAsync(UserPassword credentials) | ||
{ | ||
// Get Actions | ||
{ | ||
Helpers.WriteConsoleTitle("Get Actions"); | ||
|
||
List<SmartMeApiClient.Containers.Action> actions = await ActionsApi.GetActionsAsync(credentials, new Guid("c04db633-3c35-4e88-b9ee-11ab04ee7331")); | ||
|
||
foreach (var action in actions) | ||
{ | ||
Console.WriteLine($"Name: {action.Name}, ObisCode: {action.ObisCode}"); | ||
} | ||
} | ||
|
||
// Run Actions | ||
{ | ||
Helpers.WriteConsoleTitle("Run Actions"); | ||
|
||
await ActionsApi.RunActionsAsync(credentials, new SmartMeApiClient.Containers.ActionToRun | ||
{ | ||
DeviceID = new Guid("c04db633-3c35-4e88-b9ee-11ab04ee7331"), | ||
Actions = new List<SmartMeApiClient.Containers.ActionToRunItem> | ||
{ | ||
new SmartMeApiClient.Containers.ActionToRunItem(HexStringHelper.ByteArrayToString(ObisCodes.SmartMeSpecificPhaseSwitchL1), 1.0) | ||
} | ||
}); | ||
|
||
Console.WriteLine("Switch on"); | ||
|
||
Thread.Sleep(5000); | ||
|
||
await ActionsApi.RunActionsAsync(credentials, new SmartMeApiClient.Containers.ActionToRun | ||
{ | ||
DeviceID = new Guid("c04db633-3c35-4e88-b9ee-11ab04ee7331"), | ||
Actions = new List<SmartMeApiClient.Containers.ActionToRunItem> | ||
{ | ||
new SmartMeApiClient.Containers.ActionToRunItem(HexStringHelper.ByteArrayToString(ObisCodes.SmartMeSpecificPhaseSwitchL1), 0.0) | ||
} | ||
}); | ||
|
||
Console.WriteLine("Switch off"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"Username": "", | ||
"Password": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
#region License | ||
// Copyright (c) 2019 smart-me AG https://web.smart-me.com/ | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
|
||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
|
||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
#endregion | ||
|
||
using SmartMeApiClient; | ||
using SmartMeApiClient.Containers; | ||
using SmartMeApiClient.Enumerations; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Example | ||
{ | ||
public class DevicesExamples | ||
{ | ||
public static async Task DevicesAsync(UserPassword credentials) | ||
{ | ||
// Get all devices | ||
{ | ||
Helpers.WriteConsoleTitle("Get all devices"); | ||
|
||
List<Device> devices = await DevicesApi.GetDevicesAsync(credentials); | ||
|
||
foreach (var device in devices) | ||
{ | ||
Console.WriteLine($"Id: {device.Id}, Name: {device.Name}"); | ||
} | ||
} | ||
|
||
// Get all devices with a certain energy type | ||
{ | ||
Helpers.WriteConsoleTitle("Get all devices with energy type 'MeterTypeAllMeters'"); | ||
|
||
List<Device> devices = await DevicesApi.GetDevicesAsync(credentials, MeterEnergyType.MeterTypeAllMeters); | ||
|
||
foreach (var device in devices) | ||
{ | ||
Console.WriteLine($"Id: {device.Id}, Name: {device.Name}, EnergyType: {Enum.GetName(typeof(MeterEnergyType), device.DeviceEnergyType)}"); | ||
} | ||
} | ||
|
||
// Get all devices with a certain meter sub type | ||
{ | ||
Helpers.WriteConsoleTitle("Get all devices with meter sub type 'MeterSubTypeElectricity'"); | ||
|
||
List<Device> devices = await DevicesApi.GetDevicesAsync(credentials, MeterSubType.MeterSubTypeElectricity); | ||
|
||
foreach (var device in devices) | ||
{ | ||
Console.Write($"Id: {device.Id} Name: {device.Name} "); | ||
|
||
if (device.MeterSubType != null) | ||
{ | ||
Console.Write($"SubType: {Enum.GetName(typeof(MeterSubType), device.MeterSubType)}"); | ||
} | ||
|
||
Console.WriteLine(); | ||
} | ||
} | ||
|
||
// Get device by Id | ||
{ | ||
Helpers.WriteConsoleTitle("Get device by Id"); | ||
|
||
Device device = await DevicesApi.GetDeviceAsync(credentials, new Guid("c04db633-3c35-4e88-b9ee-11ab04ee7331")); | ||
Console.WriteLine($"Name: {device.Name}, Id: {device.Id}"); | ||
} | ||
|
||
// Get device by Serial | ||
{ | ||
Helpers.WriteConsoleTitle("Get device by serial number"); | ||
|
||
Device device = await DevicesApi.GetDeviceAsync(credentials, 200354); | ||
Console.WriteLine($"Name: {device.Name}, Serial: {device.Serial}"); | ||
} | ||
|
||
// Get additional device information | ||
{ | ||
Helpers.WriteConsoleTitle("Get additional device information"); | ||
|
||
var info = await DevicesApi.GetAdditionalDeviceInformationAsync(credentials, new Guid("c04db633-3c35-4e88-b9ee-11ab04ee7331")); | ||
Console.WriteLine($"ID: {info.ID}, HardwareVersion: {info.HardwareVersion}, FirmwareVersion: {info.FirmwareVersion}, AdditionalMeterSerialNumber: {info.AdditionalMeterSerialNumber}"); | ||
} | ||
|
||
// Add and update device | ||
{ | ||
Helpers.WriteConsoleTitle("Add a new device"); | ||
|
||
Device newDevice = await DevicesApi.AddDeviceAsync(credentials, new Device | ||
{ | ||
Name = "NewDevice", | ||
DeviceEnergyType = MeterEnergyType.MeterTypeElectricity, | ||
ActivePower = 0, | ||
CounterReading = 0, | ||
Voltage = 230, | ||
VoltageL1 = 230, | ||
Current = 1.0, | ||
PowerFactor = 0, | ||
PowerFactorL1 = 0, | ||
Temperature = 26 | ||
}); | ||
|
||
Helpers.WriteConsoleTitle("Update the name of a device"); | ||
|
||
newDevice.Name = "UpdatedDevice"; | ||
|
||
await DevicesApi.UpdateDeviceAsync(credentials, newDevice); | ||
|
||
Helpers.WriteConsoleTitle("Update CounterReadingImport and ActivePower of a device"); | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
newDevice.CounterReading = i + 1; | ||
newDevice.ActivePower = i * 1.1; | ||
|
||
await DevicesApi.UpdateDeviceAsync(credentials, newDevice); | ||
|
||
Thread.Sleep(1000); | ||
} | ||
} | ||
} | ||
|
||
public static async Task DeviceConfigurationAsync(UserPassword credentials) | ||
{ | ||
// Get smart-me Device Configuration | ||
{ | ||
Helpers.WriteConsoleTitle("Get smart-me device configuration"); | ||
|
||
var configuration = await DevicesApi.GetSmartMeDeviceConfigurationAsync(credentials, new Guid("c04db633-3c35-4e88-b9ee-11ab04ee7331")); | ||
Console.WriteLine($"Id: {configuration.Id}, UploadInterval: {configuration.UploadInterval}"); | ||
} | ||
|
||
// Set smart-me Device Configuration | ||
{ | ||
Helpers.WriteConsoleTitle("Set smart-me device configuration"); | ||
|
||
var configuration = await DevicesApi.GetSmartMeDeviceConfigurationAsync(credentials, new Guid("c04db633-3c35-4e88-b9ee-11ab04ee7331")); | ||
|
||
configuration.SwitchConfiguration[0].CanSwitchOff = false; | ||
|
||
await DevicesApi.SetSmartMeDeviceConfigurationAsync(credentials, configuration); | ||
|
||
Console.WriteLine("Device is not allowed to switch off"); | ||
|
||
Thread.Sleep(5000); | ||
|
||
configuration = await DevicesApi.GetSmartMeDeviceConfigurationAsync(credentials, new Guid("c04db633-3c35-4e88-b9ee-11ab04ee7331")); | ||
|
||
configuration.SwitchConfiguration[0].CanSwitchOff = true; | ||
|
||
await DevicesApi.SetSmartMeDeviceConfigurationAsync(credentials, configuration); | ||
|
||
Console.WriteLine("Device is allowed to switch off"); | ||
|
||
Thread.Sleep(5000); | ||
} | ||
} | ||
|
||
public static async Task CustomDevicesAsync(UserPassword credentials) | ||
{ | ||
// Add Custom Device | ||
{ | ||
Helpers.WriteConsoleTitle("Add a custom device"); | ||
|
||
await DevicesApi.AddCustomDeviceAsync(credentials, new CustomDevice | ||
{ | ||
Id = new Guid(), | ||
Name = "CustomDeviceTest", | ||
Serial = 0, | ||
ValueDate = DateTime.UtcNow, | ||
Values = new List<CustomDeviceValue> | ||
{ | ||
new CustomDeviceValue { Name = "SomeVoltageValue", Value = 5.6 }, | ||
new CustomDeviceValue { Name = "SomeTemperatureValue", Value = 12.1 } | ||
} | ||
}); | ||
} | ||
|
||
// Get Custom Devices | ||
{ | ||
Helpers.WriteConsoleTitle("Get custom devices"); | ||
|
||
List<CustomDevice> customDevices = await DevicesApi.GetCustomDevicesAsync(credentials); | ||
|
||
foreach (CustomDevice customDevice in customDevices) | ||
{ | ||
Console.WriteLine($"Id: {customDevice.Id}, Name: {customDevice.Name}"); | ||
} | ||
} | ||
|
||
// Get Custom Device by Id | ||
{ | ||
Helpers.WriteConsoleTitle("Get custom device by id"); | ||
|
||
CustomDevice customDevice = await DevicesApi.GetCustomDeviceAsync(credentials, new Guid("{b41338ba-b2bf-4717-bacb-10a9fa278e59}")); | ||
Console.WriteLine($"Id: {customDevice.Id}, Name: {customDevice.Name}"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.