36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using HomeAssistant.Entities.Interfaces;
|
|
using HomeAssistant.Models;
|
|
using NetDaemon.Extensions.MqttEntityManager;
|
|
|
|
namespace HomeAssistant.Entities;
|
|
|
|
public class EntityManager(IMqttEntityManager entityManager) : IEntityManager
|
|
{
|
|
public async Task CreateEntitiesAsync(ICollection<EntityCreateModel> entities)
|
|
{
|
|
await Task.WhenAll(entities.Select(CreateEntityAsync));
|
|
}
|
|
|
|
public async Task CreateEntityAsync(EntityCreateModel createModel)
|
|
{
|
|
if (createModel.EntityId != null)
|
|
{
|
|
await entityManager.CreateAsync(createModel.EntityId, createModel.Options, createModel.AdditionalConfig);
|
|
}
|
|
}
|
|
|
|
public async Task SetEntityState(string entityId, string state)
|
|
{
|
|
await entityManager.SetStateAsync(entityId, state);
|
|
}
|
|
|
|
public async Task SetEntityAttributes(string entityId, object attributes)
|
|
{
|
|
await entityManager.SetAttributesAsync(entityId, attributes);
|
|
}
|
|
|
|
public async Task RemoveEntity(string entityId)
|
|
{
|
|
await entityManager.RemoveAsync(entityId);
|
|
}
|
|
} |