in development funktionieren Steckdosen, Prod: baseURL fehler
This commit is contained in:
@@ -18,13 +18,13 @@ export class TasmotaControlComponent implements OnInit {
|
||||
}
|
||||
|
||||
updateSocketStatuses(): void {
|
||||
this.tasmotaService.getSocketStatus(this.tasmotaService.socket1IP)
|
||||
this.tasmotaService.getSocketStatus(this.tasmotaService.socket1Path)
|
||||
.subscribe({
|
||||
next: (status) => this.socket1Status = status,
|
||||
error: (error) => console.error('Fehler beim Abrufen des Status von Steckdose 1:', error)
|
||||
});
|
||||
|
||||
this.tasmotaService.getSocketStatus(this.tasmotaService.socket2IP)
|
||||
this.tasmotaService.getSocketStatus(this.tasmotaService.socket2Path)
|
||||
.subscribe({
|
||||
next: (status) => this.socket2Status = status,
|
||||
error: (error) => console.error('Fehler beim Abrufen des Status von Steckdose 2:', error)
|
||||
@@ -32,7 +32,7 @@ export class TasmotaControlComponent implements OnInit {
|
||||
}
|
||||
|
||||
toggleSocket1(): void {
|
||||
this.tasmotaService.toggleSocket(this.tasmotaService.socket1IP, this.socket1Status)
|
||||
this.tasmotaService.toggleSocket(this.tasmotaService.socket1Path, this.socket1Status)
|
||||
.subscribe({
|
||||
next: (status) => this.socket1Status = status,
|
||||
error: (error) => console.error('Fehler beim Schalten von Steckdose 1:', error)
|
||||
@@ -40,7 +40,7 @@ export class TasmotaControlComponent implements OnInit {
|
||||
}
|
||||
|
||||
toggleSocket2(): void {
|
||||
this.tasmotaService.toggleSocket(this.tasmotaService.socket2IP, this.socket2Status)
|
||||
this.tasmotaService.toggleSocket(this.tasmotaService.socket2Path, this.socket2Status)
|
||||
.subscribe({
|
||||
next: (status) => this.socket2Status = status,
|
||||
error: (error) => console.error('Fehler beim Schalten von Steckdose 2:', error)
|
||||
|
||||
+28
-17
@@ -1,39 +1,50 @@
|
||||
// tasmota.service.ts
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { environment } from '../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TasmotaService {
|
||||
private SOCKET1_IP = '10.0.0.31'; // Ändere zu deiner ersten Tasmota IP
|
||||
private SOCKET2_IP = '10.0.0.32'; // Ändere zu deiner zweiten Tasmota IP
|
||||
private baseUrl = environment.production
|
||||
? ''
|
||||
: '';
|
||||
|
||||
private SOCKET1_PATH = this.baseUrl + '/tasmota1';
|
||||
private SOCKET2_PATH = this.baseUrl + '/tasmota2';
|
||||
|
||||
private httpOptions = {
|
||||
headers: new HttpHeaders({
|
||||
'Content-Type': 'application/json',
|
||||
// Weitere Header falls nötig
|
||||
})
|
||||
};
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
toggleSocket(socketIP: string, currentStatus: boolean): Observable<boolean> {
|
||||
getSocketStatus(socketPath: string): Observable<boolean> {
|
||||
return this.http.get<any>(`${socketPath}/cm?cmnd=Power`, this.httpOptions)
|
||||
.pipe(
|
||||
map(response => response.POWER === 'ON')
|
||||
);
|
||||
}
|
||||
|
||||
toggleSocket(socketPath: string, currentStatus: boolean): Observable<boolean> {
|
||||
const command = currentStatus ? 'Power%20Off' : 'Power%20On';
|
||||
return this.http.get<any>(`http://${socketIP}/cm?cmnd=${command}`)
|
||||
return this.http.get<any>(`${socketPath}/cm?cmnd=${command}`, this.httpOptions)
|
||||
.pipe(
|
||||
map(response => response.POWER === 'ON')
|
||||
);
|
||||
}
|
||||
|
||||
getSocketStatus(socketIP: string): Observable<boolean> {
|
||||
return this.http.get<any>(`http://${socketIP}/cm?cmnd=Power`)
|
||||
.pipe(
|
||||
map(response => response.POWER === 'ON')
|
||||
);
|
||||
get socket1Path(): string {
|
||||
return this.SOCKET1_PATH;
|
||||
}
|
||||
|
||||
get socket1IP(): string {
|
||||
return this.SOCKET1_IP;
|
||||
}
|
||||
|
||||
get socket2IP(): string {
|
||||
return this.SOCKET2_IP;
|
||||
get socket2Path(): string {
|
||||
return this.SOCKET2_PATH;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// environments/environment.prod.ts
|
||||
export const environment = {
|
||||
production: true,
|
||||
apiUrl: '' // Produktions-URL (leer wenn gleicher Server)
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
// environments/environment.ts
|
||||
export const environment = {
|
||||
production: false,
|
||||
apiUrl: 'http://localhost:4200' // Entwicklungs-URL
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user