Integrate dscKeybusInterface with portal
This commit is contained in:
parent
0668449f95
commit
1fa0596f6a
|
@ -751,15 +751,42 @@ class StatsViewSet(viewsets.ViewSet, List):
|
|||
|
||||
@action(detail=False, methods=['post'])
|
||||
def alarm(self, request):
|
||||
# Sample messages:
|
||||
# {'data': 'Connected'}
|
||||
# {'data': 'Trouble status on'}
|
||||
# {'data': 'Exit delay in progress: Partition 1'}
|
||||
# {'data': 'Disarmed: Partition 1'}
|
||||
# {'data': 'Armed away: Partition 1'}
|
||||
# {'data': 'Alarm: Partition 1'}
|
||||
# {'data': 'Alarm: Partition 2'}
|
||||
# {'data': 'Zone alarm restored: 1'}
|
||||
# {'data': 'Zone alarm restored: 3'}
|
||||
# {'data': 'Disarmed: Partition 1'}
|
||||
# {'data': 'Disarmed: Partition 2'}
|
||||
|
||||
try:
|
||||
alarm = dict(time=time.time(), data=int(request.data['data']))
|
||||
cache.set('alarm', alarm)
|
||||
return Response(200)
|
||||
except ValueError:
|
||||
raise exceptions.ValidationError(dict(data='Invalid integer.'))
|
||||
data = str(request.data['data'])
|
||||
except KeyError:
|
||||
raise exceptions.ValidationError(dict(data='This field is required.'))
|
||||
|
||||
logging.info('Alarm data: %s', data)
|
||||
|
||||
alarm = None
|
||||
if data.startswith('Armed'):
|
||||
alarm = 'Armed'
|
||||
elif data.startswith('Disarmed'):
|
||||
alarm = 'Disarmed'
|
||||
elif data.startswith('Exit delay in progress'):
|
||||
alarm = 'Exit delay'
|
||||
elif data.startswith('Alarm'):
|
||||
alarm = 'TRIGGERED!'
|
||||
|
||||
if alarm:
|
||||
logging.info('Settings alarm status to: %s', alarm)
|
||||
cache.set('alarm', alarm)
|
||||
|
||||
return Response(200)
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def track(self, request):
|
||||
if 'name' not in request.data:
|
||||
|
|
|
@ -254,11 +254,7 @@ export function Home(props) {
|
|||
const getTrackAgo = (x) => stats && stats.track && stats.track[x] ? moment.unix(stats.track[x]['time']).tz('America/Edmonton').fromNow() : '';
|
||||
const getTrackName = (x) => stats && stats.track && stats.track[x] && stats.track[x]['first_name'] ? stats.track[x]['first_name'] : 'Unknown';
|
||||
|
||||
//const alarmStat = () => stats && stats.alarm && moment().unix() - stats.alarm['time'] < 300 ? stats.alarm['data'] < 270 ? 'Armed' : 'Disarmed' : 'Unknown';
|
||||
const alarmStat = () => 'Unknown';
|
||||
|
||||
//const doorOpenStat = () => alarmStat() === 'Disarmed' && stats.alarm['data'] > 360 ? ', door open' : '';
|
||||
const doorOpenStat = () => '';
|
||||
const alarmStat = () => stats && stats.alarm ? stats.alarm.toString() : 'Unknown'; // toString prevents crash from cached alarm Object
|
||||
|
||||
const closedStat = (x) => stats && stats.closing ? moment().unix() > stats.closing['time'] ? 'Closed' : 'Open until ' + stats.closing['time_str'] : 'Unknown';
|
||||
|
||||
|
@ -401,7 +397,7 @@ export function Home(props) {
|
|||
|
||||
<p>ORD3 printer: {printer3dStat('ord3')}</p>
|
||||
|
||||
{user && <p>Alarm status: {alarmStat()}{doorOpenStat()}</p>}
|
||||
{user && <p>Alarm status: {alarmStat()}</p>}
|
||||
|
||||
{user && <p>Hosting status: {closedStat()}</p>}
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue
Block a user