コード例 #1
0
    public async Task <bool> GetOrCreateAsync(string applicationId, CancellationToken token)
    {
        var haConnection = _runner.CurrentConnection ??
                           throw new InvalidOperationException();

        var entityId = EntityMapperHelper.ToEntityIdFromApplicationId(applicationId, _hostEnvironment.IsDevelopment());

        try
        {
            var state = await haConnection.GetEntityStateAsync(entityId, token)
                        .ConfigureAwait(false);

            return(state?.State == "on");
        }
        catch (HomeAssistantApiCallException e)
        {
            // Missing entity will throw a http status not found
            if (e.Code != HttpStatusCode.NotFound)
            {
                throw;
            }
            // The app state input_boolean does not exist, lets create a helper
            var name = entityId[14..]; // remove the "input_boolean." part
コード例 #2
0
    public void TestToSafeHomeAssistantEntityIdFromApplicationIdShouldGiveCorrectNameDevelopment(string fromId, string toId)
    {
        var expected = $"input_boolean.dev_netdaemon_{toId}";

        EntityMapperHelper.ToEntityIdFromApplicationId(fromId, true).Should().Be(expected);
    }