From bb070e82c2fcf0feefa3fb09a5f1e036a54132b1 Mon Sep 17 00:00:00 2001 From: seo Date: Mon, 13 Jul 2026 22:15:18 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=90=EB=8F=99=20=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EA=B0=B1=EC=8B=A0=205=EC=B4=88=20=EB=AA=85=EB=A0=B9=20?= =?UTF-8?q?=EB=B3=B5=EC=9B=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- js/main.js | 2 +- php/api.php | 68 ++++------------------------------------------------- 3 files changed, 7 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index d13b94f..4384fec 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ PWA standalone으로 진입한 경우에는 설치형 앱 사용성을 우선해 페이지 본문에는 `
`만 두면 됩니다. `main.js`는 이 컨테이너 안에 지도, 헤더, 설정/기록/위치/업데이트/배터리/활동 섹션과 iOS PWA 안내 영역을 항상 자동 생성합니다. 상단 복귀 링크는 `chaegeon.com`이면 채건닷컴, `/blog`이면 블로그처럼 알려진 경로명을 우선 표시하고, 같은 출처의 다른 이전 페이지는 문서 제목을 읽어 표시합니다. 같은 경로에서 쿼리만 바뀐 화면은 같은 페이지로 보고 세션 방문 기록에서 다른 이전 페이지를 찾습니다. 직접 접속처럼 이전 페이지 확인이 어려우면 채건닷컴으로 표시하고 `https://chaegeon.com/`로 이동합니다. -위치 갱신 명령은 `/custom/common/config.php`의 `findmydevice_location_refresh` 설정을 사용합니다. `seoul`, `main` Home Assistant 프로필의 `notify.mobile_app_seocaegeonyi_z_fold7` 서비스로 Companion App notification command를 보냅니다. 자동 업데이트는 서울 집과 목포 집 150m 반경 밖이고 충전 중이거나 `Niro` 블루투스가 연결되어 있을 때만 Android high accuracy mode를 5초 간격으로 설정하고 `force_on`, `request_location_update`, `command_update_sensors`를 호출합니다. 화면 자동 갱신 tick은 5초마다 돌지만, 휴대폰 위치/센서 명령은 서버에서 30초 이상 간격으로 제한합니다. 고정밀 모드가 이미 켜져 스위치가 잠긴 상태에서는 웹 화면이 추가 자동 명령을 보내지 않고 상태 표시만 유지합니다. HA 자동화도 30초마다 같은 조건을 확인합니다. 집 안이거나 충전 중도 아니고 `Niro`도 연결되어 있지 않으면 자동 명령은 `force_off`로 고정밀 위치 갱신을 끕니다. +위치 갱신 명령은 `/custom/common/config.php`의 `findmydevice_location_refresh` 설정을 사용합니다. `seoul`, `main` Home Assistant 프로필의 `notify.mobile_app_seocaegeonyi_z_fold7` 서비스로 Companion App notification command를 보냅니다. 자동 업데이트는 서울 집과 목포 집 150m 반경 밖이고 충전 중이거나 `Niro` 블루투스가 연결되어 있을 때만 Android high accuracy mode를 5초 간격으로 설정하고 `force_on`, `request_location_update`, `command_update_sensors`를 호출합니다. 화면이 열려 있고 자동 업데이트가 켜져 있거나 폰의 고정밀 모드가 이미 켜져 있으면 5초마다 위치/센서 갱신 명령을 보냅니다. 웹 화면에서 보이는 일반 알림 자동화가 중복 실행되지 않도록 findmydevice 서버는 위치 갱신용 HA 웹훅을 추가 호출하지 않고 Companion App command만 직접 보냅니다. HA 자동화도 30초마다 같은 조건을 확인합니다. 집 안이거나 충전 중도 아니고 `Niro`도 연결되어 있지 않으면 자동 명령은 `force_off`로 고정밀 위치 갱신을 끕니다. 집 판정 중심은 `/custom/common/config.php`의 `findmydevice_quiet_zones` 설정을 사용합니다. 현재 서울 집 좌표는 `37.558924572072, 127.20413804054`, 목포 집 좌표는 `34.80634217996409, 126.38442277908327`이며 둘 다 반경은 `150m`입니다. API 응답의 `homes` 값을 브라우저가 사용하므로 서울 집과 목포 집 모두 집 원, 체류/외출 판정, GPS 튐 흡수 기준에 포함됩니다. diff --git a/js/main.js b/js/main.js index c7354e4..9e10822 100644 --- a/js/main.js +++ b/js/main.js @@ -1102,7 +1102,7 @@ document.getElementById('autoUpdateSwitch').addEventListener('change', () => { setInterval(() => { if (!findmydeviceAuthenticated) return; const switchEl = document.getElementById('autoUpdateSwitch'); - if (switchEl?.checked && !switchEl.disabled) { + if (switchEl?.checked || highAccuracyModeActive) { callDeviceWebhook('auto_tick'); } }, 5000); diff --git a/php/api.php b/php/api.php index 996bde5..8dcd022 100644 --- a/php/api.php +++ b/php/api.php @@ -87,60 +87,6 @@ function findmydevice_mobile_command(string $message, array $data = []): bool return $ok; } -function findmydevice_command_state_file(): string -{ - return rtrim(sys_get_temp_dir(), '/\\') . '/findmydevice_location_refresh_state.json'; -} - -function findmydevice_throttled_mobile_command(string $key, int $seconds, string $message, array $data = []): ?bool -{ - if ($seconds <= 0) { - return findmydevice_mobile_command($message, $data); - } - - $file = findmydevice_command_state_file(); - $now = time(); - $handle = fopen($file, 'c+'); - if (!$handle) { - return findmydevice_mobile_command($message, $data); - } - - try { - if (!flock($handle, LOCK_EX)) { - fclose($handle); - return findmydevice_mobile_command($message, $data); - } - - $raw = stream_get_contents($handle); - $state = json_decode($raw ?: '{}', true); - if (!is_array($state)) { - $state = []; - } - - $last = (int)($state[$key] ?? 0); - if ($last > 0 && ($now - $last) < $seconds) { - flock($handle, LOCK_UN); - fclose($handle); - return null; - } - - $state[$key] = $now; - ftruncate($handle, 0); - rewind($handle); - fwrite($handle, json_encode($state, JSON_UNESCAPED_UNICODE)); - fflush($handle); - flock($handle, LOCK_UN); - fclose($handle); - } catch (Throwable $e) { - if (is_resource($handle)) { - flock($handle, LOCK_UN); - fclose($handle); - } - } - - return findmydevice_mobile_command($message, $data); -} - function findmydevice_ha_profiles(): array { $config = custom_config(); @@ -306,9 +252,6 @@ function findmydevice_bool_result_exists(array $results): bool if ($value === true) { return true; } - if ($value === 'throttled') { - return true; - } } return false; } @@ -318,7 +261,6 @@ function findmydevice_location_refresh(string $name): array $config = custom_config(); $refresh = $config['findmydevice_location_refresh'] ?? []; $interval = max(1, (int)($refresh['high_accuracy_interval'] ?? 1)); - $autoTickInterval = max(5, (int)($refresh['auto_tick_command_interval'] ?? 30)); $results = []; if ($name === 'auto_on') { @@ -364,18 +306,18 @@ function findmydevice_location_refresh(string $name): array } $results['policy'] = 'allowed'; + $results['allowWebhook'] = false; $results['quietZone'] = null; $results['charging'] = $policy['charging']; $results['requiredBluetoothConnected'] = $policy['required_bluetooth_connected']; - $requestLocation = findmydevice_throttled_mobile_command('auto_tick_request_location', $autoTickInterval, 'request_location_update'); - $updateSensors = findmydevice_throttled_mobile_command('auto_tick_update_sensors', $autoTickInterval, 'command_update_sensors'); - $results['throttleSeconds'] = $autoTickInterval; - $results['request_location'] = $requestLocation ?? 'throttled'; - $results['update_sensors'] = $updateSensors ?? 'throttled'; + $results['request_location'] = findmydevice_mobile_command('request_location_update'); + $results['update_sensors'] = findmydevice_mobile_command('command_update_sensors'); } elseif ($name === 'force_update') { + $results['allowWebhook'] = false; $results['request_location'] = findmydevice_mobile_command('request_location_update'); $results['update_sensors'] = findmydevice_mobile_command('command_update_sensors'); } elseif ($name === 'auto_off') { + $results['allowWebhook'] = false; $results['high_accuracy_off'] = findmydevice_mobile_command('command_high_accuracy_mode', [ 'command' => 'force_off', ]);