fix: report group control failures
This commit is contained in:
@@ -278,7 +278,7 @@ class GroupsLoadStateNotifier extends Notifier<GroupsLoadState> {
|
||||
}
|
||||
|
||||
void setError(Object error) =>
|
||||
state = GroupsLoadState.error(error.toString());
|
||||
state = GroupsLoadState.error(describeLoadError(error));
|
||||
}
|
||||
|
||||
class GroupsNotifier extends Notifier<List<dynamic>> {
|
||||
@@ -432,7 +432,6 @@ class GroupsNotifier extends Notifier<List<dynamic>> {
|
||||
state = updatedList;
|
||||
ref.read(groupsLoadStateProvider.notifier).setData(updatedList);
|
||||
} catch (e) {
|
||||
debugPrint("Ошибка глобального опроса: $e");
|
||||
if (_isActiveGeneration(generation)) {
|
||||
ref.read(groupsLoadStateProvider.notifier).setError(e);
|
||||
}
|
||||
@@ -474,6 +473,7 @@ class GroupsNotifier extends Notifier<List<dynamic>> {
|
||||
void _debouncedControl(
|
||||
String id,
|
||||
String key,
|
||||
String action,
|
||||
Map<String, dynamic> localPatch,
|
||||
Map<String, dynamic> apiParams,
|
||||
) {
|
||||
@@ -489,7 +489,8 @@ class GroupsNotifier extends Notifier<List<dynamic>> {
|
||||
await _api.controlGroup(id, apiParams);
|
||||
} catch (e) {
|
||||
_lockUntil.remove(id);
|
||||
refresh();
|
||||
await refresh();
|
||||
ref.read(groupControlErrorProvider.notifier).report(id, action, e);
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -513,6 +514,7 @@ class GroupsNotifier extends Notifier<List<dynamic>> {
|
||||
_debouncedControl(
|
||||
id,
|
||||
'brightness',
|
||||
'яркость',
|
||||
{'brightness': value},
|
||||
{'brightness': value},
|
||||
);
|
||||
@@ -520,7 +522,13 @@ class GroupsNotifier extends Notifier<List<dynamic>> {
|
||||
|
||||
/// Установить цветовую температуру (2700-6500K) -- с debounce
|
||||
void setTemperature(String id, int value) {
|
||||
_debouncedControl(id, 'temp', {'temp': value}, {'temp': value});
|
||||
_debouncedControl(
|
||||
id,
|
||||
'temp',
|
||||
'температуру',
|
||||
{'temp': value},
|
||||
{'temp': value},
|
||||
);
|
||||
}
|
||||
|
||||
/// Установить RGB-цвет -- с debounce
|
||||
@@ -528,6 +536,7 @@ class GroupsNotifier extends Notifier<List<dynamic>> {
|
||||
_debouncedControl(
|
||||
id,
|
||||
'color',
|
||||
'цвет',
|
||||
{'r': r, 'g': g, 'b': b},
|
||||
{'r': r, 'g': g, 'b': b},
|
||||
);
|
||||
@@ -558,6 +567,41 @@ class GroupsNotifier extends Notifier<List<dynamic>> {
|
||||
}
|
||||
}
|
||||
|
||||
class GroupControlError {
|
||||
final String groupId;
|
||||
final String action;
|
||||
final String message;
|
||||
final int sequence;
|
||||
|
||||
const GroupControlError({
|
||||
required this.groupId,
|
||||
required this.action,
|
||||
required this.message,
|
||||
required this.sequence,
|
||||
});
|
||||
}
|
||||
|
||||
final groupControlErrorProvider =
|
||||
NotifierProvider<GroupControlErrorNotifier, GroupControlError?>(
|
||||
() => GroupControlErrorNotifier(),
|
||||
);
|
||||
|
||||
class GroupControlErrorNotifier extends Notifier<GroupControlError?> {
|
||||
int _sequence = 0;
|
||||
|
||||
@override
|
||||
GroupControlError? build() => null;
|
||||
|
||||
void report(String groupId, String action, Object error) {
|
||||
state = GroupControlError(
|
||||
groupId: groupId,
|
||||
action: action,
|
||||
message: describeLoadError(error),
|
||||
sequence: ++_sequence,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Устройства (для создания групп) ─────────────────────────
|
||||
|
||||
final devicesProvider =
|
||||
|
||||
Reference in New Issue
Block a user