Skip to content

Commit

Permalink
udpate
Browse files Browse the repository at this point in the history
  • Loading branch information
RicoSuter committed Nov 22, 2024
1 parent 90ce4a4 commit 6ab5f5f
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/Namotion.Shelly/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static IServiceCollection AddShellyDevice(this IServiceCollection service
return device;
})
.AddSingleton<IHostedService>(sp => sp.GetRequiredKeyedService<ShellyDeviceBase>(name));
.AddSingleton<IHostedService>(sp => sp.GetRequiredKeyedService<ShellyDevice>(name));
}

public static ShellyDevice GetRequiredShellyDevice(this IServiceProvider serviceProvider, string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Namotion.Shelly
{
[GenerateProxy]
public class ShellyCoverBase :
public partial class ShellyCover :
IThing,
IIconProvider,
IPowerConsumptionSensor,
Expand All @@ -32,10 +32,12 @@ public class ShellyCoverBase :

public DateTimeOffset? LastUpdated => Parent?.LastUpdated;

[Derived]
[State(Unit = StateUnit.Percent)]
public virtual decimal? Position => (100 - CurrentPosition) / 100m;
public decimal? Position => (100 - CurrentPosition) / 100m;

public virtual RollerShutterState State => LastState switch
[Derived]
public RollerShutterState State => LastState switch
{
"open" => RollerShutterState.Opening,
"close" => RollerShutterState.Closing,
Expand All @@ -49,41 +51,42 @@ public class ShellyCoverBase :
};

[State]
public virtual bool? IsMoving => PowerConsumption > 1;
[Derived]
public bool? IsMoving => PowerConsumption > 1;

[State(Unit = StateUnit.Watt)]
[JsonPropertyName("power")]
public virtual decimal? PowerConsumption { get; set; }
public partial decimal? PowerConsumption { get; set; }

[JsonPropertyName("state"), State]
public virtual string? LastState { get; set; }
public partial string? LastState { get; set; }

[JsonPropertyName("source"), State]
public virtual string? Source { get; set; }
public partial string? Source { get; set; }

[JsonPropertyName("is_valid"), State]
public virtual bool? IsValid { get; set; }
public partial bool? IsValid { get; set; }

[JsonPropertyName("safety_switch"), State]
public virtual bool? IsSafetySwitchTriggered { get; set; }
public partial bool? IsSafetySwitchTriggered { get; set; }

[JsonPropertyName("overtemperature"), State]
public virtual bool? OvertemperatureOccurred { get; set; }
public partial bool? OvertemperatureOccurred { get; set; }

[JsonPropertyName("stop_reason"), State]
public virtual string? StopReason { get; set; }
public partial string? StopReason { get; set; }

[JsonPropertyName("last_direction"), State]
public virtual string? LastDirection { get; set; }
public partial string? LastDirection { get; set; }

[JsonPropertyName("current_pos")]
public virtual int? CurrentPosition { get; set; }
public partial int? CurrentPosition { get; set; }

[JsonPropertyName("calibrating"), State]
public virtual bool? IsCalibrating { get; set; }
public partial bool? IsCalibrating { get; set; }

[JsonPropertyName("positioning"), State]
public virtual bool? IsPositioning { get; set; }
public partial bool? IsPositioning { get; set; }

[Operation]
public async Task OpenAsync(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Namotion.Shelly
[ThingType("HomeBlaze.Shelly.ShellyDevice")]
[DisplayName("Shelly Device")]
[GenerateProxy]
public abstract class ShellyDeviceBase :
public partial class ShellyDevice :
PollingThing,
IConnectedThing,
INetworkAdapter,
Expand All @@ -32,30 +32,30 @@ public abstract class ShellyDeviceBase :

public override string Title => $"Shelly: {Information?.Name ?? Information?.Application}";

public virtual DateTimeOffset? LastUpdated { get; protected set; }
public partial DateTimeOffset? LastUpdated { get; protected set; }

public virtual string IconName => "fas fa-box";
public string IconName => "fas fa-box";

[Configuration]
public virtual string? IpAddress { get; set; }
public string? IpAddress { get; set; }

[Configuration]
public virtual int RefreshInterval { get; set; } = 15 * 1000;
public int RefreshInterval { get; set; } = 15 * 1000;

[State]
public virtual bool IsConnected { get; internal set; }
public partial bool IsConnected { get; internal set; }

[ScanForState]
public virtual ShellyInformation? Information { get; protected set; }
public partial ShellyInformation? Information { get; protected set; }

[State]
public virtual ShellyEnergyMeter? EnergyMeter { get; internal set; }
public partial ShellyEnergyMeter? EnergyMeter { get; internal set; }

[State]
public virtual ShellySwitch? Switch0 { get; internal set; }
public partial ShellySwitch? Switch0 { get; internal set; }

[State]
public virtual ShellySwitch? Switch1 { get; internal set; }
public partial ShellySwitch? Switch1 { get; internal set; }

[State]
public virtual ShellyCover? Cover { get; protected set; }
Expand All @@ -65,7 +65,7 @@ public abstract class ShellyDeviceBase :

internal ShellyWebSocketClient? WebSocketClient { get; private set; }

public ShellyDeviceBase(IHttpClientFactory httpClientFactory, ILogger<ShellyDevice> logger)
public ShellyDevice(IHttpClientFactory httpClientFactory, ILogger<ShellyDevice> logger)
: base( logger)
{
_httpClientFactory = httpClientFactory;
Expand Down
20 changes: 10 additions & 10 deletions src/Namotion.Shelly/ShellyEnergyDataBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,62 @@
namespace Namotion.Shelly
{
[GenerateProxy]
public class ShellyEnergyDataBase
public partial class ShellyEnergyData
{
/// <summary>
/// Gets the identifier.
/// </summary>
[JsonPropertyName("id")]
public virtual int Id { get; init; }
public partial int Id { get; internal set; }

/// <summary>
/// Gets the total active energy across all phases, measured in watt-hours.
/// </summary>
[State(Unit = StateUnit.WattHour)]
[JsonPropertyName("total_act")]
public virtual decimal TotalActiveEnergy { get; init; }
public partial decimal TotalActiveEnergy { get; internal set; }

/// <summary>
/// Gets the total active returned energy across all phases, measured in watt-hours.
/// </summary>
[State(Unit = StateUnit.WattHour)]
[JsonPropertyName("total_act_ret")]
public virtual double TotalActiveReturnedEnergy { get; init; }
public partial double TotalActiveReturnedEnergy { get; internal set; }

/// <summary>
/// Gets the total active energy for phase A, measured in watt-hours.
/// </summary>
[JsonPropertyName("a_total_act_energy")]
public virtual double PhaseATotalActiveEnergy { get; init; }
public partial double PhaseATotalActiveEnergy { get; internal set; }

/// <summary>
/// Gets the total active returned energy for phase A, measured in watt-hours.
/// </summary>
[JsonPropertyName("a_total_act_ret_energy")]
public virtual double PhaseATotalActiveReturnedEnergy { get; init; }
public partial double PhaseATotalActiveReturnedEnergy { get; internal set; }

/// <summary>
/// Gets the total active energy for phase B, measured in watt-hours.
/// </summary>
[JsonPropertyName("b_total_act_energy")]
public virtual double PhaseBTotalActiveEnergy { get; init; }
public partial double PhaseBTotalActiveEnergy { get; internal set; }

/// <summary>
/// Gets the total active returned energy for phase B, measured in watt-hours.
/// </summary>
[JsonPropertyName("b_total_act_ret_energy")]
public virtual double PhaseBTotalActiveReturnedEnergy { get; init; }
public partial double PhaseBTotalActiveReturnedEnergy { get; internal set; }

/// <summary>
/// Gets the total active energy for phase C, measured in watt-hours.
/// </summary>
[JsonPropertyName("c_total_act_energy")]
public virtual double PhaseCTotalActiveEnergy { get; init; }
public partial double PhaseCTotalActiveEnergy { get; internal set; }

/// <summary>
/// Gets the total active returned energy for phase C, measured in watt-hours.
/// </summary>
[JsonPropertyName("c_total_act_ret_energy")]
public virtual double PhaseCTotalActiveReturnedEnergy { get; init; }
public partial double PhaseCTotalActiveReturnedEnergy { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Namotion.Shelly
{
[GenerateProxy]
public class ShellyEnergyMeterBase :
public partial class ShellyEnergyMeter :
IThing,
IIconProvider,
IPowerConsumptionSensor,
Expand All @@ -29,55 +29,64 @@ public class ShellyEnergyMeterBase :

public DateTimeOffset? LastUpdated => Parent?.LastUpdated;

public virtual decimal? PowerConsumption => TotalActivePower;
[Derived]
public decimal? PowerConsumption => TotalActivePower;

[ScanForState]
public virtual ShellyEnergyData? EnergyData { get; internal set; }
public partial ShellyEnergyData? EnergyData { get; internal set; }

[State]
public virtual ShellyEnergyMeterPhase PhaseA { get; protected set; } = new ShellyEnergyMeterPhase("a");
public partial ShellyEnergyMeterPhase PhaseA { get; protected set; }

[State]
public virtual ShellyEnergyMeterPhase PhaseB { get; protected set; } = new ShellyEnergyMeterPhase("b");
public partial ShellyEnergyMeterPhase PhaseB { get; protected set; }

[State]
public virtual ShellyEnergyMeterPhase PhaseC { get; protected set; } = new ShellyEnergyMeterPhase("c");
public partial ShellyEnergyMeterPhase PhaseC { get; protected set; }

[State(Unit = StateUnit.WattHour, IsCumulative = true)]
[Derived]
public decimal? TotalConsumedEnergy => EnergyData?.TotalActiveEnergy;

/// <summary>
/// Gets or sets the ID of the EM1 component.
/// </summary>
[JsonPropertyName("id")]
public int Id { get; set; }
public partial int Id { get; set; }

/// <summary>
/// Gets or sets the total current in amperes.
/// </summary>
[JsonPropertyName("total_current"), State(Unit = StateUnit.Ampere)]
public double TotalCurrent { get; set; }
public partial double TotalCurrent { get; set; }

/// <summary>
/// Gets or sets the total active power in watts.
/// Active power (real power) is the actual power consumed by electrical equipment to perform useful work, such as running a motor or lighting a bulb.
/// </summary>
[JsonPropertyName("total_act_power"), State(Unit = StateUnit.Watt)]
public decimal TotalActivePower { get; set; }
public partial decimal TotalActivePower { get; set; }

/// <summary>
/// Gets or sets the total apparent power in volt-amperes.
/// Apparent power is the combination of active power (real power) and reactive power.
/// It represents the total power used by the electrical equipment to do work and sustain the magnetic and electric fields.
/// </summary>
[JsonPropertyName("total_aprt_power"), State(Unit = StateUnit.Watt)]
public double TotalApparentPower { get; set; }
public partial double TotalApparentPower { get; set; }

/// <summary>
/// Gets or sets the current of the neutral line in amperes.
/// </summary>
[JsonPropertyName("n_current"), State(Unit = StateUnit.Ampere)]
public double? NeutralCurrent { get; set; }
public partial double? NeutralCurrent { get; set; }

public ShellyEnergyMeter()
{
PhaseA = new ShellyEnergyMeterPhase("a");
PhaseB = new ShellyEnergyMeterPhase("b");
PhaseC = new ShellyEnergyMeterPhase("c");
}

public void Update()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Namotion.Shelly
{
[GenerateProxy]
public class ShellyEnergyMeterPhaseBase :
public partial class ShellyEnergyMeterPhase :
IThing,
IIconProvider,
ILastUpdatedProvider
Expand All @@ -28,7 +28,7 @@ public class ShellyEnergyMeterPhaseBase :

public DateTimeOffset? LastUpdated => Parent?.LastUpdated;

public ShellyEnergyMeterPhaseBase(string phase)
public ShellyEnergyMeterPhase(string phase)
{
_phase = phase;
}
Expand All @@ -37,51 +37,51 @@ public ShellyEnergyMeterPhaseBase(string phase)
/// Gets or sets the current of phase A in amperes.
/// </summary>
[State(Unit = StateUnit.Ampere), JsonInclude]
public virtual double Current { get; internal set; }
public partial double Current { get; internal set; }

/// <summary>
/// Gets or sets the voltage of phase A in volts.
/// </summary>
[State(Unit = StateUnit.Volt), JsonInclude]
public virtual double Voltage { get; internal set; }
public partial double Voltage { get; internal set; }

/// <summary>
/// Gets or sets the active power of phase A in watts.
/// Active power (real power) is the actual power consumed by electrical equipment to perform useful work, such as running a motor or lighting a bulb.
/// </summary>
[State(Unit = StateUnit.Watt), JsonInclude]
public virtual double ActivePower { get; internal set; }
public partial double ActivePower { get; internal set; }

/// <summary>
/// Gets or sets the apparent power of phase A in volt-amperes.
/// Apparent power is the combination of active power (real power) and reactive power.
/// It represents the total power used by the electrical equipment to do work and sustain the magnetic and electric fields.
/// </summary>
[State(Unit = StateUnit.Watt), JsonInclude]
public virtual double ApparentPower { get; internal set; }
public partial double ApparentPower { get; internal set; }

/// <summary>
/// Gets or sets the power factor of phase A.
/// </summary>
[State, JsonInclude]
public virtual double PowerFactor { get; internal set; }
public partial double PowerFactor { get; internal set; }

/// <summary>
/// Gets or sets the frequency of phase A in hertz.
/// </summary>
[State(Unit = StateUnit.Hertz), JsonInclude]
public virtual double Frequency { get; internal set; }
public partial double Frequency { get; internal set; }

/// <summary>
/// Gets or sets the total active energy for phase A, measured in watts.
/// </summary>
[State(Unit = StateUnit.WattHour), JsonInclude]
public double? TotalActiveEnergy { get; internal set; }
public partial double? TotalActiveEnergy { get; internal set; }

/// <summary>
/// Gets or sets the total active returned energy for phase A, measured in watts.
/// </summary>
[State(Unit = StateUnit.WattHour), JsonInclude]
public double? TotalActiveReturnedEnergy { get; internal set; }
public partial double? TotalActiveReturnedEnergy { get; internal set; }
}
}
Loading

0 comments on commit 6ab5f5f

Please sign in to comment.