mirror of
https://github.com/Stefan-5422/-T5-Elektrifikatsiya.git
synced 2026-09-04 00:45:58 +02:00
Fix merge bugs
This commit is contained in:
@@ -6,12 +6,12 @@
|
|||||||
@using Elektrifikatsiya.Services.Implementations
|
@using Elektrifikatsiya.Services.Implementations
|
||||||
@using Elektrifikatsiya.Utilities
|
@using Elektrifikatsiya.Utilities
|
||||||
@using FluentResults;
|
@using FluentResults;
|
||||||
|
@using Blazorise.LoadingIndicator;
|
||||||
@inject IVersionProvider VersionProvider
|
@inject IVersionProvider VersionProvider
|
||||||
@inject IDeviceManagmentService DeviceManagmentService
|
@inject IDeviceManagmentService DeviceManagmentService
|
||||||
@inject IAuthenticationService AuthenticationService
|
@inject IAuthenticationService AuthenticationService
|
||||||
@inject IMessageService MessageService
|
@inject IMessageService MessageService
|
||||||
|
|
||||||
@inject IAuthenticationService AuthenticationService
|
|
||||||
|
|
||||||
<Row Style="height:50%; width:100%" Padding="Padding.Is3.OnDesktop.Is5.FromStart.OnMobile">
|
<Row Style="height:50%; width:100%" Padding="Padding.Is3.OnDesktop.Is5.FromStart.OnMobile">
|
||||||
<Row Style="height:90%; width:100%">
|
<Row Style="height:90%; width:100%">
|
||||||
@@ -27,8 +27,8 @@
|
|||||||
Add a plug via wifi
|
Add a plug via wifi
|
||||||
</Column>
|
</Column>
|
||||||
<Column ColumnSize="ColumnSize.Is3.Is6.WithOffset">
|
<Column ColumnSize="ColumnSize.Is3.Is6.WithOffset">
|
||||||
<LoadingIndicator @bind-Visible="@visible">
|
<LoadingIndicator @bind-Visible="@visible"/>
|
||||||
</LoadingIndicator>
|
|
||||||
</Column>
|
</Column>
|
||||||
</BarBrand>
|
</BarBrand>
|
||||||
</Bar>
|
</Bar>
|
||||||
@@ -97,36 +97,61 @@
|
|||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
List<IPAddress> ipAddresses = new List<IPAddress>();
|
|
||||||
|
|
||||||
List<IPAddress> ipAddresses = new List<IPAddress>();
|
List<IPAddress> ipAddresses = new List<IPAddress>();
|
||||||
|
|
||||||
bool visible = false;
|
Validation? ipValidation;
|
||||||
|
|
||||||
DateTime time = DateTime.UtcNow;
|
bool visible = true;
|
||||||
|
|
||||||
|
string ipText = null!;
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
ipAddresses.AddRange(MdnsDiscovery.GetChachedDevices());
|
MdnsDiscovery.OnDeviceFound += async ipAddress =>
|
||||||
|
|
||||||
System.Timers.Timer aTimer = new System.Timers.Timer(1000);
|
|
||||||
aTimer.Elapsed += (_, _) => {
|
|
||||||
DateTime dateTime = DateTime.UtcNow;
|
|
||||||
if(dateTime >= time.AddSeconds(3))
|
|
||||||
{
|
|
||||||
visible = false;
|
|
||||||
InvokeAsync(StateHasChanged);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
aTimer.Start();
|
|
||||||
|
|
||||||
MdnsDiscovery.OnDeviceFound += address =>
|
|
||||||
{
|
{
|
||||||
visible = true;
|
visible = false;
|
||||||
|
if (!ipAddresses.Contains(ipAddress))
|
||||||
ipAddresses.Add(address);
|
{
|
||||||
InvokeAsync(StateHasChanged);
|
ipAddresses.Add(ipAddress);
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
time = DateTime.UtcNow;
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MdnsDiscovery.FetchChachedDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task RegisterDevice(IPAddress ipAddress)
|
||||||
|
{
|
||||||
|
Result<Device> result = await DeviceManagmentService.RegisterDevice(ipAddress, (await AuthenticationService.GetUserAsync()).ValueOrDefault);
|
||||||
|
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
await MessageService.Success("Device added!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await MessageService.Error(string.Join(',', result.Errors.Select(e => e.Message)), "Adding device failed!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ValidateIPv4(ValidatorEventArgs e)
|
||||||
|
{
|
||||||
|
string? input = Convert.ToString(e.Value);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(input))
|
||||||
|
{
|
||||||
|
e.Status = ValidationStatus.None;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] splitValues = input.Split('.');
|
||||||
|
if (splitValues.Length != 4)
|
||||||
|
{
|
||||||
|
e.Status = ValidationStatus.Error;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Status = splitValues.All(r => byte.TryParse(r, out _)) ? ValidationStatus.Success : ValidationStatus.Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,8 +2,13 @@
|
|||||||
@using Blazorise.Components;
|
@using Blazorise.Components;
|
||||||
@using Elektrifikatsiya.Models;
|
@using Elektrifikatsiya.Models;
|
||||||
@using System.Net
|
@using System.Net
|
||||||
|
@using Elektrifikatsiya.Services
|
||||||
|
@using Elektrifikatsiya.Utilities
|
||||||
|
@using System.Diagnostics
|
||||||
@inject IVersionProvider VersionProvider
|
@inject IVersionProvider VersionProvider
|
||||||
|
|
||||||
|
@inject IDeviceStatusService DeviceStatusService;
|
||||||
|
|
||||||
<Div>
|
<Div>
|
||||||
<Row Padding="Padding.Is3">
|
<Row Padding="Padding.Is3">
|
||||||
<Div Display="Display.Flex.Row.OnDesktop" Margin=" Margin.Is3.FromBottom" Width="Width.Is100">
|
<Div Display="Display.Flex.Row.OnDesktop" Margin=" Margin.Is3.FromBottom" Width="Width.Is100">
|
||||||
@@ -34,7 +39,7 @@
|
|||||||
</Row>
|
</Row>
|
||||||
<Row>
|
<Row>
|
||||||
<Column>
|
<Column>
|
||||||
<Small>User: @context.Item.User</Small>
|
<Small>User: @context.Item.User.Name</Small>
|
||||||
<br />
|
<br />
|
||||||
<Small>Room: @context.Item.Room</Small>
|
<Small>Room: @context.Item.Room</Small>
|
||||||
</Column>
|
</Column>
|
||||||
@@ -44,7 +49,7 @@
|
|||||||
</Row>
|
</Row>
|
||||||
</Column>
|
</Column>
|
||||||
<Column ColumnSize="ColumnSize.Is4">
|
<Column ColumnSize="ColumnSize.Is4">
|
||||||
<Button Clicked="@ChangeButtonColor" Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Color="Color.Primary"Primary Outline>
|
<Button Position="Position.Absolute.Top.Is50.Start.Is50.Translate.Middle" Color="Color.Primary"Primary Outline>
|
||||||
<!--TODO: This button should change color-->
|
<!--TODO: This button should change color-->
|
||||||
<BarIcon IconName="IconName.Bolt" />
|
<BarIcon IconName="IconName.Bolt" />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -92,12 +97,22 @@
|
|||||||
|
|
||||||
@code {
|
@code {
|
||||||
//TODO: insert new event here if plug produces one
|
//TODO: insert new event here if plug produces one
|
||||||
List<Event> events = new List<Event>() { new Event("Placeholder", "Event", DateTime.Now), new Event("Placeholder", "Event", DateTime.Now), new Event("Placeholder", "Event", DateTime.Now) };
|
List<Event> events = new List<Event>() { new Event("Placeholder", "Placeholder", DateTime.Now), new Event("Placeholder", "Placeholder", DateTime.Now), new Event("Placeholder", "Placeholder", DateTime.Now) };
|
||||||
//TODO: insert new Device here if user adds one
|
//TODO: insert new Device here if user adds one
|
||||||
List<Device> plugs = new List<Device>() { new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "Josne", Role.Admin), "Raum"), new Device("ffff:ffff:ffff:ffff", "Josne", IPAddress.Broadcast, new User("Joe", "qiowruioewjfopa", Role.Admin), "Raum"), };
|
List<Device> plugs = new List<Device>();
|
||||||
//code for graph
|
//code for graph
|
||||||
LineChart<double> lineChart;
|
LineChart<double> lineChart;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
plugs = DeviceStatusService.GetDevices().ValueOrDefault ?? new List<Device>();
|
||||||
|
|
||||||
|
DeviceStatusService.OnDeviceStatusChanged += (_, e) =>
|
||||||
|
{
|
||||||
|
InvokeAsync(StateHasChanged);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
if (firstRender)
|
if (firstRender)
|
||||||
@@ -108,50 +123,47 @@
|
|||||||
|
|
||||||
async Task HandleRedraw()
|
async Task HandleRedraw()
|
||||||
{
|
{
|
||||||
|
labels.Clear();
|
||||||
await lineChart.Clear();
|
await lineChart.Clear();
|
||||||
|
await lineChart.AddLabelsDatasetsAndUpdate(labels, await GetLineChartDataset());
|
||||||
await lineChart.AddLabelsDatasetsAndUpdate(Labels, GetLineChartDataset());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: insert dataset of current and last voltage usages
|
//TODO: insert dataset of current and last voltage usages
|
||||||
LineChartDataset<double> GetLineChartDataset()
|
async Task<LineChartDataset<double>> GetLineChartDataset()
|
||||||
{
|
{
|
||||||
return new LineChartDataset<double>
|
return new LineChartDataset<double>
|
||||||
{
|
{
|
||||||
Label = "# of random number in thousands",
|
Label = "Wattage",
|
||||||
Data = RandomizeData(),
|
Data = await RandomizeData(),
|
||||||
BackgroundColor = backgroundColors,
|
|
||||||
BorderColor = borderColors,
|
|
||||||
Fill = true,
|
Fill = true,
|
||||||
PointRadius = 3,
|
PointRadius = 3,
|
||||||
CubicInterpolationMode = "monotone",
|
CubicInterpolationMode = "monotone",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] Labels = { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" };
|
List<string> labels = new List<string>();
|
||||||
List<string> backgroundColors = new List<string> { ChartColor.FromRgba(255, 99, 132, 0.2f), ChartColor.FromRgba(54, 162, 235, 0.2f), ChartColor.FromRgba(255, 206, 86, 0.2f), ChartColor.FromRgba(75, 192, 192, 0.2f), ChartColor.FromRgba(153, 102, 255, 0.2f), ChartColor.FromRgba(255, 159, 64, 0.2f) };
|
|
||||||
List<string> borderColors = new List<string> { ChartColor.FromRgba(255, 99, 132, 1f), ChartColor.FromRgba(54, 162, 235, 1f), ChartColor.FromRgba(255, 206, 86, 1f), ChartColor.FromRgba(75, 192, 192, 1f), ChartColor.FromRgba(153, 102, 255, 1f), ChartColor.FromRgba(255, 159, 64, 1f) };
|
|
||||||
|
|
||||||
List<double> RandomizeData()
|
async Task<List<double>> RandomizeData()
|
||||||
{
|
{
|
||||||
|
PrometheusQuery promQueryer = new PrometheusQuery("http://localhost:9090");
|
||||||
|
|
||||||
|
string plugnames = "";
|
||||||
|
foreach (Device device in plugs)
|
||||||
|
{
|
||||||
|
plugnames += $"shellyplug-s-{device.MacAddress}/relay/0|";
|
||||||
|
}
|
||||||
|
plugnames = plugnames[0..^1];
|
||||||
|
|
||||||
|
Debug.WriteLine($$"""sum(power{sensor=~"{{plugnames}}"})[1h:1m]""");
|
||||||
|
|
||||||
|
PrometheusDataWrapper? deviceData = (await promQueryer.Query($$"""sum(power{sensor=~"{{plugnames}}"})[1h:1m]"""))?.Data;
|
||||||
|
|
||||||
var r = new Random(DateTime.Now.Millisecond);
|
var r = new Random(DateTime.Now.Millisecond);
|
||||||
|
|
||||||
return new List<double> {
|
return deviceData?.MatrixTypeToTimestampFloatTuple().ValueOrDefault?.Select(x =>
|
||||||
r.Next( 3, 50 ) * r.NextDouble(),
|
{
|
||||||
r.Next( 3, 50 ) * r.NextDouble(),
|
labels.Add(DateTimeOffset.FromUnixTimeSeconds(long.Parse($"1{x.Item1}0")).UtcDateTime.ToLocalTime().ToShortTimeString());
|
||||||
r.Next( 3, 50 ) * r.NextDouble(),
|
return x.Item2;
|
||||||
r.Next( 3, 50 ) * r.NextDouble(),
|
}).ToList() ?? new List<double>();
|
||||||
r.Next( 3, 50 ) * r.NextDouble(),
|
|
||||||
r.Next( 3, 50 ) * r.NextDouble() };
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//private Background buttonColor = Background.Primary;
|
|
||||||
|
|
||||||
private void ChangeButtonColor()
|
|
||||||
{
|
|
||||||
//device.on = !device.on;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user