Request frequent mobile location updates

This commit is contained in:
seo
2026-06-17 20:01:20 +09:00
parent 938868ea64
commit d9c8aef1dd
2 changed files with 68 additions and 4 deletions
+6 -2
View File
@@ -20,8 +20,8 @@ Home Assistant에 기록된 Galaxy Z Fold7의 위치, 배터리, 활동 상태,
- 집 체류 합산, 외출/복귀 세션, 마지막 복귀 시각과 현재 상태 표시 - 집 체류 합산, 외출/복귀 세션, 마지막 복귀 시각과 현재 상태 표시
- 배터리, 충전 상태, 배터리 건강, 온도, 전력, 활동 상태, 걸음 수, 이동 거리 표시 - 배터리, 충전 상태, 배터리 건강, 온도, 전력, 활동 상태, 걸음 수, 이동 거리 표시
- 네트워크, 기기, 화면/오디오, 건강/활동, 저장공간/데이터, 알림/통화, 센서 정보를 섹션별로 표시 - 네트워크, 기기, 화면/오디오, 건강/활동, 저장공간/데이터, 알림/통화, 센서 정보를 섹션별로 표시
- 자동 위치 갱신 웹훅 제어 - 자동 위치 갱신 웹훅 제어와 Companion App 위치 갱신 명령 전송
- 강제 업데이트 요청 - 강제 위치/센서 업데이트 요청
- 한국어/영어 전환 - 한국어/영어 전환
- Wake Lock 지원 - Wake Lock 지원
@@ -40,6 +40,8 @@ Home Assistant에 기록된 Galaxy Z Fold7의 위치, 배터리, 활동 상태,
표시할 모바일 앱 센서 목록은 `/custom/common/config.php``findmydevice_sensor_sections`에서 섹션 단위로 관리합니다. 화면 CSS 원본은 `/custom/common/css/findmydevice.css`를 사용합니다. 기존 운영 HTML이 `/custom/findmydevice/css/style.css`를 참조해도 호환 파일이 공용 CSS를 import합니다. 표시할 모바일 앱 센서 목록은 `/custom/common/config.php``findmydevice_sensor_sections`에서 섹션 단위로 관리합니다. 화면 CSS 원본은 `/custom/common/css/findmydevice.css`를 사용합니다. 기존 운영 HTML이 `/custom/findmydevice/css/style.css`를 참조해도 호환 파일이 공용 CSS를 import합니다.
위치 갱신 명령은 `/custom/common/config.php``findmydevice_location_refresh` 설정을 사용합니다. 현재 위치 엔티티를 읽는 Home Assistant 인스턴스와 같은 `seoul` 프로필의 `notify.mobile_app_seocaegeonyi_z_fold7` 서비스로 Companion App notification command를 보냅니다. 자동 업데이트가 켜지면 Android high accuracy mode를 5초 간격으로 설정하고 `force_on`을 보낸 뒤 `request_location_update``command_update_sensors`를 함께 호출합니다. 자동 업데이트 중에는 10초마다 위치 요청과 센서 업데이트 요청을 반복하고, 자동 업데이트를 끄거나 페이지를 벗어나면 `force_off`를 보냅니다.
## 히스토리와 지도 ## 히스토리와 지도
실시간 화면은 현재 위치와 상태를 조회하고, 기본 기간 입력값에 해당하는 최근 하루 이동 기록도 지도에 함께 표시합니다. 기간 입력을 변경하면 해당 범위의 이동 기록을 `history=1` 옵션으로 다시 요청합니다. 서버는 기간이 길어도 Home Assistant 히스토리 API를 실행한 뒤, 브라우저 렌더링용으로 경로를 부드럽게 단순화해 응답합니다. 실시간 화면은 현재 위치와 상태를 조회하고, 기본 기간 입력값에 해당하는 최근 하루 이동 기록도 지도에 함께 표시합니다. 기간 입력을 변경하면 해당 범위의 이동 기록을 `history=1` 옵션으로 다시 요청합니다. 서버는 기간이 길어도 Home Assistant 히스토리 API를 실행한 뒤, 브라우저 렌더링용으로 경로를 부드럽게 단순화해 응답합니다.
@@ -70,4 +72,6 @@ Android Companion App의 실제 상태값은 API에서 한국어/영어 표시
긴 기간 히스토리 조회는 Home Assistant recorder 데이터량과 웹서버/프록시 timeout 영향을 받을 수 있습니다. findmydevice API는 Home Assistant 쿼리를 실행한 뒤 원본 지점 수와 렌더링 지점 수를 함께 내려주며, 브라우저에는 부드러운 지도 표시용 경로를 출력합니다. 긴 기간 히스토리 조회는 Home Assistant recorder 데이터량과 웹서버/프록시 timeout 영향을 받을 수 있습니다. findmydevice API는 Home Assistant 쿼리를 실행한 뒤 원본 지점 수와 렌더링 지점 수를 함께 내려주며, 브라우저에는 부드러운 지도 표시용 경로를 출력합니다.
Companion App의 `request_location_update`는 앱이 실행 중이거나 백그라운드에 있을 때 위치 보고를 시도합니다. Android에서는 위치 권한, 백그라운드 실행 허용, Location Sensors의 Background Location, Single Accurate Location, High Accuracy Mode 설정이 실제 갱신 빈도에 영향을 줍니다.
이 프로젝트는 위치, 주소, 배터리, 활동 기록을 포함하므로 private 저장소와 개인 접근 환경에서만 운영합니다. 이 프로젝트는 위치, 주소, 배터리, 활동 기록을 포함하므로 private 저장소와 개인 접근 환경에서만 운영합니다.
+62 -2
View File
@@ -21,6 +21,58 @@ if (function_exists('set_time_limit')) {
custom_require_auth(); custom_require_auth();
$requestData = custom_read_request_data(); $requestData = custom_read_request_data();
function findmydevice_mobile_command(string $message, array $data = []): bool
{
$config = custom_config();
$refresh = $config['findmydevice_location_refresh'] ?? [];
$profile = (string)($refresh['profile'] ?? 'seoul');
$service = (string)($refresh['notify_service'] ?? '');
if ($service === '') {
return false;
}
$payload = ['message' => $message];
if ($data) {
$payload['data'] = $data;
}
return custom_ha_service($profile, 'notify', $service, $payload, 5);
}
function findmydevice_location_refresh(string $name): array
{
$config = custom_config();
$refresh = $config['findmydevice_location_refresh'] ?? [];
$interval = max(5, (int)($refresh['high_accuracy_interval'] ?? 5));
$results = [];
if ($name === 'auto_on') {
$results['high_accuracy_interval'] = findmydevice_mobile_command('command_high_accuracy_mode', [
'command' => 'high_accuracy_set_update_interval',
'high_accuracy_update_interval' => $interval,
]);
$results['high_accuracy_on'] = findmydevice_mobile_command('command_high_accuracy_mode', [
'command' => 'force_on',
]);
$results['request_location'] = findmydevice_mobile_command('request_location_update');
$results['update_sensors'] = findmydevice_mobile_command('command_update_sensors');
} elseif ($name === 'auto_tick') {
$results['request_location'] = findmydevice_mobile_command('request_location_update');
$results['update_sensors'] = findmydevice_mobile_command('command_update_sensors');
} elseif ($name === 'force_update') {
$results['request_location'] = findmydevice_mobile_command('request_location_update');
$results['update_sensors'] = findmydevice_mobile_command('command_update_sensors');
} elseif ($name === 'auto_off') {
$results['high_accuracy_off'] = findmydevice_mobile_command('command_high_accuracy_mode', [
'command' => 'force_off',
]);
}
return $results;
}
if (isset($_GET['action']) && $_GET['action'] === 'webhook') { if (isset($_GET['action']) && $_GET['action'] === 'webhook') {
$name = (string)($requestData['name'] ?? ''); $name = (string)($requestData['name'] ?? '');
$allowed = [ $allowed = [
@@ -34,8 +86,16 @@ if (isset($_GET['action']) && $_GET['action'] === 'webhook') {
custom_json(['result' => 'invalid_webhook'], 400); custom_json(['result' => 'invalid_webhook'], 400);
} }
$ok = custom_ha_webhook($allowed[$name]); $mobileResults = findmydevice_location_refresh($name);
custom_json(['result' => $ok ? 'ok' : 'fail'], $ok ? 200 : 502); $webhookOk = custom_ha_webhook($allowed[$name]);
$mobileOk = !$mobileResults || in_array(true, $mobileResults, true);
$ok = $webhookOk || $mobileOk;
custom_json([
'result' => $ok ? 'ok' : 'fail',
'webhook' => $webhookOk ? 'ok' : 'fail',
'mobileCommands' => $mobileResults,
], $ok ? 200 : 502);
} }
$config = custom_config(); $config = custom_config();