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();
|
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);
|
_ = _onEventRecived?.Invoke(sensorEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,8 +108,8 @@ public class ControlServer : IControlServer
|
|||||||
writer.Write(message);
|
writer.Write(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public record UpdateResponse(bool disarm, Card[] cards);
|
private record UpdateResponse(bool disarm, Card[] cards);
|
||||||
public record Card(string id, string name);
|
private record Card(string id, string name);
|
||||||
private bool HandleSensorEvent(SensorEvent se)
|
private bool HandleSensorEvent(SensorEvent se)
|
||||||
{
|
{
|
||||||
if (se.Type == EventType.Update && _disarmRequestPending)
|
if (se.Type == EventType.Update && _disarmRequestPending)
|
||||||
@ -118,9 +120,10 @@ public class ControlServer : IControlServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
_events.TryGetValue(se.EventId, out var storedEvent);
|
_events.TryGetValue(se.EventId, out var storedEvent);
|
||||||
|
//New One
|
||||||
if (storedEvent is null)
|
if (storedEvent is null)
|
||||||
{
|
{
|
||||||
//New One
|
//ESP does not send this type of event yet
|
||||||
if (se.Type == EventType.DisarmedEntrance)
|
if (se.Type == EventType.DisarmedEntrance)
|
||||||
{
|
{
|
||||||
_disarmRequestPending = false;
|
_disarmRequestPending = false;
|
||||||
@ -129,11 +132,18 @@ public class ControlServer : IControlServer
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Alarm is armed and fired.
|
||||||
if (se.Type == EventType.Fired)
|
if (se.Type == EventType.Fired)
|
||||||
{
|
{
|
||||||
//Check pending desarmed.
|
//Check pending disarm request.
|
||||||
se.Authorization = _disarmRequestPending ? Authorization.Authorized : Authorization.Unauthorized;
|
if (_disarmRequestPending)
|
||||||
|
{
|
||||||
|
se.Authorization = Authorization.Authorized;
|
||||||
|
se.Type = EventType.DisarmedEntrance;
|
||||||
_disarmRequestPending = false;
|
_disarmRequestPending = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
se.Authorization = Authorization.Unauthorized;
|
||||||
_events.Add(se.EventId, se);
|
_events.Add(se.EventId, se);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ namespace ControlServer;
|
|||||||
public record SensorEvent(long EventId, EventType Type, string Data)
|
public record SensorEvent(long EventId, EventType Type, string Data)
|
||||||
{
|
{
|
||||||
public Authorization Authorization { get; set; }
|
public Authorization Authorization { get; set; }
|
||||||
|
public EventType Type { get; set; } = Type;
|
||||||
};
|
};
|
||||||
|
|
||||||
public enum EventType
|
public enum EventType
|
||||||
|
Loading…
Reference in New Issue
Block a user