fix: Sensor schema drift with upstream API
This commit is contained in:
@@ -24,10 +24,9 @@ class PhoenixSensorRepository implements SensorRepository {
|
||||
Sensor.fromJson(await client.getSensor(id));
|
||||
|
||||
@override
|
||||
Future<Sensor> updateSensor(int id, {String? name, double? rssiRef}) async {
|
||||
Future<Sensor> updateSensor(int id, {String? name}) async {
|
||||
final params = <String, dynamic>{};
|
||||
if (name != null) params['name'] = name;
|
||||
if (rssiRef != null) params['rssi_ref'] = rssiRef;
|
||||
return Sensor.fromJson(await client.updateSensor(id, params));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ abstract class SensorRepository {
|
||||
Future<List<Sensor>> getSensors();
|
||||
Future<List<Sensor>> getUnplacedSensors();
|
||||
Future<Sensor> getSensor(int id);
|
||||
Future<Sensor> updateSensor(int id, {String? name, double? rssiRef});
|
||||
Future<Sensor> updateSensor(int id, {String? name});
|
||||
Future<void> deleteSensor(int id);
|
||||
Future<Sensor> placeSensor(int id,
|
||||
{required int roomId, required double x, required double y});
|
||||
|
||||
@@ -6,16 +6,14 @@ class Sensor {
|
||||
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;
|
||||
final double? x; // room relative
|
||||
final double? y; // room relative
|
||||
|
||||
bool get isPlaced => roomId != null;
|
||||
String get displayName => name ?? sensorId;
|
||||
@@ -25,9 +23,8 @@ class Sensor {
|
||||
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(),
|
||||
x: (json['x'] as num?)?.toDouble(),
|
||||
y: (json['y'] as num?)?.toDouble(),
|
||||
);
|
||||
|
||||
Sensor copyWith({
|
||||
@@ -44,6 +41,5 @@ class Sensor {
|
||||
roomId: roomId ?? this.roomId,
|
||||
x: x ?? this.x,
|
||||
y: y ?? this.y,
|
||||
rssiRef: rssiRef ?? this.rssiRef,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -49,11 +49,6 @@ class _Body extends ConsumerWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_InfoRow(label: 'Device ID', value: sensor.sensorId),
|
||||
if (sensor.rssiRef != null)
|
||||
_InfoRow(
|
||||
label: 'RSSI reference',
|
||||
value: '${sensor.rssiRef!.toStringAsFixed(1)} dBm',
|
||||
),
|
||||
_InfoRow(
|
||||
label: 'Floor position',
|
||||
value: sensor.isPlaced
|
||||
|
||||
Reference in New Issue
Block a user