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

46 lines
1.1 KiB
Dart

class Sensor {
const Sensor({
required this.id,
required this.sensorId,
this.name,
this.roomId,
this.x,
this.y,
});
final int id;
final String sensorId; // BLE MAC / provisioning device ID
final String? name; // human-readable label
final int? roomId;
final double? x; // room relative
final double? y; // room relative
bool get isPlaced => roomId != null && x != null && y != 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['x'] as num?)?.toDouble(),
y: (json['y'] 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,
);
}