Files
ignis_app/lib/features/homes/services/geofence_automation_service.dart
2026-05-15 10:18:46 +07:00

42 lines
1.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/services.dart';
import '../../../models/home_config.dart';
import '../../../services/settings_service.dart';
class GeofenceAutomationService {
GeofenceAutomationService({SettingsService? settingsService})
: _settingsService = settingsService ?? SettingsService();
static const _channel = MethodChannel('ignis/geofence_automation');
final SettingsService _settingsService;
Future<void> syncActiveHome(HomeConfig? home) async {
if (home == null || !home.geofenceReady) {
await _invoke('disarmGeofence');
return;
}
final apiKey = await _settingsService.requireHomeApiKey(home.id);
await _invoke('armGeofence', {
'homeId': home.id,
'homeName': home.name,
'baseUrl': home.url,
'apiKey': apiKey,
'latitude': home.latitude,
'longitude': home.longitude,
'radiusMeters': home.geofenceRadiusMeters,
});
}
Future<void> _invoke(String method, [Map<String, Object?>? arguments]) async {
try {
await _channel.invokeMethod<void>(method, arguments);
} on MissingPluginException {
// В тестах и на не-Android средах platform channel может отсутствовать.
} on PlatformException {
rethrow;
}
}
}