// tasmota.service.ts import { Injectable } from '@angular/core'; 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 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) { } getSocketStatus(socketPath: string): Observable { return this.http.get(`${socketPath}/cm?cmnd=Power`, this.httpOptions) .pipe( map(response => response.POWER === 'ON') ); } toggleSocket(socketPath: string, currentStatus: boolean): Observable { const command = currentStatus ? 'Power%20Off' : 'Power%20On'; return this.http.get(`${socketPath}/cm?cmnd=${command}`, this.httpOptions) .pipe( map(response => response.POWER === 'ON') ); } get socket1Path(): string { return this.SOCKET1_PATH; } get socket2Path(): string { return this.SOCKET2_PATH; } }