feat: partial-support for authorized entrance
This commit is contained in:
parent
dabab6757b
commit
064595c3e3
@ -76,8 +76,10 @@ public class ControlServer : IControlServer
|
||||
}
|
||||
response.Close();
|
||||
|
||||
if (notify)
|
||||
if (notify && _onEventRecived is not null)
|
||||
{
|
||||
//don't await this, we don't care about the result.
|
||||
//and we don't want to block the server thread.
|
||||
_ = _onEventRecived?.Invoke(sensorEvent);
|
||||
}
|
||||
}
|
||||
@ -106,8 +108,8 @@ public class ControlServer : IControlServer
|
||||
writer.Write(message);
|
||||
}
|
||||
|
||||
public record UpdateResponse(bool disarm, Card[] cards);
|
||||
public record Card(string id, string name);
|
||||
private record UpdateResponse(bool disarm, Card[] cards);
|
||||
private record Card(string id, string name);
|
||||
private bool HandleSensorEvent(SensorEvent se)
|
||||
{
|
||||
if (se.Type == EventType.Update && _disarmRequestPending)
|
||||
@ -118,9 +120,10 @@ public class ControlServer : IControlServer
|
||||
}
|
||||
|
||||
_events.TryGetValue(se.EventId, out var storedEvent);
|
||||
//New One
|
||||
if (storedEvent is null)
|
||||
{
|
||||
//New One
|
||||
//ESP does not send this type of event yet
|
||||
if (se.Type == EventType.DisarmedEntrance)
|
||||
{
|
||||
_disarmRequestPending = false;
|
||||
@ -129,11 +132,18 @@ public class ControlServer : IControlServer
|
||||
return true;
|
||||
}
|
||||
|
||||
//Alarm is armed and fired.
|
||||
if (se.Type == EventType.Fired)
|
||||
{
|
||||
//Check pending desarmed.
|
||||
se.Authorization = _disarmRequestPending ? Authorization.Authorized : Authorization.Unauthorized;
|
||||
//Check pending disarm request.
|
||||
if (_disarmRequestPending)
|
||||
{
|
||||
se.Authorization = Authorization.Authorized;
|
||||
se.Type = EventType.DisarmedEntrance;
|
||||
_disarmRequestPending = false;
|
||||
return true;
|
||||
}
|
||||
se.Authorization = Authorization.Unauthorized;
|
||||
_events.Add(se.EventId, se);
|
||||
return true;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ namespace ControlServer;
|
||||
public record SensorEvent(long EventId, EventType Type, string Data)
|
||||
{
|
||||
public Authorization Authorization { get; set; }
|
||||
public EventType Type { get; set; } = Type;
|
||||
};
|
||||
|
||||
public enum EventType
|
||||
|
Loading…
Reference in New Issue
Block a user