예제 #1
0
        public async Task ShouldUpdateAutomation()
        {
            // arrange
            var automation = new AutomationObject
            {
                Id          = AutomationId,
                Alias       = $"test_automation_{AutomationId}",
                Description = $"This is an updated test automation {DateTime.Now.ToLongDateString()}",
                Actions     = new List <Dictionary <string, object> >()
                {
                    new Dictionary <string, object>()
                    {
                        { "entity_id", "switch.switch" },
                        { "service", "switch.turn_off" }
                    }
                }
            };

            var client = ClientFactory.GetClient <AutomationClient>();

            // act
            var result = await client.Update(automation);

            // assert
            Assert.IsNotNull(result);
            Assert.AreEqual("ok", result.Result);
        }
예제 #2
0
        public async Task OneTimeSetUp()
        {
            // arrange
            AutomationId = Guid.NewGuid().ToString();
            Instance     = new Uri(Environment.GetEnvironmentVariable("HADotNet:Tests:Instance"));
            ApiKey       = Environment.GetEnvironmentVariable("HADotNet:Tests:ApiKey");

            ClientFactory.Initialize(Instance, ApiKey);

            var client = ClientFactory.GetClient <AutomationClient>();

            var automation = new AutomationObject
            {
                Id          = AutomationId,
                Alias       = $"test_automation_{AutomationId}",
                Description = $"This is a test automation {DateTime.Now.ToLongDateString()}",
                Actions     = new List <Dictionary <string, object> >()
                {
                    new Dictionary <string, object>()
                    {
                        { "entity_id", "switch.switch" },
                        { "service", "switch.turn_on" }
                    }
                }
            };

            // act
            var result = await client.Create(automation);

            // assert
            Assert.IsNotNull(result);
            Assert.AreEqual("ok", result.Result);
        }
예제 #3
0
 /// <summary>
 /// Update the <see cref="AutomationObject"/>.
 /// </summary>
 /// <param name="automation">The <see cref="AutomationObject"/>.</param>
 /// <returns>The <see cref="AutomationResultObject"/>.</returns>
 public async Task <AutomationResultObject> Update(AutomationObject automation) => await Create(automation);
예제 #4
0
 /// <summary>
 /// Create the <see cref="AutomationObject"/>.
 /// </summary>
 /// <param name="automation">The <see cref="AutomationObject"/>.</param>
 /// <returns>The <see cref="AutomationResultObject"/>.</returns>
 public async Task <AutomationResultObject> Create(AutomationObject automation) => await Post <AutomationResultObject>($"/api/config/automation/config/{automation.Id}", automation);