Files
new-landing-page-homenas/src/app/tasmota.service.ts
T

40 lines
1.0 KiB
TypeScript
Raw Normal View History

// tasmota.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
@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
constructor(private http: HttpClient) { }
toggleSocket(socketIP: string, currentStatus: boolean): Observable<boolean> {
const command = currentStatus ? 'Power%20Off' : 'Power%20On';
return this.http.get<any>(`http://${socketIP}/cm?cmnd=${command}`)
.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 socket1IP(): string {
return this.SOCKET1_IP;
}
get socket2IP(): string {
return this.SOCKET2_IP;
}
}