diff --git a/README.md b/README.md index afcdc12..3174912 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`를 호출합니다. 집 안이거나 `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`를 호출합니다. 집 안이거나 충전 중도 아니고 `Niro`도 연결되어 있지 않으면 자동 명령은 `force_off`로 고정밀 위치 갱신을 끕니다. 집 판정 중심은 `/custom/common/config.php`의 `findmydevice_home` 설정을 사용합니다. 현재 서울 집 좌표는 `37.558924572072, 127.20413804054`, 반경은 `150m`입니다. 목포 집은 Home Assistant `zone.home` 기준인 `34.80634217996409, 126.38442277908327`, 반경 `150m`를 고정밀 위치 갱신 제외 구역으로 사용합니다. API 응답의 `home` 값을 브라우저가 사용하므로 설정 변경 시 집 원, 체류/외출 판정, GPS 튐 흡수 기준이 같은 좌표로 적용됩니다. diff --git a/php/api.php b/php/api.php index 5741997..7a6a75a 100644 --- a/php/api.php +++ b/php/api.php @@ -218,16 +218,30 @@ function findmydevice_required_bluetooth_connected(): bool return false; } +function findmydevice_is_charging(): bool +{ + $config = custom_config(); + $entity = (string)($config['entities']['is_charging'] ?? ''); + if ($entity === '') { + return false; + } + + $state = findmydevice_latest_state($entity); + return strtolower((string)($state['state'] ?? '')) === 'on'; +} + function findmydevice_auto_tracking_policy(): array { $position = findmydevice_current_position(); $zone = findmydevice_quiet_zone($position); $bluetooth = findmydevice_required_bluetooth_connected(); + $charging = findmydevice_is_charging(); return [ - 'allowed' => !$zone && $bluetooth, + 'allowed' => !$zone && ($charging || $bluetooth), 'position' => $position, 'quiet_zone' => $zone, + 'charging' => $charging, 'required_bluetooth_connected' => $bluetooth, ]; } @@ -254,6 +268,7 @@ function findmydevice_location_refresh(string $name): array if (!$policy['allowed']) { $results['policy'] = 'blocked'; $results['quietZone'] = $policy['quiet_zone']; + $results['charging'] = $policy['charging']; $results['requiredBluetoothConnected'] = $policy['required_bluetooth_connected']; $results['allowWebhook'] = false; $results['high_accuracy_off'] = findmydevice_mobile_command('command_high_accuracy_mode', [ @@ -264,7 +279,8 @@ function findmydevice_location_refresh(string $name): array $results['policy'] = 'allowed'; $results['quietZone'] = null; - $results['requiredBluetoothConnected'] = true; + $results['charging'] = $policy['charging']; + $results['requiredBluetoothConnected'] = $policy['required_bluetooth_connected']; $results['high_accuracy_interval'] = findmydevice_mobile_command('command_high_accuracy_mode', [ 'command' => 'high_accuracy_set_update_interval', 'high_accuracy_update_interval' => $interval, @@ -279,6 +295,7 @@ function findmydevice_location_refresh(string $name): array if (!$policy['allowed']) { $results['policy'] = 'blocked'; $results['quietZone'] = $policy['quiet_zone']; + $results['charging'] = $policy['charging']; $results['requiredBluetoothConnected'] = $policy['required_bluetooth_connected']; $results['allowWebhook'] = false; $results['high_accuracy_off'] = findmydevice_mobile_command('command_high_accuracy_mode', [ @@ -289,7 +306,8 @@ function findmydevice_location_refresh(string $name): array $results['policy'] = 'allowed'; $results['quietZone'] = null; - $results['requiredBluetoothConnected'] = true; + $results['charging'] = $policy['charging']; + $results['requiredBluetoothConnected'] = $policy['required_bluetooth_connected']; $results['request_location'] = findmydevice_mobile_command('request_location_update'); $results['update_sensors'] = findmydevice_mobile_command('command_update_sensors'); } elseif ($name === 'force_update') {