diff --git a/HADotNet.Core.Tests/InfoTests.cs b/HADotNet.Core.Tests/InfoTests.cs new file mode 100644 index 0000000..632208b --- /dev/null +++ b/HADotNet.Core.Tests/InfoTests.cs @@ -0,0 +1,58 @@ +using System; +using System.Threading.Tasks; +using HADotNet.Core.Clients; +using NUnit.Framework; + +namespace HADotNet.Core.Tests +{ + public class InfoTests + { + private Uri Instance { get; set; } + private string ApiKey { get; set; } + + [SetUp] + public void Setup() + { + Instance = new Uri(Environment.GetEnvironmentVariable("HADotNet:Tests:Instance")); + ApiKey = Environment.GetEnvironmentVariable("HADotNet:Tests:ApiKey"); + + ClientFactory.Initialize(Instance, ApiKey); + } + + [Test] + public async Task ShouldRetrieveSupervisorInfo() + { + var client = ClientFactory.GetClient(); + + var info = await client.GetSupervisorInfo(); + + Assert.AreEqual("ok", info.Result); + Assert.IsNotNull(info.Data); + Assert.IsNotNull(info.Data.Version); + } + + [Test] + public async Task ShouldRetrieveHostInfo() + { + var client = ClientFactory.GetClient(); + + var info = await client.GetHostInfo(); + + Assert.AreEqual("ok", info.Result); + Assert.IsNotNull(info.Data); + Assert.IsNotNull(info.Data.OperatingSystem); + } + + [Test] + public async Task ShouldRetrieveCoreInfo() + { + var client = ClientFactory.GetClient(); + + var info = await client.GetCoreInfo(); + + Assert.AreEqual("ok", info.Result); + Assert.IsNotNull(info.Data); + Assert.IsNotNull(info.Data.Version); + } + } +} diff --git a/HADotNet.Core.Tests/StatsTests.cs b/HADotNet.Core.Tests/StatsTests.cs new file mode 100644 index 0000000..8bcafa5 --- /dev/null +++ b/HADotNet.Core.Tests/StatsTests.cs @@ -0,0 +1,44 @@ +using System; +using System.Threading.Tasks; +using HADotNet.Core.Clients; +using NUnit.Framework; + +namespace HADotNet.Core.Tests +{ + public class StatsTests + { + private Uri Instance { get; set; } + private string ApiKey { get; set; } + + [SetUp] + public void Setup() + { + Instance = new Uri(Environment.GetEnvironmentVariable("HADotNet:Tests:Instance")); + ApiKey = Environment.GetEnvironmentVariable("HADotNet:Tests:ApiKey"); + + ClientFactory.Initialize(Instance, ApiKey); + } + + [Test] + public async Task ShouldRetrieveSupervisorStats() + { + var client = ClientFactory.GetClient(); + + var stats = await client.GetSupervisorStats(); + + Assert.AreEqual("ok", stats.Result); + Assert.IsNotNull(stats.Data); + } + + [Test] + public async Task ShouldRetrieveCoreStats() + { + var client = ClientFactory.GetClient(); + + var stats = await client.GetCoreStats(); + + Assert.AreEqual("ok", stats.Result); + Assert.IsNotNull(stats.Data); + } + } +} diff --git a/HADotNet.Core/Clients/InfoClient.cs b/HADotNet.Core/Clients/InfoClient.cs new file mode 100644 index 0000000..1812f18 --- /dev/null +++ b/HADotNet.Core/Clients/InfoClient.cs @@ -0,0 +1,37 @@ +using System; +using System.Threading.Tasks; +using HADotNet.Core.Models; + +namespace HADotNet.Core.Clients +{ + /// + /// Provides access to the info API for retrieving information about Supervisor, Core and Host. + /// + public class InfoClient : BaseClient + { + /// + /// Initializes a new instance of the . + /// + /// The Home Assistant base instance URL. + /// The Home Assistant long-lived access token. + public InfoClient(Uri instance, string apiKey) : base(instance, apiKey) { } + + /// + /// Retrieves Supervisor information. + /// + /// A representing Supervisor informatio. + public async Task> GetSupervisorInfo() => await Get>("/api/hassio/supervisor/info"); + + /// + /// Retrieves Host information. + /// + /// A representing Host informatio. + public async Task> GetHostInfo() => await Get>("/api/hassio/host/info"); + + /// + /// Retrieves Core information. + /// + /// A representing Host informatio. + public async Task> GetCoreInfo() => await Get>("/api/hassio/core/info"); + } +} diff --git a/HADotNet.Core/Clients/StatsClient.cs b/HADotNet.Core/Clients/StatsClient.cs new file mode 100644 index 0000000..e44d871 --- /dev/null +++ b/HADotNet.Core/Clients/StatsClient.cs @@ -0,0 +1,31 @@ +using System; +using System.Threading.Tasks; +using HADotNet.Core.Models; + +namespace HADotNet.Core.Clients +{ + /// + /// Provides access to the info API for retrieving statistics about Supervisor and Core. + /// + public class StatsClient : BaseClient + { + /// + /// Initializes a new instance of the . + /// + /// The Home Assistant base instance URL. + /// The Home Assistant long-lived access token. + public StatsClient(Uri instance, string apiKey) : base(instance, apiKey) { } + + /// + /// Retrieves Supervisor information. + /// + /// A representing Supervisor stats. + public async Task> GetSupervisorStats() => await Get>("/api/hassio/supervisor/stats"); + + /// + /// Retrieves Core stats. + /// + /// A representing Core stats. + public async Task> GetCoreStats() => await Get>("/api/hassio/core/stats"); + } +} diff --git a/HADotNet.Core/Models/AddonObject.cs b/HADotNet.Core/Models/AddonObject.cs new file mode 100644 index 0000000..ff89ef4 --- /dev/null +++ b/HADotNet.Core/Models/AddonObject.cs @@ -0,0 +1,70 @@ +using Newtonsoft.Json; + +namespace HADotNet.Core.Models +{ + /// + /// Represents Add-on object. + /// + public class AddonObject + { + /// + /// Gets or sets the description. + /// + [JsonProperty("description")] + public string Description { get; set; } + + /// + /// True if icon is available, otherwise False. + /// + [JsonProperty("icon")] + public bool Icon { get; set; } + + /// + /// True if logo is available, otherwise False. + /// + [JsonProperty("logo")] + public bool Logo { get; set; } + + /// + /// Gets or sets the name. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Gets or sets the repository. + /// + [JsonProperty("repository")] + public string Repository { get; set; } + + /// + /// Gets or sets the slug. + /// + [JsonProperty("slug")] + public string Slug { get; set; } + + /// + /// Gets or sets the state. + /// + [JsonProperty("state")] + public string State { get; set; } + + /// + /// True if update is available, otherwise False. + /// + [JsonProperty("update_available")] + public bool UpdateAvailable { get; set; } + + /// + /// Gets or sets the version. + /// + [JsonProperty("version")] + public string Version { get; set; } + + /// + /// Gets or sets the latest version. + /// + [JsonProperty("version_latest")] + public string VersionLatest { get; set; } + } +} diff --git a/HADotNet.Core/Models/CoreInfoObject.cs b/HADotNet.Core/Models/CoreInfoObject.cs new file mode 100644 index 0000000..717c0d5 --- /dev/null +++ b/HADotNet.Core/Models/CoreInfoObject.cs @@ -0,0 +1,100 @@ +using Newtonsoft.Json; + +namespace HADotNet.Core.Models +{ + /// + /// Represents Core info object. + /// + public class CoreInfoObject + { + /// + /// Gets or sets the processor architecture. + /// + [JsonProperty("arch")] + public string Arch { get; set; } + + /// + /// Gets or sets the audio input. + /// + [JsonProperty("audio_input")] + public string AudioInput { get; set; } + + /// + /// Gets or sets the audio output. + /// + [JsonProperty("audio_output")] + public string AudioOutput { get; set; } + + /// + /// True if booted, otherwise False. + /// + [JsonProperty("boot")] + public bool Boot { get; set; } + + /// + /// Gets or sets the image. + /// + [JsonProperty("image")] + public string Image { get; set; } + + /// + /// Gets or sets the IP address. + /// + [JsonProperty("ip_address")] + public string IpAddress { get; set; } + + /// + /// Gets or sets the last_version. + /// + [JsonProperty("last_version")] + public string LastVersion { get; set; } + + /// + /// Gets or sets the machine. + /// + [JsonProperty("machine")] + public string Machine { get; set; } + + /// + /// Gets or sets the port. + /// + [JsonProperty("port")] + public int Port { get; set; } + + /// + /// True if SSL is enabled, otherwise False. + /// + [JsonProperty("ssl")] + public bool Ssl { get; set; } + + /// + /// True if update is available, otherwise False. + /// + [JsonProperty("update_available")] + public bool UpdateAvailable { get; set; } + + /// + /// Gets or sets the version. + /// + [JsonProperty("version")] + public string Version { get; set; } + + /// + /// Gets or sets the latest version. + /// + [JsonProperty("version_latest")] + public string VersionLatest { get; set; } + + /// + /// Gets or sets the wait boot timeout. + /// + [JsonProperty("wait_boot")] + public int WaitBoot { get; set; } + + /// + /// True if watchdog is enabled, otherwise False. + /// + [JsonProperty("watchdog")] + public bool Watchdog { get; set; } + } +} diff --git a/HADotNet.Core/Models/HostInfoObject.cs b/HADotNet.Core/Models/HostInfoObject.cs new file mode 100644 index 0000000..1f4d125 --- /dev/null +++ b/HADotNet.Core/Models/HostInfoObject.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace HADotNet.Core.Models +{ + /// + /// Represents Host info object. + /// + public class HostInfoObject + { + /// + /// Gets or sets the chassis. + /// + [JsonProperty("chassis")] + public string Chassis { get; set; } + + /// + /// Gets or sets the CPE. + /// + [JsonProperty("cpe")] + public string Cpe { get; set; } + + /// + /// Gets or sets the deployment. + /// + [JsonProperty("deployment")] + public string Deployment { get; set; } + + /// + /// Gets or sets the disk free. + /// + [JsonProperty("disk_free")] + public double DiskFree { get; set; } + + /// + /// Gets or sets the disk total. + /// + [JsonProperty("disk_total")] + public double DiskTotal { get; set; } + + /// + /// Gets or sets the disk used. + /// + [JsonProperty("disk_used")] + public double DiskUsed { get; set; } + + /// + /// Gets or sets the features. + /// + [JsonProperty("features")] + public IList Features { get; set; } + + /// + /// Gets or sets the hostname. + /// + [JsonProperty("hostname")] + public string Hostname { get; set; } + + /// + /// Gets or sets the kernel. + /// + [JsonProperty("kernel")] + public string Kernel { get; set; } + + /// + /// Gets or sets the operating system. + /// + [JsonProperty("operating_system")] + public string OperatingSystem { get; set; } + } +} diff --git a/HADotNet.Core/Models/LogbookObject.cs b/HADotNet.Core/Models/LogbookObject.cs index 82bc2a0..63c16ac 100644 --- a/HADotNet.Core/Models/LogbookObject.cs +++ b/HADotNet.Core/Models/LogbookObject.cs @@ -1,89 +1,89 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; using System; - -namespace HADotNet.Core.Models -{ - /// - /// Represents a logbook entry object. The only consistently available properties are , , and . - /// - public class LogbookObject - { - /// - /// Gets or sets the entity ID for this entry. - /// - [JsonProperty("entity_id")] - public string EntityId { get; set; } - - /// - /// Gets or sets the domain. - /// - [JsonProperty("domain")] - public string Domain { get; set; } - - /// - /// Gets or sets the context user ID associated with this entry. - /// - [JsonProperty("context_user_id")] - public string ContextUserId { get; set; } - - /// - /// Gets or sets the context entity ID associated with this entry. (For example, which automation triggered this change?) - /// - [JsonProperty("context_entity_id")] - public string ContextEntityId { get; set; } - - /// - /// Gets or sets the friendly name for the . This is sometimes the same as . - /// - [JsonProperty("context_entity_id_name")] - public string ContextEntityIdName { get; set; } - - /// - /// Gets or sets the type of associated change, for example, if an automation triggered this event, the value is 'automation_triggered'. - /// - [JsonProperty("context_event_type")] - public string ContextEventType { get; set; } - - /// - /// Gets or sets the domain associated with the context entity. For example, if an automation triggered this change, the value is 'automation'. - /// - [JsonProperty("context_domain")] - public string ContextDomain { get; set; } - - /// - /// Gets or sets the name associated with the context entity (e.g. the name of the automation). This is sometimes the same as . - /// - [JsonProperty("context_name")] - public string ContextName { get; set; } - - /// - /// Gets or sets the new state that the entity transitioned to. - /// - [JsonProperty("state")] - public string State { get; set; } - - /// - /// Gets or sets the source for this logbook entry (i.e. what triggered this change). - /// - [JsonProperty("source")] - public string Source { get; set; } - - /// - /// Gets or sets the message, a brief description of what happened. - /// - [JsonProperty("message")] - public string Message { get; set; } - - /// - /// Gets or sets the category name for this entry. - /// - [JsonProperty("name")] - public string Name { get; set; } - - /// - /// Gets or sets the timestmap when this entry occurred.. - /// - [JsonProperty("when")] - public DateTimeOffset Timestamp { get; set; } - } -} + +namespace HADotNet.Core.Models +{ + /// + /// Represents a logbook entry object. The only consistently available properties are , , and . + /// + public class LogbookObject + { + /// + /// Gets or sets the entity ID for this entry. + /// + [JsonProperty("entity_id")] + public string EntityId { get; set; } + + /// + /// Gets or sets the domain. + /// + [JsonProperty("domain")] + public string Domain { get; set; } + + /// + /// Gets or sets the context user ID associated with this entry. + /// + [JsonProperty("context_user_id")] + public string ContextUserId { get; set; } + + /// + /// Gets or sets the context entity ID associated with this entry. (For example, which automation triggered this change?) + /// + [JsonProperty("context_entity_id")] + public string ContextEntityId { get; set; } + + /// + /// Gets or sets the friendly name for the . This is sometimes the same as . + /// + [JsonProperty("context_entity_id_name")] + public string ContextEntityIdName { get; set; } + + /// + /// Gets or sets the type of associated change, for example, if an automation triggered this event, the value is 'automation_triggered'. + /// + [JsonProperty("context_event_type")] + public string ContextEventType { get; set; } + + /// + /// Gets or sets the domain associated with the context entity. For example, if an automation triggered this change, the value is 'automation'. + /// + [JsonProperty("context_domain")] + public string ContextDomain { get; set; } + + /// + /// Gets or sets the name associated with the context entity (e.g. the name of the automation). This is sometimes the same as . + /// + [JsonProperty("context_name")] + public string ContextName { get; set; } + + /// + /// Gets or sets the new state that the entity transitioned to. + /// + [JsonProperty("state")] + public string State { get; set; } + + /// + /// Gets or sets the source for this logbook entry (i.e. what triggered this change). + /// + [JsonProperty("source")] + public string Source { get; set; } + + /// + /// Gets or sets the message, a brief description of what happened. + /// + [JsonProperty("message")] + public string Message { get; set; } + + /// + /// Gets or sets the category name for this entry. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Gets or sets the timestmap when this entry occurred.. + /// + [JsonProperty("when")] + public DateTimeOffset Timestamp { get; set; } + } +} diff --git a/HADotNet.Core/Models/ResponseObject.cs b/HADotNet.Core/Models/ResponseObject.cs new file mode 100644 index 0000000..51f3ba3 --- /dev/null +++ b/HADotNet.Core/Models/ResponseObject.cs @@ -0,0 +1,23 @@ +using Newtonsoft.Json; + +namespace HADotNet.Core.Models +{ + /// + /// Represents Home Assistant response. + /// + /// + public class ResponseObject + { + /// + /// Gets or sets the result. + /// + [JsonProperty("result")] + public string Result { get; set; } + + /// + /// Gets or sets the data. + /// + [JsonProperty("data")] + public T Data { get; set; } + } +} diff --git a/HADotNet.Core/Models/StatsObject.cs b/HADotNet.Core/Models/StatsObject.cs new file mode 100644 index 0000000..75a69af --- /dev/null +++ b/HADotNet.Core/Models/StatsObject.cs @@ -0,0 +1,58 @@ +using Newtonsoft.Json; + +namespace HADotNet.Core.Models +{ + /// + /// Represents the stats object. + /// + public class StatsObject + { + /// + /// Gets or sets the number of bulk reads. + /// + [JsonProperty("blk_read")] + public long BlkRead { get; set; } + + /// + /// Gets or sets the number of bulk writes. + /// + [JsonProperty("blk_write")] + public long BlkWrite { get; set; } + + /// + /// Gets or sets the CPU usage percent. + /// + [JsonProperty("cpu_percent")] + public double CpuPercent { get; set; } + + /// + /// Gets or sets the memory limit. + /// + [JsonProperty("memory_limit")] + public long MemoryLimit { get; set; } + + /// + /// Gets or sets the memory usage percent. + /// + [JsonProperty("memory_percent")] + public double MemoryPercent { get; set; } + + /// + /// Gets or sets the memory usage. + /// + [JsonProperty("memory_usage")] + public long MemoryUsage { get; set; } + + /// + /// Gets or sets the network rx. + /// + [JsonProperty("network_rx")] + public int NetworkRx { get; set; } + + /// + /// Gets or sets the network tx. + /// + [JsonProperty("network_tx")] + public int NetworkTx { get; set; } + } +} diff --git a/HADotNet.Core/Models/SupervisorInfoObject.cs b/HADotNet.Core/Models/SupervisorInfoObject.cs new file mode 100644 index 0000000..aa21426 --- /dev/null +++ b/HADotNet.Core/Models/SupervisorInfoObject.cs @@ -0,0 +1,107 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace HADotNet.Core.Models +{ + /// + /// Represents Supervisor info object. + /// + public class SupervisorInfoObject + { + /// + /// Gets or sets the addons. + /// + [JsonProperty("addons")] + public IList Addons { get; set; } + + /// + /// Gets or sets the addons repositories. + /// + [JsonProperty("addons_repositories")] + public IList AddonsRepositories { get; set; } + + /// + /// Gets or sets the processor architecture. + /// + [JsonProperty("arch")] + public string Arch { get; set; } + + /// + /// Gets or sets the processor channel. + /// + [JsonProperty("channel")] + public string Channel { get; set; } + + /// + /// True if debug, otherwise False. + /// + [JsonProperty("debug")] + public bool Debug { get; set; } + + /// + /// True if debug block, otherwise False. + /// + [JsonProperty("debug_block")] + public bool DebugBlock { get; set; } + + /// + /// True if diagnostics is available, otherwise False. + /// + [JsonProperty("diagnostics")] + public bool Diagnostics { get; set; } + + /// + /// True if healthy, otherwise False. + /// + [JsonProperty("healthy")] + public bool Healthy { get; set; } + + /// + /// Gets or sets the IP address. + /// + [JsonProperty("ip_address")] + public string IpAddress { get; set; } + + /// + /// Gets or sets the logging. + /// + [JsonProperty("logging")] + public string Logging { get; set; } + + /// + /// True if supported, otherwise False. + /// + [JsonProperty("supported")] + public bool Supported { get; set; } + + /// + /// Gets or sets the timezone. + /// + [JsonProperty("timezone")] + public string Timezone { get; set; } + + /// + /// True if update is available, otherwise False. + /// + [JsonProperty("update_available")] + public bool UpdateAvailable { get; set; } + + /// + /// Gets or sets the version. + /// + [JsonProperty("version")] + public string Version { get; set; } + + /// + /// Gets or sets the latest version. + /// + [JsonProperty("version_latest")] + public string VersionLatest { get; set; } + + /// + /// Gets or sets the wait boot timeout. + /// + [JsonProperty("wait_boot")] + public int WaitBoot { get; set; } + } +}