Tasmota component hinzugefuegt - CORSprobleme

This commit is contained in:
2025-03-12 11:16:31 +01:00
parent e21677311c
commit 7f818f5463
12 changed files with 749 additions and 267 deletions
+3
View File
@@ -104,5 +104,8 @@
} }
} }
} }
},
"cli": {
"analytics": false
} }
} }
+510 -265
View File
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -1,10 +1,12 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router'; import { RouterModule, Routes } from '@angular/router';
import { LinksComponent } from './links/links.component'; import { LinksComponent } from './links/links.component';
import { TasmotaControlComponent } from './tasmota-control/tasmota-control.component';
const routes: Routes = [ const routes: Routes = [
{ path: '', redirectTo: '/list-links', pathMatch: 'full'}, { path: '', redirectTo: '/list-links', pathMatch: 'full'},
{ path: 'list-links', component:LinksComponent } { path: 'list-links', component:LinksComponent },
{ path: 'steckdosen', component:TasmotaControlComponent}
]; ];
@NgModule({ @NgModule({
+8
View File
@@ -5,6 +5,14 @@
<img src="assets/img/net-so.org.logo.png" alt="" width="100" class="d-inline-block align-text-center"> <img src="assets/img/net-so.org.logo.png" alt="" width="100" class="d-inline-block align-text-center">
Net-So.Org Net-So.Org
</a> </a>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" routerLink="/list-links" routerLinkActive="active">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLink="/steckdosen" routerLinkActive="active">Steckdosen</a>
</li>
</ul>
</div> </div>
</nav> </nav>
+4 -1
View File
@@ -6,11 +6,14 @@ import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http'; import { HttpClientModule } from '@angular/common/http';
import { LinksComponent } from './links/links.component'; import { LinksComponent } from './links/links.component';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { TasmotaControlComponent } from './tasmota-control/tasmota-control.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
AppComponent, AppComponent,
LinksComponent LinksComponent,
TasmotaControlComponent
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
+33
View File
@@ -0,0 +1,33 @@
/* tasmota-control.component.css */
.tasmota-control {
padding: 20px;
}
.socket-control {
margin: 20px 0;
padding: 15px;
border: 1px solid #ccc;
border-radius: 5px;
}
.socket-control button {
padding: 10px 20px;
margin-right: 10px;
border-radius: 5px;
border: none;
cursor: pointer;
}
.socket-control button.on {
background-color: #ff4444;
color: white;
}
.socket-control button.off {
background-color: #44ff44;
color: black;
}
.socket-control span {
margin-left: 10px;
}
@@ -0,0 +1,33 @@
/* tasmota-control.component.css */
.tasmota-control {
padding: 20px;
}
.socket-control {
margin: 20px 0;
padding: 15px;
border: 1px solid #ccc;
border-radius: 5px;
}
.socket-control button {
padding: 10px 20px;
margin-right: 10px;
border-radius: 5px;
border: none;
cursor: pointer;
}
.socket-control button.on {
background-color: #ff4444;
color: white;
}
.socket-control button.off {
background-color: #44ff44;
color: black;
}
.socket-control span {
margin-left: 10px;
}
@@ -0,0 +1,27 @@
<!-- tasmota-control.component.html -->
<div class="tasmota-control">
<h2>Tasmota Steckdosen Steuerung</h2>
<div class="socket-control">
<h3>Steckdose 1</h3>
<button
(click)="toggleSocket1()"
[class.on]="socket1Status"
[class.off]="!socket1Status">
{{ socket1Status ? 'Ausschalten' : 'Einschalten' }}
</button>
<span>Status: {{ socket1Status ? 'Ein' : 'Aus' }}</span>
</div>
<div class="socket-control">
<h3>Steckdose 2</h3>
<button
(click)="toggleSocket2()"
[class.on]="socket2Status"
[class.off]="!socket2Status">
{{ socket2Status ? 'Ausschalten' : 'Einschalten' }}
</button>
<span>Status: {{ socket2Status ? 'Ein' : 'Aus' }}</span>
</div>
</div>
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TasmotaControlComponent } from './tasmota-control.component';
describe('TasmotaControlComponent', () => {
let component: TasmotaControlComponent;
let fixture: ComponentFixture<TasmotaControlComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [TasmotaControlComponent]
})
.compileComponents();
fixture = TestBed.createComponent(TasmotaControlComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,50 @@
// tasmota-control.component.ts
import { Component, OnInit } from '@angular/core';
import { TasmotaService } from '../tasmota.service';
@Component({
selector: 'app-tasmota-control',
templateUrl: './tasmota-control.component.html',
styleUrls: ['./tasmota-control.component.css']
})
export class TasmotaControlComponent implements OnInit {
socket1Status = false;
socket2Status = false;
constructor(private tasmotaService: TasmotaService) { }
ngOnInit(): void {
this.updateSocketStatuses();
}
updateSocketStatuses(): void {
this.tasmotaService.getSocketStatus(this.tasmotaService.socket1IP)
.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)
.subscribe({
next: (status) => this.socket2Status = status,
error: (error) => console.error('Fehler beim Abrufen des Status von Steckdose 2:', error)
});
}
toggleSocket1(): void {
this.tasmotaService.toggleSocket(this.tasmotaService.socket1IP, this.socket1Status)
.subscribe({
next: (status) => this.socket1Status = status,
error: (error) => console.error('Fehler beim Schalten von Steckdose 1:', error)
});
}
toggleSocket2(): void {
this.tasmotaService.toggleSocket(this.tasmotaService.socket2IP, this.socket2Status)
.subscribe({
next: (status) => this.socket2Status = status,
error: (error) => console.error('Fehler beim Schalten von Steckdose 2:', error)
});
}
}
+16
View File
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { TasmotaService } from './tasmota.service';
describe('TasmotaControlService', () => {
let service: TasmotaService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(TasmotaService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
+39
View File
@@ -0,0 +1,39 @@
// 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;
}
}