Harden geofence automation and home editing
This commit is contained in:
@@ -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),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user