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

net-daemon / netdaemon / 6682362857

29 Oct 2023 08:56AM UTC coverage: 79.505% (-1.2%) from 80.706%
6682362857

push

github

web-flow
Bump Roslynator.Analyzers from 4.5.0 to 4.6.1 (#960)

Bumps [Roslynator.Analyzers](https://github.com/dotnet/roslynator) from 4.5.0 to 4.6.1.
- [Release notes](https://github.com/dotnet/roslynator/releases)
- [Changelog](https://github.com/dotnet/roslynator/blob/main/ChangeLog.md)
- [Commits](https://github.com/dotnet/roslynator/compare/v4.5.0...v4.6.1)

---
updated-dependencies:
- dependency-name: Roslynator.Analyzers
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

802 of 1143 branches covered (0.0%)

Branch coverage included in aggregate %.

2895 of 3507 relevant lines covered (82.55%)

50.4 hits per line

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

74.42
/src/HassModel/NetDeamon.HassModel/Entities/Entity.cs
1
namespace NetDaemon.HassModel.Entities;
2

3
/// <summary>Represents a Home Assistant entity with its state, changes and services</summary>
4
public record Entity : IEntityCore
×
5
{
6
    /// <summary>
7
    /// The IHAContext
8
    /// </summary>
9
    public IHaContext HaContext { get; }
123✔
10

11
    /// <summary>
12
    /// Entity id being handled by this entity
13
    /// </summary>
14
    public string EntityId { get; }
164✔
15

16
    /// <summary>
17
    /// Creates a new instance of a Entity class
18
    /// </summary>
19
    /// <param name="haContext">The Home Assistant context associated with this Entity</param>
20
    /// <param name="entityId">The id of this Entity</param>
21
    public Entity(IHaContext haContext, string entityId)
59✔
22
    {
23
        HaContext = haContext;
59✔
24
        EntityId = entityId;
59✔
25
    }
59✔
26

27
    /// <summary>Copy constructor from IEntityCore</summary>
28
    public Entity(IEntityCore entity)
14✔
29
    {
30
        ArgumentNullException.ThrowIfNull(entity);
14✔
31
        HaContext = entity.HaContext;
14✔
32
        EntityId = entity.EntityId;
14✔
33
    }
14✔
34
        
35
    /// <summary>
36
    /// Area name of entity
37
    /// </summary>
38
    public string? Area => HaContext.GetAreaFromEntityId(EntityId)?.Name;
1!
39

40
    /// <summary>The current state of this Entity</summary>
41
    public string? State => EntityState?.State;
4!
42

43
    /// <summary>
44
    /// The current Attributes of this Entity
45
    /// </summary>
46
    public virtual object? Attributes => EntityState?.Attributes;
×
47

48
    /// <summary>
49
    /// The full state of this Entity
50
    /// </summary>
51
    public virtual EntityState? EntityState => HaContext.GetState(EntityId);
90✔
52

53
    /// <summary>
54
    /// Observable that emits all state changes, including attribute changes.<br/>
55
    /// Use <see cref="System.ObservableExtensions.Subscribe{T}(System.IObservable{T})"/> to subscribe to the returned observable and receive state changes.
56
    /// </summary>
57
    /// <example>
58
    /// <code>
59
    /// bedroomLight.StateAllChanges()
60
    ///     .Where(s =&gt; s.Old?.Attributes?.Brightness &lt; 128 
61
    ///              &amp;&amp; s.New?.Attributes?.Brightness &gt;= 128)
62
    ///     .Subscribe(e =&gt; HandleBrightnessOverHalf());
63
    /// </code>
64
    /// </example>
65
    public virtual IObservable<StateChange> StateAllChanges() =>
66
        HaContext.StateAllChanges().Where(e => e.Entity.EntityId == EntityId);
33✔
67

68
    /// <summary>
69
    /// Observable that emits state changes where New.State != Old.State<br/>
70
    /// Use <see cref="System.ObservableExtensions.Subscribe{T}(System.IObservable{T})"/> to subscribe to the returned observable and receive state changes.
71
    /// </summary>
72
    /// <example>
73
    /// <code>
74
    /// disabledLight.StateChanges()
75
    ///    .Where(s =&gt; s.New?.State == "on")
76
    ///    .Subscribe(e =&gt; e.Entity.TurnOff());
77
    /// </code>
78
    /// </example>
79
    public virtual IObservable<StateChange> StateChanges() =>
80
        StateAllChanges().StateChangesOnly();
×
81

82
    /// <summary>
83
    /// Calls a service using this entity as the target
84
    /// </summary>
85
    /// <param name="service">Name of the service to call. If the Domain of the service is the same as the domain of the Entity it can be omitted</param>
86
    /// <param name="data">Data to provide</param>
87
    public virtual void CallService(string service, object? data = null)
88
    {
89
        EntityExtensions.CallService(this, service, data);
1✔
90
    }
1✔
91
}
92

93
/// <summary>Represents a Home Assistant entity with its state, changes and services</summary>
94
public abstract record Entity<TEntity, TEntityState, TAttributes> : Entity
×
95
    where TEntity : Entity<TEntity, TEntityState, TAttributes>
96
    where TEntityState : EntityState<TAttributes>
97
    where TAttributes : class
98
{
99
    /// <summary>Copy constructor from IEntityCore</summary>
100
    protected Entity(IEntityCore entity) : base(entity)
6✔
101
    { }
6✔
102

103
    /// <summary>Constructor from haContext and entityId</summary>
104
    protected Entity(IHaContext haContext, string entityId) : base(haContext, entityId)
6✔
105
    { }
6✔
106

107
    /// <inheritdoc />
108
    public override TAttributes? Attributes => EntityState?.Attributes;
8!
109

110
    /// <inheritdoc />
111
    public override TEntityState? EntityState => MapState(base.EntityState);
47✔
112

113
    /// <inheritdoc />
114
    public override IObservable<StateChange<TEntity, TEntityState>> StateAllChanges() =>
115
        base.StateAllChanges().Select(e => new StateChange<TEntity, TEntityState>((TEntity)this, 
18✔
116
            Entities.EntityState.Map<TEntityState>(e.Old), 
18✔
117
            Entities.EntityState.Map<TEntityState>(e.New)));
18✔
118

119
    /// <inheritdoc />
120
    public override IObservable<StateChange<TEntity, TEntityState>> StateChanges() => StateAllChanges().StateChangesOnly();
1✔
121

122
    private static TEntityState? MapState(EntityState? state) => Entities.EntityState.Map<TEntityState>(state);
47✔
123
}
124
    
125
/// <summary>Represents a Home Assistant entity with its state, changes and services</summary>
126
public record Entity<TAttributes> : Entity<Entity<TAttributes>, EntityState<TAttributes>, TAttributes>
×
127
    where TAttributes : class
128
{
129
    // This type is needed because the base type has a recursive type parameter so it can not be used as a return value
130
        
131
    /// <summary>Copy constructor from IEntityCore</summary>
132
    public Entity(IEntityCore entity) : base(entity) { }
2✔
133
        
134
    /// <summary>Constructor from haContext and entityId</summary>
135
    public Entity(IHaContext haContext, string entityId) : base(haContext, entityId) { }
×
136
}
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