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

54 lines
1.4 KiB
Dart

class Sensor {
const Sensor({
required this.id,
required this.sensorId,
required this.confirmed,
this.name,
this.roomId,
this.x,
this.y,
this.version,
});
final int id;
final String sensorId; // BLE MAC / provisioning device ID
final bool confirmed; // true once seen on MQTT
final String? name; // human-readable label
final int? roomId;
final double? x; // room relative
final double? y; // room relative
final String? version;
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,
confirmed: json['confirmed'] as bool,
name: json['name'] as String?,
roomId: json['room_id'] as int?,
x: (json['x'] as num?)?.toDouble(),
y: (json['y'] as num?)?.toDouble(),
version: json['version'] as String?,
);
Sensor copyWith({
String? name,
int? roomId,
double? x,
double? y,
String? version,
}) =>
Sensor(
id: id,
sensorId: sensorId,
confirmed: confirmed,
name: name ?? this.name,
roomId: roomId ?? this.roomId,
x: x ?? this.x,
y: y ?? this.y,
version: version ?? this.version,
);
}