refactor(netd): clean up code
All checks were successful
Discord / discord commits (push) Has been skipped
All checks were successful
Discord / discord commits (push) Has been skipped
This commit is contained in:
parent
70fe1a0e81
commit
f24026db00
2 changed files with 37 additions and 38 deletions
|
@ -26,10 +26,10 @@ dotnet_sort_system_directives_first = true
|
||||||
file_header_template = unset
|
file_header_template = unset
|
||||||
|
|
||||||
# this. and Me. preferences
|
# this. and Me. preferences
|
||||||
dotnet_style_qualification_for_event = false:silent
|
dotnet_style_qualification_for_event = true
|
||||||
dotnet_style_qualification_for_field = false:silent
|
dotnet_style_qualification_for_field = true
|
||||||
dotnet_style_qualification_for_method = false:silent
|
dotnet_style_qualification_for_method = true
|
||||||
dotnet_style_qualification_for_property = false:silent
|
dotnet_style_qualification_for_property = true
|
||||||
|
|
||||||
# Language keywords vs BCL types preferences
|
# Language keywords vs BCL types preferences
|
||||||
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
|
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
|
||||||
|
|
|
@ -11,51 +11,50 @@ namespace NetDaemonConfig.Apps.Frontend.BathroomLight
|
||||||
[NetDaemonApp]
|
[NetDaemonApp]
|
||||||
public class BathroomLight
|
public class BathroomLight
|
||||||
{
|
{
|
||||||
public BathroomLight(Services services, Entities entities)
|
private LightEntity? Entity { get; set; }
|
||||||
{
|
private InputTextEntity? BrightnessInput { get; set; }
|
||||||
// ZigBee needs restart to access Light
|
|
||||||
entities.Button.Slzb06p7CoreRestart.Press();
|
|
||||||
|
|
||||||
LightEntity? bathroomLight = entities.Light.Tz3210KatchgxyTs0505bLight;
|
private void BrightnessCallback(Action<double, double> callback)
|
||||||
InputTextEntity? bathroomLightBrightness = entities.InputText.BathroomLightBrightness;
|
|
||||||
|
|
||||||
var brightnessCallback = (Action<double, double> callback) =>
|
|
||||||
{
|
{
|
||||||
double? currentBrightness = bathroomLight?.Attributes?.Brightness;
|
double? currentBrightness = this.Entity?.Attributes?.Brightness;
|
||||||
|
|
||||||
if (currentBrightness is not null)
|
if (currentBrightness is not null)
|
||||||
{
|
{
|
||||||
double currentBrightnessPercent = Math.Floor((double)currentBrightness / 2.54);
|
double currentBrightnessPercent = Math.Floor((double)currentBrightness / 2.54);
|
||||||
double inputBrightnessPercent = Double.Parse(bathroomLightBrightness.State ?? "0");
|
double inputBrightnessPercent = double.Parse(this.BrightnessInput?.State ?? "0");
|
||||||
|
|
||||||
if (currentBrightnessPercent != inputBrightnessPercent)
|
if (currentBrightnessPercent != inputBrightnessPercent)
|
||||||
{
|
{
|
||||||
callback(currentBrightnessPercent, inputBrightnessPercent);
|
callback(currentBrightnessPercent, inputBrightnessPercent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
bathroomLightBrightness
|
public BathroomLight(Services services, Entities entities)
|
||||||
.StateAllChanges()
|
|
||||||
.Subscribe((_) => brightnessCallback((current, input) =>
|
|
||||||
{
|
{
|
||||||
|
// ZigBee needs restart to access Light
|
||||||
|
entities.Button.Slzb06p7CoreRestart.Press();
|
||||||
|
|
||||||
|
this.Entity = entities.Light.Tz3210KatchgxyTs0505bLight;
|
||||||
|
this.BrightnessInput = entities.InputText.BathroomLightBrightness;
|
||||||
|
|
||||||
|
this.BrightnessInput
|
||||||
|
.StateAllChanges()
|
||||||
|
.Subscribe((_) =>
|
||||||
|
this.BrightnessCallback((_, input) =>
|
||||||
services.Light.TurnOn(
|
services.Light.TurnOn(
|
||||||
target: ServiceTarget.FromEntity("light.tz3210_katchgxy_ts0505b_light"),
|
target: ServiceTarget.FromEntity("light.tz3210_katchgxy_ts0505b_light"),
|
||||||
brightness: Math.Floor(input * 2.54 + 1));
|
brightness: Math.Floor(input * 2.54 + 1))));
|
||||||
}));
|
|
||||||
|
|
||||||
bathroomLight
|
this.Entity
|
||||||
.StateAllChanges()
|
.StateAllChanges()
|
||||||
.Subscribe((_) => brightnessCallback((current, input) =>
|
.Subscribe((_) =>
|
||||||
{
|
this.BrightnessCallback((current, _) =>
|
||||||
bathroomLightBrightness.SetValue(current.ToString());
|
this.BrightnessInput.SetValue(current.ToString())));
|
||||||
}));
|
|
||||||
|
|
||||||
// Init value
|
// Init value
|
||||||
brightnessCallback((current, input) =>
|
this.BrightnessCallback((current, _) =>
|
||||||
{
|
this.BrightnessInput.SetValue(current.ToString()));
|
||||||
bathroomLightBrightness.SetValue(current.ToString());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue