Support Galaxy sensor fields and remove debug file

This commit is contained in:
seo
2026-06-12 15:18:13 +09:00
parent 72aedf47e5
commit 4559301fa6
4 changed files with 294 additions and 233 deletions
+105 -10
View File
@@ -42,8 +42,6 @@ $deviceUrl = $entities['device'];
$geoUrl = $entities['geo'];
$batteryStateUrl = $entities['battery_state'];
$batteryLevelUrl = $entities['battery_level'];
$watchBatteryStateUrl = $entities['watch_battery_state'];
$watchBatteryLevelUrl = $entities['watch_battery_level'];
$activityUrl = $entities['activity'];
$connectionUrl = $entities['connection'];
$fascendedUrl = $entities['daily_floors'];
@@ -77,13 +75,39 @@ function getData($entityId) {
return custom_ha_state('seoul', $entityId) ?? [];
}
function getEntityData($entities, $key) {
if (empty($entities[$key])) {
return [];
}
return getData($entities[$key]);
}
function stateValue($data) {
$state = $data['state'] ?? null;
if ($state === null || $state === 'unknown' || $state === 'unavailable' || $state === '<not connected>' || $state === '<not available>') {
return null;
}
return $state;
}
function boolText($state, $lang) {
if ($state === null) return null;
if ($lang === 'ko') {
return $state === 'on' ? '켜짐' : ($state === 'off' ? '꺼짐' : $state);
}
return $state === 'on' ? 'On' : ($state === 'off' ? 'Off' : $state);
}
function mappedText($state, $lang, $map) {
if ($state === null) return null;
return $map[$lang][$state] ?? $map[$lang][strtolower((string)$state)] ?? $state;
}
// 데이터 불러오기
$deviceData = getData($deviceUrl);
$geoData = getData($geoUrl);
$batteryStateData = getData($batteryStateUrl);
$batteryLevelData = getData($batteryLevelUrl);
$watchBatteryStateData = getData($watchBatteryStateUrl);
$watchBatteryLevelData = getData($watchBatteryLevelUrl);
$activityData = getData($activityUrl);
$connectionData = getData($connectionUrl);
$ascendedData = getData($fascendedUrl);
@@ -92,6 +116,27 @@ $stepsData = getData($stepsUrl);
$distanceData = getData($distanceUrl);
$historyData = custom_ha_request('seoul', 'GET', $historyEndpoint) ?? [];
$triggerData = getData($triggerUrl);
$galaxyData = [
'isCharging' => getEntityData($entities, 'is_charging'),
'chargerType' => getEntityData($entities, 'charger_type'),
'batteryHealth' => getEntityData($entities, 'battery_health'),
'batteryTemperature' => getEntityData($entities, 'battery_temperature'),
'batteryPower' => getEntityData($entities, 'battery_power'),
'remainingChargeTime' => getEntityData($entities, 'remaining_charge_time'),
'batteryCycleCount' => getEntityData($entities, 'battery_cycle_count'),
'wifiConnection' => getEntityData($entities, 'wifi_connection'),
'wifiBssid' => getEntityData($entities, 'wifi_bssid'),
'wifiIp' => getEntityData($entities, 'wifi_ip'),
'wifiLinkSpeed' => getEntityData($entities, 'wifi_link_speed'),
'wifiFrequency' => getEntityData($entities, 'wifi_frequency'),
'wifiSignalStrength' => getEntityData($entities, 'wifi_signal_strength'),
'mobileData' => getEntityData($entities, 'mobile_data'),
'phoneState' => getEntityData($entities, 'phone_state'),
'interactive' => getEntityData($entities, 'interactive'),
'dozeMode' => getEntityData($entities, 'doze_mode'),
'powerSave' => getEntityData($entities, 'power_save'),
'deviceLocked' => getEntityData($entities, 'device_locked'),
];
// 경로 기록
$path = [];
@@ -160,18 +205,43 @@ $connectionMap = [
$batteryStateMap = [
'ko' => [
'Charging' => '충전 중',
'Discharging' => '방전 중',
'Not Charging' => '충전중이 아님',
'Full' => '가득참',
'charging' => '충전 중',
'discharging' => '방전 중',
'not_charging' => '충전중이 아님',
'full' => '가득참',
'Unknown' => '-',
],
'en' => [
'Charging' => 'Charging',
'Discharging' => 'Discharging',
'Not Charging' => 'Not Charging',
'Full' => 'Full',
'charging' => 'Charging',
'discharging' => 'Discharging',
'not_charging' => 'Not Charging',
'full' => 'Full',
'Unknown' => '-',
]
];
$androidValueMap = [
'chargerType' => [
'ko' => ['none' => '없음', 'wireless' => '무선', 'ac' => '유선', 'usb' => 'USB'],
'en' => ['none' => 'None', 'wireless' => 'Wireless', 'ac' => 'AC', 'usb' => 'USB'],
],
'batteryHealth' => [
'ko' => ['good' => '양호', 'overheat' => '과열', 'dead' => '불량', 'over_voltage' => '과전압', 'cold' => '저온'],
'en' => ['good' => 'Good', 'overheat' => 'Overheat', 'dead' => 'Dead', 'over_voltage' => 'Over voltage', 'cold' => 'Cold'],
],
'phoneState' => [
'ko' => ['idle' => '대기', 'ringing' => '수신 중', 'offhook' => '통화 중'],
'en' => ['idle' => 'Idle', 'ringing' => 'Ringing', 'offhook' => 'Off hook'],
],
];
$triggerMap = [
'ko' => [
"Launch" => "앱 실행",
@@ -202,10 +272,9 @@ $triggerMap = [
];
$activityState = $activityData['state'] ?? null;
$aaccuracyState = $activityData['attributes']['Confidence'] ?? null;
$aaccuracyState = $activityData['attributes']['Confidence'] ?? $activityData['attributes']['confidence'] ?? null;
$connectionState = $connectionData['state'] ?? null;
$batteryState = $batteryStateData['state'] ?? null;
$watchBatteryState = $watchBatteryStateData['state'] ?? null;
$address = null;
@@ -224,6 +293,34 @@ if (($deviceData['state'] ?? null) !== 'not_home') {
$address = trim($locality . ' ' . ($geoData['attributes']['Name'] ?? ''));
}
$galaxy = [
'isCharging' => boolText(stateValue($galaxyData['isCharging']), $lang),
'chargerType' => mappedText(stateValue($galaxyData['chargerType']), $lang, $androidValueMap['chargerType']),
'batteryHealth' => mappedText(stateValue($galaxyData['batteryHealth']), $lang, $androidValueMap['batteryHealth']),
'batteryTemperature' => stateValue($galaxyData['batteryTemperature']),
'batteryPower' => stateValue($galaxyData['batteryPower']),
'remainingChargeTime' => stateValue($galaxyData['remainingChargeTime']),
'batteryCycleCount' => stateValue($galaxyData['batteryCycleCount']),
'wifiConnection' => stateValue($galaxyData['wifiConnection']),
'wifiBssid' => stateValue($galaxyData['wifiBssid']),
'wifiIp' => stateValue($galaxyData['wifiIp']),
'wifiLinkSpeed' => stateValue($galaxyData['wifiLinkSpeed']),
'wifiFrequency' => stateValue($galaxyData['wifiFrequency']),
'wifiSignalStrength' => stateValue($galaxyData['wifiSignalStrength']),
'mobileData' => boolText(stateValue($galaxyData['mobileData']), $lang),
'phoneState' => mappedText(stateValue($galaxyData['phoneState']), $lang, $androidValueMap['phoneState']),
'interactive' => boolText(stateValue($galaxyData['interactive']), $lang),
'dozeMode' => boolText(stateValue($galaxyData['dozeMode']), $lang),
'powerSave' => boolText(stateValue($galaxyData['powerSave']), $lang),
'deviceLocked' => boolText(stateValue($galaxyData['deviceLocked']), $lang),
];
if (!$galaxy['wifiConnection']) {
foreach (['wifiBssid', 'wifiIp', 'wifiLinkSpeed', 'wifiFrequency', 'wifiSignalStrength'] as $wifiKey) {
$galaxy[$wifiKey] = null;
}
}
// 해시 요청만 들어온 경우
if (isset($_GET['hashonly']) && $_GET['hashonly'] == '1') {
$raw = json_encode([
@@ -235,8 +332,6 @@ if (isset($_GET['hashonly']) && $_GET['hashonly'] == '1') {
'address' => $address,
'state' => $batteryStateMap[$lang][$batteryState] ?? $batteryState ?? null,
'level' => $batteryLevelData['state'] ?? null,
'wstate' => $batteryStateMap[$lang][$watchBatteryState] ?? $watchBatteryState ?? null,
'wlevel' => $watchBatteryLevelData['state'] ?? null,
'ascended' => $ascendedData['state'] ?? null,
'descended' => $descendedData['state'] ?? null,
'steps' => $stepsData['state'] ?? null,
@@ -244,6 +339,7 @@ if (isset($_GET['hashonly']) && $_GET['hashonly'] == '1') {
'activity' => $activityMap[$lang][$activityState] ?? $activityState ?? null,
'aaccuracy' => $aaccuracyMap[$lang][$aaccuracyState] ?? $aaccuracyState ?? null,
'connection' => $connectionMap[$lang][$connectionState] ?? $connectionState ?? null,
'galaxy' => $galaxy,
]);
echo json_encode(['hash' => hash('sha256', $raw)]);
@@ -259,8 +355,6 @@ echo json_encode([
'address' => $address,
'state' => $batteryStateMap[$lang][$batteryState] ?? $batteryState ?? null,
'level' => $batteryLevelData['state'] ?? null,
'wstate' => $batteryStateMap[$lang][$watchBatteryState] ?? $watchBatteryState ?? null,
'wlevel' => $watchBatteryLevelData['state'] ?? null,
'ascended' => $ascendedData['state'] ?? null,
'descended' => $descendedData['state'] ?? null,
'steps' => $stepsData['state'] ?? null,
@@ -268,6 +362,7 @@ echo json_encode([
'activity' => $activityMap[$lang][$activityState] ?? $activityState ?? null,
'aaccuracy' => $aaccuracyMap[$lang][$aaccuracyState] ?? $aaccuracyState ?? null,
'connection' => $connectionMap[$lang][$connectionState] ?? $connectionState ?? null,
'galaxy' => $galaxy,
'history' => $path ?? null,
], JSON_UNESCAPED_UNICODE);
?>