Files
companion/lib/domain/models/sensor.dart
T

50 lines
1.2 KiB
Dart

class Sensor {
const Sensor({
required this.id,
required this.sensorId,
this.name,
this.roomId,
this.x,
this.y,
this.rssiRef,
});
final int id;
final String sensorId; // BLE MAC / provisioning device ID
final String? name; // human-readable label
final int? roomId;
final double? x; // floor_x from API
final double? y; // floor_y from API
final double? rssiRef;
bool get isPlaced => roomId != null;
String get displayName => name ?? sensorId;
factory Sensor.fromJson(Map<String, dynamic> json) => Sensor(
id: json['id'] as int,
sensorId: json['sensor_id'] as String,
name: json['name'] as String?,
roomId: json['room_id'] as int?,
x: (json['floor_x'] as num?)?.toDouble(),
y: (json['floor_y'] as num?)?.toDouble(),
rssiRef: (json['rssi_ref'] as num?)?.toDouble(),
);
Sensor copyWith({
String? name,
int? roomId,
double? x,
double? y,
double? rssiRef,
}) =>
Sensor(
id: id,
sensorId: sensorId,
name: name ?? this.name,
roomId: roomId ?? this.roomId,
x: x ?? this.x,
y: y ?? this.y,
rssiRef: rssiRef ?? this.rssiRef,
);
}