Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wemo plugin support #3184

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions helper/config.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const configSchema = {
'tpLinkSmartPlug',
'tasmota',
'tasmotaMqtt',
'wemo',
],
properties: {
displayLayerProgress: {
Expand Down Expand Up @@ -276,6 +277,25 @@ const configSchema = {
},
},
},
wemo: {
$id: '#/properties/plugins/properties/wemo',
type: 'object',
required: ['enabled', 'ip'],
properties: {
enabled: {
$id: '#/properties/plugins/properties/ip/properties/enabled',
type: 'boolean',
},
ip: {
$id: '#/properties/plugins/properties/wemo/properties/ip',
type: 'string',
},
port: {
$id: '#/properties/plugins/properties/wemo/properties/port',
type: 'number',
},
},
},
},
},
octodash: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export class AppService {
(config.plugins.tasmota = { enabled: false, ip: '127.0.0.1', index: null }),
"/plugins must have required property 'tasmotaMqtt'": config =>
(config.plugins.tasmotaMqtt = { enabled: false, topic: 'topic', relayNumber: null }),
"/plugins must have required property 'wemo'": config =>
(config.plugins.wemo = { enabled: false, ip: '127.0.0.1', port: 49152 }),
"/octodash must have required property 'previewProgressCircle'": config =>
(config.octodash.previewProgressCircle = false),
"/octodash must have required property 'turnOnPrinterWhenExitingSleep'": config => {
Expand Down
5 changes: 5 additions & 0 deletions src/app/config/config.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export const defaultConfig: Config = {
topic: 'topic',
relayNumber: null,
},
wemo: {
enabled: false,
ip: '127.0.0.1',
port: 49152,
},
},
octodash: {
customActions: [
Expand Down
6 changes: 6 additions & 0 deletions src/app/config/config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ interface Plugins {
tpLinkSmartPlug: TPLinkSmartPlugPlugin;
tasmota: TasmotaPlugin;
tasmotaMqtt: TasmotaMqttPlugin;
wemo: WemoPlugin;
}

interface Plugin {
Expand Down Expand Up @@ -92,6 +93,11 @@ interface TasmotaMqttPlugin extends Plugin {
relayNumber: number;
}

interface WemoPlugin extends Plugin {
ip: string;
port: number;
}

interface OctoDash {
customActions: CustomAction[];
fileSorting: FileSorting;
Expand Down
8 changes: 8 additions & 0 deletions src/app/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ export class ConfigService {
return this.config.plugins.tasmotaMqtt.relayNumber;
}

public useWemo(): boolean {
return this.config.plugins.wemo.enabled;
}

public getWemoIP(): string {
return `${this.config.plugins.wemo.ip}:${this.config.plugins.wemo.port}`;
}

public getFilamentThickness(): number {
return this.config.filament.thickness;
}
Expand Down
6 changes: 6 additions & 0 deletions src/app/config/setup/plugins/plugins.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,10 @@
</app-toggle-switch>
<ng-container i18n="@@plugin-tasmota-mqtt"> Tasmota MQTT </ng-container>
</span>

<span>
<app-toggle-switch [value]="wemoPlugin" (valueChange)="wemoPluginChange.emit(!wemoPlugin)">
</app-toggle-switch>
<ng-container i18n="@@plugin-wemo"> Wemo </ng-container>
</span>
</div>
2 changes: 2 additions & 0 deletions src/app/config/setup/plugins/plugins.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class PluginsComponent {
@Input() tpLinkSmartPlugPlugin: boolean;
@Input() tasmotaPlugin: boolean;
@Input() tasmotaMqttPlugin: boolean;
@Input() wemoPlugin: boolean;

@Output() displayLayerProgressPluginChange = new EventEmitter<boolean>();
@Output() enclosurePluginChange = new EventEmitter<boolean>();
Expand All @@ -29,4 +30,5 @@ export class PluginsComponent {
@Output() tpLinkSmartPlugPluginChange = new EventEmitter<boolean>();
@Output() tasmotaPluginChange = new EventEmitter<boolean>();
@Output() tasmotaMqttPluginChange = new EventEmitter<boolean>();
@Output() wemoPluginChange = new EventEmitter<boolean>();
}
3 changes: 2 additions & 1 deletion src/app/config/setup/setup.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
[(ophomPlugin)]="config.plugins.ophom.enabled"
[(tpLinkSmartPlugPlugin)]="config.plugins.tpLinkSmartPlug.enabled"
[(tasmotaPlugin)]="config.plugins.tasmota.enabled"
[(tasmotaMqttPlugin)]="config.plugins.tasmotaMqtt.enabled"></app-config-setup-plugins>
[(tasmotaMqttPlugin)]="config.plugins.tasmotaMqtt.enabled"
[(wemoPlugin)]="config.plugins.wemo.enabled"></app-config-setup-plugins>

<div *ngIf="page === 6">
<span class="setup__text" i18n="@@checking">Great! I'll check everything.</span>
Expand Down
1 change: 1 addition & 0 deletions src/app/model/octoprint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export * from './plugins/ophomplugstatus.model';
export * from './plugins/tp-link.model';
export * from './plugins/tasmota.model';
export * from './plugins/tasmota-mqtt.model';
export * from './plugins/wemo.model';
4 changes: 4 additions & 0 deletions src/app/model/octoprint/plugins/wemo.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface WemoCommand {
command: 'turnOn' | 'turnOff';
ip: string;
}
25 changes: 25 additions & 0 deletions src/app/services/enclosure/enclosure.octoprint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
TasmotaCommand,
TasmotaMqttCommand,
TPLinkCommand,
WemoCommand,
} from '../../model/octoprint';
import { NotificationService } from '../../notification/notification.service';
import { EnclosureService } from './enclosure.service';
Expand Down Expand Up @@ -158,6 +159,8 @@ export class EnclosureOctoprintService implements EnclosureService {
this.setPSUStateTasmota(state);
} else if (this.configService.useTasmotaMqtt()) {
this.setPSUStateTasmotaMqtt(state);
} else if (this.configService.useWemo()) {
this.setPSUStateWemo(state);
} else {
this.notificationService.setNotification({
heading: $localize`:@@error-psu-state:Can't change PSU State!`,
Expand Down Expand Up @@ -307,6 +310,28 @@ export class EnclosureOctoprintService implements EnclosureService {
.subscribe();
}

private setPSUStateWemo(state: PSUState) {
const wemoPayload: WemoCommand = {
command: state === PSUState.ON ? 'turnOn' : 'turnOff',
ip: this.configService.getWemoIP(),
};

this.http
.post(this.configService.getApiURL('plugin/wemoswitch'), wemoPayload, this.configService.getHTTPHeaders())
.pipe(
catchError(error => {
this.notificationService.setNotification({
heading: $localize`:@@error-send-wemo-plug:Can't update Wemo!`,
text: error.message,
type: NotificationType.ERROR,
time: new Date(),
});
return of(null);
}),
)
.subscribe();
}

togglePSU(): void {
this.currentPSUState === PSUState.ON ? this.setPSUState(PSUState.OFF) : this.setPSUState(PSUState.ON);
}
Expand Down
35 changes: 33 additions & 2 deletions src/app/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@
config.plugins.ophom.enabled ||
config.plugins.tpLinkSmartPlug.enabled ||
config.plugins.tasmota.enabled ||
config.plugins.tasmotaMqtt.enabled
config.plugins.tasmotaMqtt.enabled ||
config.plugins.wemo.enabled
)
}"
(click)="config.octodash.turnOnPrinterWhenExitingSleep = !config.octodash.turnOnPrinterWhenExitingSleep">
Expand All @@ -331,7 +332,8 @@
config.plugins.ophom.enabled ||
config.plugins.tpLinkSmartPlug.enabled ||
config.plugins.tasmota.enabled ||
config.plugins.tasmotaMqtt.enabled
config.plugins.tasmotaMqtt.enabled ||
config.plugins.wemo.enabled
)
}"
*ngIf="config.octodash.turnOnPrinterWhenExitingSleep"></span>
Expand Down Expand Up @@ -635,6 +637,35 @@
style="width: 44.94vw"
[(ngModel)]="config.plugins.tasmotaMqtt.relayNumber"
[disabled]="!config.plugins.tasmotaMqtt.enabled" />
<span class="settings__heading-2" i18n="@@settings-wemo">Wemo</span>
<div
class="settings__checkbox-container"
(click)="config.plugins.wemo.enabled = !config.plugins.wemo.enabled">
<span class="settings__checkbox">
<span class="settings__checkbox-checked" *ngIf="config.plugins.wemo.enabled"></span>
</span>
<span class="settings__checkbox-descriptor" i18n="@@settings-wemo-enabled">enabled</span>
</div>
<label for="wemo-ip" class="settings__input-label" i18n="@@settings-wemo-ip" >Wemo IP</label>
<input
type="text"
id="wemo-ip"
class="settings__input"
name="wemo-ip"
style="width: 44.94vw"
[(ngModel)]="config.plugins.wemo.ip"
required
[disabled]="!config.plugins.wemo.enabled" />
<label for="wemo-port" class="settings__input-label" i18n="@@settings-wemo-port" >Wemo Port</label>
<input
type="number"
id="wemo-port"
class="settings__input"
name="wemo-port"
style="width: 44.94vw"
[(ngModel)]="config.plugins.wemo.port"
required
[disabled]="!config.plugins.wemo.enabled" />
</div>
</div>
<div class="settings__content settings__content-inactive" #settingsCredits>
Expand Down
Loading