Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strongly-type EntityState.Attributes #1251

Merged
merged 2 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/HassModel/NetDeamon.HassModel/Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Entity(IEntityCore entity)
/// <summary>
/// The current Attributes of this Entity
/// </summary>
public virtual object? Attributes => EntityState?.Attributes;
public Dictionary<string, object>? Attributes => EntityState?.Attributes;

/// <summary>
/// The full state of this Entity
Expand Down Expand Up @@ -110,7 +110,7 @@ protected Entity(IHaContext haContext, string entityId) : base(haContext, entity
{ }

/// <inheritdoc />
public override TAttributes? Attributes => EntityState?.Attributes;
public new virtual TAttributes? Attributes => EntityState?.Attributes;

/// <inheritdoc />
public override TEntityState? EntityState => MapState(base.EntityState);
Expand Down
4 changes: 2 additions & 2 deletions src/HassModel/NetDeamon.HassModel/Entities/EntityState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public record EntityState
/// <summary>
/// The attributes
/// </summary>
public virtual object? Attributes => AttributesJson?.Deserialize<Dictionary<string, object>>() ?? [];
public Dictionary<string, object>? Attributes => AttributesJson?.Deserialize<Dictionary<string, object>>() ?? [];

/// <summary>Last changed, when state changed from and to different values</summary>
[JsonPropertyName("last_changed")] public DateTime? LastChanged { get; init; }
Expand Down Expand Up @@ -52,5 +52,5 @@ public EntityState(EntityState source) : base(source)
}

/// <inheritdoc/>
public override TAttributes? Attributes => _attributesLazy.Value;
public new virtual TAttributes? Attributes => _attributesLazy.Value;
}