Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
daltskin committed Jun 26, 2020
1 parent 7683d62 commit 04d3ec8
Show file tree
Hide file tree
Showing 62 changed files with 24,297 additions and 0 deletions.
528 changes: 528 additions & 0 deletions .github/workflows/dotnet-core.yml

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
mode: Mainline
next-version: 0.9.0
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-format: '{Major}.{Minor}.{Patch}'
assembly-informational-format: '{FullBuildMetaData}'
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
no-bump-message: '\+semver:\s?(none|skip)'
commit-message-incrementing: Enabled
merge-message-formats: {}
branches:
master:
track-merge-target: false
tracks-release-branches: false
is-release-branch: false
is-mainline: true
increment: Patch
prevent-increment-of-merged-branch-version: true

# mode: ContinuousDelivery
tag: ''
ignore:
sha: []
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SmartThings Terminal

![.NET Core](https://github.com/daltskin/SmartThingsTerminal/workflows/.NET%20Core/badge.svg)
[![Release](https://img.shields.io/github/release/daltskin/SmartThingsTerminal.svg?style=flat-square)](https://github.com/daltskin/SmartThingsTerminal/releases/latest)
37 changes: 37 additions & 0 deletions SmartThingsTerminal.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30204.135
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartThingsTerminal", "SmartThingsTerminal\SmartThingsTerminal.csproj", "{9DF95721-8429-48A4-BFA7-8F1C006E8322}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8AB9BD79-B877-4441-B6A4-88F1F71EE4E2}"
ProjectSection(SolutionItems) = preProject
GitVersion.yml = GitVersion.yml
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Terminal.Gui", "Terminal.Gui\Terminal.Gui.csproj", "{007B0279-3E5F-440D-A5BC-522415D5ABF1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9DF95721-8429-48A4-BFA7-8F1C006E8322}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9DF95721-8429-48A4-BFA7-8F1C006E8322}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9DF95721-8429-48A4-BFA7-8F1C006E8322}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9DF95721-8429-48A4-BFA7-8F1C006E8322}.Release|Any CPU.Build.0 = Release|Any CPU
{007B0279-3E5F-440D-A5BC-522415D5ABF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{007B0279-3E5F-440D-A5BC-522415D5ABF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{007B0279-3E5F-440D-A5BC-522415D5ABF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{007B0279-3E5F-440D-A5BC-522415D5ABF1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {67A7EDCD-7026-4DEE-A90D-4758DF431428}
EndGlobalSection
EndGlobal
251 changes: 251 additions & 0 deletions SmartThingsTerminal/API/SmartThingsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
using SmartThingsNet.Api;
using SmartThingsNet.Client;
using SmartThingsNet.Model;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SmartThingsTerminal
{
public class SmartThingsClient
{
private PagedDevices _allDevices;
private PagedLocations _allLocations;
private PagedRooms _allRooms;
private PagedScene _allScenes;
private PagedRules _allRules;
private PagedSchedules _allSchedules;
private PagedApps _allApps;
private PagedSubscriptions _allSubscriptions;
private PagedInstalledApps _allInstalledApps;
private PagedDeviceProfiles _allDeviceProfiles;

private DevicesApi _devicesApi;
private LocationsApi _locationsApi;
private RoomsApi _roomsApi;
private ScenesApi _scenesApi;
private RulesApi _rulesApi;
private SchedulesApi _schedulesApi;
private AppsApi _appsApi;
private SubscriptionsApi _subscriptionsApi;
private InstalledAppsApi _installedAppsApi;
private DeviceProfilesApi _deviceProfilesApi;

public SmartThingsClient(string accessToken)
{
if (accessToken == null)
{
throw new ArgumentNullException(accessToken);
}

var configuration = new Configuration();
configuration.AccessToken = accessToken;

_devicesApi = new DevicesApi(configuration);
_locationsApi = new LocationsApi(configuration);
_roomsApi = new RoomsApi(configuration);
_scenesApi = new ScenesApi(configuration);
_rulesApi = new RulesApi(configuration);
_schedulesApi = new SchedulesApi(configuration);
_appsApi = new AppsApi(configuration);
_subscriptionsApi = new SubscriptionsApi(configuration);
_installedAppsApi = new InstalledAppsApi(configuration);
_deviceProfilesApi = new DeviceProfilesApi(configuration);
}

public void ResetData()
{
_allDevices = null;
_allLocations = null;
_allRooms = null;
_allScenes = null;
_allRules = null;
_allSchedules = null;
_allApps = null;
_allSubscriptions = null;
_allInstalledApps = null;
_allDeviceProfiles = null;
}

public PagedApps GetAllApps()
{
if (_allApps == null)
{
_allApps = _appsApi.ListApps();
}
return _allApps;
}

public PagedInstalledApps GetAllInstalledApps(string locationId = null)
{
if (_allInstalledApps == null)
{
if (locationId != null)
{
_allInstalledApps = _installedAppsApi.ListInstallations(locationId);
}
else
{
_allInstalledApps = new PagedInstalledApps();
foreach (var location in GetAllLocations().Items)
{
var locationApps = _installedAppsApi.ListInstallations(location.LocationId.ToString());
if (locationApps.Items?.Count > 0)
{
_allInstalledApps.Items ??= new List<InstalledApp>();
_allInstalledApps.Items.AddRange(locationApps.Items);
}
}
}
}
return _allInstalledApps;
}

public PagedSubscriptions GetAllSubscriptions(string appId = null)
{
if (_allSubscriptions == null)
{
if (appId != null)
{
_allSubscriptions = _subscriptionsApi.ListSubscriptions(appId);
}
else
{
_allSubscriptions = new PagedSubscriptions();
foreach (var app in GetAllInstalledApps().Items)
{
var appSubscriptions = _subscriptionsApi.ListSubscriptions(app.InstalledAppId.ToString());
if (appSubscriptions.Items?.Count > 0)
{
_allSubscriptions.Items ??= new List<Subscription>();
_allSubscriptions.Items.AddRange(appSubscriptions.Items);
}
}
}
}
return _allSubscriptions;
}

public async Task<PagedDevices> GetAllDevicesAsync()
{
if (_allDevices == null)
{
_allDevices = await _devicesApi.GetDevicesAsync();
}
return _allDevices;
}

public PagedDevices GetAllDevices()
{
if (_allDevices == null)
{
_allDevices = _devicesApi.GetDevices();
}
return _allDevices;
}

public PagedDeviceProfiles GetAllDeviceProfiles()
{
if (_allDeviceProfiles == null)
{
_allDeviceProfiles = _deviceProfilesApi.ListDeviceProfiles();
}
return _allDeviceProfiles;
}

public async Task<PagedLocations> GetAllLocationsAsync()
{
if (_allLocations == null)
{
_allLocations = await _locationsApi.ListLocationsAsync();
}
return _allLocations;
}

public PagedLocations GetAllLocations()
{
if (_allLocations == null)
{
_allLocations = _locationsApi.ListLocations();
}
return _allLocations;
}

public async Task<PagedRooms> GetAllRoomsAsync(string locationId)
{
if (_allRooms == null)
{
_allRooms = await _roomsApi.ListRoomsAsync(locationId);
}
return _allRooms;
}

public PagedRooms GetAllRooms(string locationId)
{
if (_allRooms == null)
{
_allRooms = _roomsApi.ListRooms(locationId);
}
return _allRooms;
}

public PagedScene GetAllScenes(string locationId = null)
{
if (_allScenes == null)
{
_allScenes = _scenesApi.ListScenes(locationId);
}
return _allScenes;
}

public PagedRules GetAllRules(string locationId = null)
{
if (_allRules == null)
{
if (locationId != null)
{
_allRules = _rulesApi.ListRules(locationId);
}
else
{
_allRules = new PagedRules();
foreach (var location in GetAllLocations().Items)
{
var locationRules = _rulesApi.ListRules(location.LocationId.ToString());
if (locationRules.Items?.Count > 0)
{
_allRules.Items ??= new List<SmartThingsNet.Model.Rule>();
_allRules.Items.AddRange(locationRules.Items);
}
}
}
}
return _allRules;
}

public PagedSchedules GetAllSchedules(string appId = null)
{
if (_allSchedules == null)
{
if (appId != null)
{
_allSchedules = _schedulesApi.GetSchedules(appId);
}
else
{
_allSchedules = new PagedSchedules();
foreach (var app in GetAllInstalledApps().Items)
{
var appSchedules = _schedulesApi.GetSchedules(app.InstalledAppId.ToString());
if (appSchedules.Items?.Count > 0)
{
_allSchedules.Items ??= new List<Schedule>();
_allSchedules.Items.AddRange(appSchedules.Items);
}
}
}
}
return _allSchedules;
}
}
}
Loading

0 comments on commit 04d3ec8

Please sign in to comment.