'array', 'demo' => 'boolean', 'last_seen_at' => 'datetime', ]; public function room(): BelongsTo { return $this->belongsTo(Room::class); } public function entities(): HasMany { return $this->hasMany(Entity::class); } /** * Reachable now. Real devices must have been seen recently (kept fresh by MQTT); a * never-seen real device is offline. Only demo devices are "assumed reachable" when * they have no last_seen, so the seeded demo doesn't rot. */ public function isOnline(): bool { if ($this->status !== 'active') { return false; } if ($this->last_seen_at !== null) { return $this->last_seen_at->gt(now()->subMinutes(10)); } return $this->demo; } }