updated view and database
This commit is contained in:
+21
-2
@@ -42,6 +42,20 @@ def _latest_config_ts(session, mac_address):
|
||||
return global_ts, device_ts, latest
|
||||
|
||||
|
||||
def _mark_wmt_checkin(device):
|
||||
"""Stamp a device as having checked in via the WMT client API.
|
||||
|
||||
Keeps the unified device record in sync: both the general monitoring
|
||||
'last_seen' and the WMT-specific 'wmt_last_seen' are advanced on every
|
||||
client interaction so the unified devices page reflects live state.
|
||||
"""
|
||||
if device is None:
|
||||
return
|
||||
now = datetime.utcnow()
|
||||
device.last_seen = now
|
||||
device.wmt_last_seen = now
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Endpoints
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -67,6 +81,10 @@ def get_config_timestamp():
|
||||
with get_db().get_session() as session:
|
||||
global_ts, device_info_reviewed_ts, latest = _latest_config_ts(session, mac)
|
||||
|
||||
# Stamp WMT check-in so the unified device record stays live
|
||||
device = session.query(Device).filter_by(mac_address=mac).first()
|
||||
_mark_wmt_checkin(device)
|
||||
|
||||
return jsonify({
|
||||
'global_updated_at': global_ts.isoformat() if global_ts != datetime(1970, 1, 1) else None,
|
||||
'device_info_reviewed_at': device_info_reviewed_ts.isoformat() if device_info_reviewed_ts != datetime(1970, 1, 1) else None,
|
||||
@@ -91,9 +109,9 @@ def get_device_config(mac_address):
|
||||
global_cfg = _get_or_create_global_config(session)
|
||||
device = session.query(Device).filter_by(mac_address=mac).first()
|
||||
|
||||
# Update last_seen if device is known
|
||||
# Update last_seen / wmt_last_seen if device is known
|
||||
if device:
|
||||
device.last_seen = datetime.utcnow()
|
||||
_mark_wmt_checkin(device)
|
||||
|
||||
_, device_ts, latest_ts = _latest_config_ts(session, mac)
|
||||
|
||||
@@ -214,6 +232,7 @@ def submit_update_request():
|
||||
|
||||
# Device is known from here on ─────────────────────────────
|
||||
device.last_seen = datetime.utcnow()
|
||||
_mark_wmt_checkin(device)
|
||||
if card_presence in ('enable', 'disable'):
|
||||
device.card_presence = card_presence
|
||||
|
||||
|
||||
Reference in New Issue
Block a user