Harden geofence automation and home editing

This commit is contained in:
Artem Kokos
2026-05-15 11:26:23 +07:00
parent 50748c6945
commit 8ffaa14b60
21 changed files with 718 additions and 160 deletions

View File

@@ -0,0 +1,52 @@
import 'package:geolocator/geolocator.dart';
import '../../homes/services/location_platform_service.dart';
import '../models/geofence_system_state.dart';
abstract class GeofenceSystemStatusService {
Future<GeofenceSystemState> inspect({
required bool hasActiveHome,
required bool hasCoordinates,
});
}
class DeviceGeofenceSystemStatusService implements GeofenceSystemStatusService {
final LocationPlatformService locationPlatformService;
DeviceGeofenceSystemStatusService({required this.locationPlatformService});
@override
Future<GeofenceSystemState> inspect({
required bool hasActiveHome,
required bool hasCoordinates,
}) async {
if (!hasActiveHome) {
return const GeofenceSystemState(GeofenceSystemIssue.noActiveHome);
}
if (!hasCoordinates) {
return const GeofenceSystemState(GeofenceSystemIssue.missingCoordinates);
}
if (!await locationPlatformService.isLocationServiceEnabled()) {
return const GeofenceSystemState(
GeofenceSystemIssue.locationServicesDisabled,
);
}
final permission = await locationPlatformService.checkPermission();
return switch (permission) {
LocationPermission.denied => const GeofenceSystemState(
GeofenceSystemIssue.permissionDenied,
),
LocationPermission.deniedForever => const GeofenceSystemState(
GeofenceSystemIssue.permissionDeniedForever,
),
LocationPermission.whileInUse => const GeofenceSystemState(
GeofenceSystemIssue.backgroundPermissionRequired,
),
LocationPermission.always => const GeofenceSystemState(
GeofenceSystemIssue.ready,
),
_ => const GeofenceSystemState(GeofenceSystemIssue.permissionDenied),
};
}
}