• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

net-daemon / netdaemon / 13173327972

06 Feb 2025 06:45AM UTC coverage: 83.631%. Remained the same
13173327972

Pull #1251

github

web-flow
Merge c0397225d into afb86edc6
Pull Request #1251: Strongly-type EntityState.Attributes

842 of 1139 branches covered (73.92%)

Branch coverage included in aggregate %.

2 of 4 new or added lines in 2 files covered. (50.0%)

3322 of 3840 relevant lines covered (86.51%)

696.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.73
/src/HassModel/NetDeamon.HassModel/Entities/EntityState.cs
1
namespace NetDaemon.HassModel.Entities;
2

3
/// <summary>
4
/// Detailed state information
5
/// </summary>
6
public record EntityState
7
{
8
    /// <summary>Unique id of the entity</summary>
9
    [JsonPropertyName("entity_id")] public string EntityId { get; init; } = "";
243✔
10

11
    /// <summary>The state </summary>
12
    [JsonPropertyName("state")] public string? State { get; init; }
367✔
13

14
    /// <summary>The attributes as a JsonElement</summary>
15
    [JsonPropertyName("attributes")] public JsonElement? AttributesJson { get; init; }
107✔
16

17
    /// <summary>
18
    /// The attributes
19
    /// </summary>
NEW
20
    public Dictionary<string, object>? Attributes => AttributesJson?.Deserialize<Dictionary<string, object>>() ?? [];
×
21

22
    /// <summary>Last changed, when state changed from and to different values</summary>
23
    [JsonPropertyName("last_changed")] public DateTime? LastChanged { get; init; }
76✔
24

25
    /// <summary>Last updated, when entity state or attributes changed </summary>
26
    [JsonPropertyName("last_updated")] public DateTime? LastUpdated { get; init; }
76✔
27

28
    /// <summary>Context</summary>
29
    [JsonPropertyName("context")] public Context? Context { get; init; }
83✔
30

31
    internal static TEntityState? Map<TEntityState>(EntityState? state)
32
        where TEntityState : class =>
33
        state == null ? null : (TEntityState)Activator.CreateInstance(typeof(TEntityState), state)!;
87!
34
}
35

36
/// <summary>
37
/// Generic EntityState with specific types of State and Attributes
38
/// </summary>
39
/// <typeparam name="TAttributes">The type of the Attributes Property</typeparam>
40
public record EntityState<TAttributes> : EntityState
41
    where TAttributes : class
42
{
43
    private readonly Lazy<TAttributes?> _attributesLazy;
44

45
    /// <summary>
46
    /// Copy constructor from base class
47
    /// </summary>
48
    /// <param name="source"></param>
49
    public EntityState(EntityState source) : base(source)
82✔
50
    {
51
        _attributesLazy = new (() => AttributesJson?.Deserialize<TAttributes>() ?? default);
100✔
52
    }
82✔
53

54
    /// <inheritdoc/>
55
    public new virtual TAttributes? Attributes => _attributesLazy.Value;
18✔
56
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc