Esempio n. 1
0
    /// <summary>
    /// Set the state of an entity
    /// </summary>
    /// <param name="entityId"></param>
    /// <param name="state"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    public async Task SetStateAsync(string entityId, string state)
    {
        var(domain, identifier) = EntityIdParser.Extract(entityId);

        await _messageSender.SendMessageAsync(StatePath(domain, identifier), state, true, QualityOfServiceLevel)
        .ConfigureAwait(false);
    }
Esempio n. 2
0
 /// <summary>
 ///     Remove an entity from Home Assistant
 /// </summary>
 /// <param name="entityId"></param>
 public async Task RemoveAsync(string entityId)
 {
     var(domain, identifier) = EntityIdParser.Extract(entityId);
     await _messageSender
     .SendMessageAsync(ConfigPath(domain, identifier), string.Empty, false, QualityOfServiceLevel)
     .ConfigureAwait(false);
 }
Esempio n. 3
0
    /// <summary>
    /// Set attributes on an entity
    /// </summary>
    /// <param name="entityId"></param>
    /// <param name="attributes"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    public async Task SetAttributesAsync(string entityId, object attributes)
    {
        var(domain, identifier) = EntityIdParser.Extract(entityId);

        await _messageSender.SendMessageAsync(AttrsPath(domain, identifier), JsonSerializer.Serialize(attributes),
                                              true, QualityOfServiceLevel)
        .ConfigureAwait(false);
    }
Esempio n. 4
0
    /// <summary>
    /// Set availability of the entity. If you specified "payload_available" and "payload_not_available" configuration
    /// on creating the entity then the value should match one of these.
    /// If not, then use "online" and "offline"
    /// </summary>
    /// <param name="entityId"></param>
    /// <param name="availability"></param>
    public async Task SetAvailabilityAsync(string entityId, string availability)
    {
        var(domain, identifier) = EntityIdParser.Extract(entityId);

        await _messageSender
        .SendMessageAsync(AvailabilityPath(domain, identifier), availability, true, QualityOfServiceLevel)
        .ConfigureAwait(false);
    }
Esempio n. 5
0
    /// <summary>
    /// Create an entity in Home Assistant via MQTT
    /// </summary>
    /// <param name="entityId">Distinct identifier, in the format "domain.id", such as "sensor.kitchen_temp"</param>
    /// <param name="options">Optional set of additional parameters</param>
    /// <param name="additionalConfig"></param>
    public async Task CreateAsync(string entityId, EntityCreationOptions?options = null,
                                  object?additionalConfig = null)
    {
        var(domain, identifier) = EntityIdParser.Extract(entityId);
        var configPath = ConfigPath(domain, identifier);

        var payload = BuildCreationPayload(domain, identifier, configPath, options, additionalConfig);

        await _messageSender
        .SendMessageAsync(configPath, payload, options?.Persist ?? true, QualityOfServiceLevel)
        .ConfigureAwait(false);
    }