public BasicApp( IHaContext haContext ) { haContext.StateChanges() .Where(n => n.Entity.EntityId == "input_select.who_cooks" ) .Subscribe( s => haContext.CallService("input_text", "set_value", ServiceTarget.FromEntities("input_text.test_result"), new { value = s.New?.State }) ); }
public LocalApp( IHaContext ha ) { ha.StateChanges() .Where(n => n.Entity.EntityId == "binary_sensor.mypir" && n.New?.State == "on") .Subscribe(_ => { ha.CallService("light", "turn_on", ServiceTarget.FromEntities("light.my_light")); }); ha.StateChanges() .Where(n => n.Entity.EntityId == "binary_sensor.mypir_creates_fault" && n.New?.State == "on") .Subscribe(_ => { throw new InvalidOperationException("Ohh nooo!"); }); }
public async Task BasicTestApp_ShouldChangeStateOfInputTextToTheStateOfInputSelect_WhenChange() { var optionToSet = GetDifferentOptionThanCurrentlySelected(); var waitTask = _haContext.StateChanges() .Where(n => n.Entity.EntityId == "input_text.test_result") .Timeout(TimeSpan.FromMilliseconds(5000)) .FirstAsync() .ToTask(); _haContext.CallService( "input_select", "select_option", ServiceTarget.FromEntities("input_select.who_cooks"), new { option = optionToSet }); var result = await waitTask.ConfigureAwait(false); result.New !.State.Should().Be(optionToSet); }
public void ServiceTargetShouldContainCorrectEntitiesUsingParams() { var serviceTarget = ServiceTarget.FromEntities("light.kitchen", "light.livingroom"); serviceTarget.EntityIds.Should().BeEquivalentTo("light.kitchen", "light.livingroom"); }