feat: Update assets and improve code comments across multiple components
- Updated favicon and various image assets. - Enhanced comments. - Adjusted styles and functionality in several components for improved user experience. - Updated package-lock.json to reflect dependency updates.
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
import axios, { AxiosError } from 'axios';
|
||||
import { HaArea, HaEntity } from '@/types/types';
|
||||
|
||||
// CONFIGURAZIONE
|
||||
// HOME ASSISTANT API CONFIGURATION
|
||||
const HA_API_URL = process.env.EXPO_PUBLIC_HA_API_URL;
|
||||
const HA_TOKEN = process.env.EXPO_PUBLIC_HA_TOKEN;
|
||||
|
||||
// Crea un'istanza di axios per Home Assistant
|
||||
// Create an axios instance for Home Assistant
|
||||
const haApi = axios.create({
|
||||
baseURL: HA_API_URL,
|
||||
headers: {
|
||||
'Authorization': `Bearer ${HA_TOKEN}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
timeout: 5000, // 5 secondi di timeout
|
||||
timeout: 5000, // 5 seconds timeout
|
||||
});
|
||||
|
||||
haApi.interceptors.request.use((config) => {
|
||||
@@ -24,7 +24,7 @@ haApi.interceptors.request.use((config) => {
|
||||
* Connection test
|
||||
*/
|
||||
export const testHaConnection = async (): Promise<{ success: boolean; message: string }> => {
|
||||
// Controlla se le variabili d'ambiente sono caricate
|
||||
// Check if environment variables are loaded
|
||||
if (!HA_API_URL || !HA_TOKEN) {
|
||||
console.error("Variabili d'ambiente per Home Assistant non trovate. Assicurati che EXPO_PUBLIC_HA_API_URL and EXPO_PUBLIC_HA_TOKEN siano definite nel file .env");
|
||||
return { success: false, message: "Configurazione API per Home Assistant mancante." };
|
||||
@@ -32,7 +32,7 @@ export const testHaConnection = async (): Promise<{ success: boolean; message: s
|
||||
|
||||
try {
|
||||
const response = await haApi.get('/');
|
||||
// Se la risposta è OK, HA restituisce un JSON con 'message'
|
||||
// If the response is OK, HA returns a JSON with 'message'
|
||||
if (response.status === 200 && response.data.message) {
|
||||
return { success: true, message: response.data.message };
|
||||
}
|
||||
@@ -46,7 +46,7 @@ export const testHaConnection = async (): Promise<{ success: boolean; message: s
|
||||
}
|
||||
|
||||
if (axiosError.response) {
|
||||
// Errori con una risposta dal server (es. 401, 404)
|
||||
// Errors with a server response (e.g., 401, 404)
|
||||
if (axiosError.response.status === 401) {
|
||||
return { success: false, message: "Errore 401: Token non autorizzato. Controlla il Long-Lived Token." };
|
||||
}
|
||||
@@ -55,10 +55,10 @@ export const testHaConnection = async (): Promise<{ success: boolean; message: s
|
||||
}
|
||||
return { success: false, message: `Errore server: Status ${axiosError.response.status}` };
|
||||
} else if (axiosError.request) {
|
||||
// Errori di rete (la richiesta è partita ma non ha ricevuto risposta)
|
||||
// Network errors (cannot receive a response)
|
||||
return { success: false, message: `Errore di rete: Impossibile raggiungere ${HA_API_URL}` };
|
||||
} else {
|
||||
// Errore generico
|
||||
// Generic errors
|
||||
return { success: false, message: `Errore sconosciuto: ${axiosError.message}` };
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ export const getHaAreas = async (): Promise<HaArea[]> => {
|
||||
|
||||
} catch (error) {
|
||||
console.error("Errore recupero aree:", error);
|
||||
return []; // Restituisce un array vuoto in caso di errore
|
||||
return []; // Return an empty array in case of error
|
||||
}
|
||||
};
|
||||
|
||||
@@ -120,7 +120,7 @@ export const getHaEntitiesByArea = async (areaId: string): Promise<HaEntity[]> =
|
||||
|
||||
} catch (error) {
|
||||
console.error(`Errore recupero entità per l'area ${areaId}:`, error);
|
||||
return []; // Restituisce un array vuoto in caso di errore
|
||||
return []; // Return an empty array in case of error
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user