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