Skip to content

Commit

Permalink
feature/tasmota (UnchartedBull#1581)
Browse files Browse the repository at this point in the history
* feature/tasmota (UnchartedBull#6)

* add tasmota plugin power options

* add Tasmota MQTT plugin support

* update install script for power plugins

* Bump lottie-web from 5.7.6 to 5.7.7 (UnchartedBull#1587)

* Update scripts urls in docs files (UnchartedBull#1585)

* Bump @typescript-eslint/parser from 4.18.0 to 4.19.0 (UnchartedBull#1589)

* Bump @typescript-eslint/eslint-plugin from 4.18.0 to 4.19.0 (UnchartedBull#1590)

* Fix a few small bugs (UnchartedBull#1588)

* fix websocket and config upgrade bug (UnchartedBull#1594)

* cache animations (UnchartedBull#1595)

* fix formatting

* update idx to index and relayN to relayNumber

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Jc Miñarro <[email protected]>
Co-authored-by: Timon G <[email protected]>
  • Loading branch information
4 people authored and pciavald committed May 12, 2021
1 parent 015156c commit 9adfe9d
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 4 deletions.
11 changes: 10 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ elif [ ! -d $DIRECTORY ]; then
fi;

if [ $DIRECTORY != "-" ]; then
plugins=( 'Display Layer Progress (mandatory)' 'Filament Manager' 'Preheat Button' 'Enclosure' 'Print Time Genius' 'Ultimaker Format Package' 'PrusaSlicer Thumbnails' )
plugins=( 'Display Layer Progress (mandatory)' 'Filament Manager' 'Preheat Button' 'Enclosure' 'Print Time Genius' 'Ultimaker Format Package' 'PrusaSlicer Thumbnails' 'TPLinkSmartPlug' 'Tasmota' 'TasmotaMQTT')
checkbox_input "Which plugins should I install (you can also install them via the Octoprint UI)?" plugins selected_plugins
echo "Installing Plugins..."

Expand All @@ -728,6 +728,15 @@ if [ $DIRECTORY != "-" ]; then
if [[ " ${selected_plugins[@]} " =~ "PrusaSlicer Thumbnails" ]]; then
"$DIRECTORY"/bin/pip install -q --disable-pip-version-check "https://github.com/jneilliii/OctoPrint-PrusaSlicerThumbnails/archive/master.zip"
fi;
if [[ " ${selected_plugins[@]} " =~ "TPLinkSmartplug" ]]; then
"$DIRECTORY"/bin/pip install -q --disable-pip-version-check "https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/archive/master.zip"
fi;
if [[ " ${selected_plugins[@]} " =~ "Tasmota" ]]; then
"$DIRECTORY"/bin/pip install -q --disable-pip-version-check "https://github.com/jneilliii/OctoPrint-Tasmota/archive/master.zip"
fi;
if [[ " ${selected_plugins[@]} " =~ "TasmotaMQTT" ]]; then
"$DIRECTORY"/bin/pip install -q --disable-pip-version-check "https://github.com/jneilliii/OctoPrint-TasmotaMQTT/archive/master.zip"
fi;
fi;

echo "Installing OctoDash "${version[7]}, $arch" ..."
Expand Down
6 changes: 5 additions & 1 deletion src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export class AppService {
this.updateError = {
".printer should have required property 'zBabystepGCode'": config => (config.printer.zBabystepGCode = 'M290 Z'),
".plugins should have required property 'tpLinkSmartPlug'": config =>
(config.plugins.tpLinkSmartPlug = { enabled: true, smartPlugIP: '127.0.0.1' }),
(config.plugins.tpLinkSmartPlug = { enabled: false, smartPlugIP: '127.0.0.1' }),
".plugins should have required property 'tasmota'": config =>
(config.plugins.tasmota = { enabled: false, ip: '127.0.0.1', index: null }),
".plugins should have required property 'tasmotaMqtt'": config =>
(config.plugins.tasmotaMqtt = { enabled: false, topic: 'topic', relayNumber: null }),
".octodash should have required property 'previewProgressCircle'": config =>
(config.octodash.previewProgressCircle = false),
".octodash should have required property 'turnOnPrinterWhenExitingSleep'": config => {
Expand Down
10 changes: 10 additions & 0 deletions src/app/config/config.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ export const defaultConfig: Config = {
enabled: false,
smartPlugIP: '127.0.0.1',
},
tasmota: {
enabled: false,
ip: '127.0.0.1',
index: null,
},
tasmotaMqtt: {
enabled: false,
topic: 'topic',
relayNumber: null,
},
},
octodash: {
customActions: [
Expand Down
12 changes: 12 additions & 0 deletions src/app/config/config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ interface Plugins {
printTimeGenius: Plugin;
psuControl: PSUControlPlugin;
tpLinkSmartPlug: TPLinkSmartPlugPlugin;
tasmota: TasmotaPlugin;
tasmotaMqtt: TasmotaMqttPlugin;
}

interface Plugin {
Expand All @@ -78,6 +80,16 @@ interface TPLinkSmartPlugPlugin extends Plugin {
smartPlugIP: string;
}

interface TasmotaPlugin extends Plugin {
ip: string;
index: number;
}

interface TasmotaMqttPlugin extends Plugin {
topic: string;
relayNumber: number;
}

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

public useTasmota(): boolean {
return this.config.plugins.tasmota.enabled;
}

public getTasmotaIP(): string {
return this.config.plugins.tasmota.ip;
}

public getTasmotaIndex(): number {
return this.config.plugins.tasmota.index;
}

public useTasmotaMqtt(): boolean {
return this.config.plugins.tasmotaMqtt.enabled;
}

public getTasmotaMqttTopic(): string {
return this.config.plugins.tasmotaMqtt.topic;
}

public getTasmotaMqttRelayNumber(): number {
return this.config.plugins.tasmotaMqtt.relayNumber;
}

public getFilamentThickness(): number {
return this.config.filament.thickness;
}
Expand Down
12 changes: 12 additions & 0 deletions src/app/config/setup/plugins/plugins.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,16 @@
TPLink SmartPlug
</ng-container>
</div>
<div class="setup__checkbox-container" (click)="changeTasmotaPlugin()">
<span class="setup__checkbox">
<span class="setup__checkbox-checked" *ngIf="tasmotaPlugin"></span>
</span>
Tasmota
</div>
<div class="setup__checkbox-container" (click)="changeTasmotaMqttPlugin()">
<span class="setup__checkbox">
<span class="setup__checkbox-checked" *ngIf="tasmotaMqttPlugin"></span>
</span>
Tasmota MQTT
</div>
</div>
14 changes: 14 additions & 0 deletions src/app/config/setup/plugins/plugins.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export class PluginsComponent {
@Input() printTimeGeniusPlugin: boolean;
@Input() psuControlPlugin: boolean;
@Input() tpLinkSmartPlugPlugin: boolean;
@Input() tasmotaPlugin: boolean;
@Input() tasmotaMqttPlugin: boolean;

@Output() displayLayerProgressPluginChange = new EventEmitter<boolean>();
@Output() enclosurePluginChange = new EventEmitter<boolean>();
Expand All @@ -21,6 +23,8 @@ export class PluginsComponent {
@Output() printTimeGeniusPluginChange = new EventEmitter<boolean>();
@Output() psuControlPluginChange = new EventEmitter<boolean>();
@Output() tpLinkSmartPlugPluginChange = new EventEmitter<boolean>();
@Output() tasmotaPluginChange = new EventEmitter<boolean>();
@Output() tasmotaMqttPluginChange = new EventEmitter<boolean>();

public changeDisplayLayerProgressPlugin(): void {
this.displayLayerProgressPlugin = !this.displayLayerProgressPlugin;
Expand Down Expand Up @@ -56,4 +60,14 @@ export class PluginsComponent {
this.tpLinkSmartPlugPlugin = !this.tpLinkSmartPlugPlugin;
this.tpLinkSmartPlugPluginChange.emit(this.tpLinkSmartPlugPlugin);
}

public changeTasmotaPlugin(): void {
this.tasmotaPlugin = !this.tasmotaPlugin;
this.tasmotaPluginChange.emit(this.tasmotaPlugin);
}

public changeTasmotaMqttPlugin(): void {
this.tasmotaMqttPlugin = !this.tasmotaMqttPlugin;
this.tasmotaMqttPluginChange.emit(this.tasmotaMqttPlugin);
}
}
2 changes: 2 additions & 0 deletions src/app/config/setup/setup.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
[(printTimeGeniusPlugin)]="config.plugins.printTimeGenius.enabled"
[(psuControlPlugin)]="config.plugins.psuControl.enabled"
[(tpLinkSmartPlugPlugin)]="config.plugins.tpLinkSmartPlug.enabled"
[(tasmotaPlugin)]="config.plugins.tasmota.enabled"
[(tasmotaMqttPlugin)]="config.plugins.tasmotaMqtt.enabled"
></app-config-setup-plugins>

<div *ngIf="page === 6">
Expand Down
2 changes: 2 additions & 0 deletions src/app/model/octoprint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ export * from './plugins/enclosure.model';
export * from './plugins/filament-manager.model';
export * from './plugins/psucontrol.model';
export * from './plugins/tp-link.model';
export * from './plugins/tasmota.model';
export * from './plugins/tasmota-mqtt.model';
5 changes: 5 additions & 0 deletions src/app/model/octoprint/plugins/tasmota-mqtt.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface TasmotaMqttCommand {
command: 'turnOn' | 'turnOff';
topic: string;
relayN: number;
}
5 changes: 5 additions & 0 deletions src/app/model/octoprint/plugins/tasmota.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface TasmotaCommand {
command: 'turnOn' | 'turnOff';
ip: string;
idx: number;
}
32 changes: 32 additions & 0 deletions src/app/services/enclosure/enclosure.octoprint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
EnclosurePluginAPI,
PSUControlCommand,
TPLinkCommand,
TasmotaCommand,
TasmotaMqttCommand,
} from '../../model/octoprint';
import { NotificationService } from '../../notification/notification.service';
import { EnclosureService } from './enclosure.service';
Expand Down Expand Up @@ -79,6 +81,10 @@ export class EnclosureOctoprintService implements EnclosureService {
this.setPSUStatePSUControl(state);
} else if (this.configService.useTpLinkSmartPlug()) {
this.setPSUStateTPLink(state);
} else if (this.configService.useTasmota()) {
this.setPSUStateTasmota(state);
} else if (this.configService.useTasmotaMqtt()) {
this.setPSUStateTasmotaMqtt(state);
} else {
this.notificationService.setWarning($localize`:@@error-psu-state:Can't change PSU State!`, $localize`:@@error-psu-provider:No provider for PSU Control is configured.`);
}
Expand Down Expand Up @@ -107,6 +113,32 @@ export class EnclosureOctoprintService implements EnclosureService {
.subscribe();
}

private setPSUStateTasmota(state: PSUState) {
const tasmotaPayload: TasmotaCommand = {
command: state === PSUState.ON ? 'turnOn' : 'turnOff',
ip: this.configService.getTasmotaIP(),
idx: this.configService.getTasmotaIndex(),
};

this.http
.post(this.configService.getApiURL('plugin/tasmota'), tasmotaPayload, this.configService.getHTTPHeaders())
.pipe(catchError(error => this.notificationService.setError("Can't send GCode!", error.message)))
.subscribe();
}

private setPSUStateTasmotaMqtt(state: PSUState) {
const tasmotaMqttPayload: TasmotaMqttCommand = {
command: state === PSUState.ON ? 'turnOn' : 'turnOff',
topic: this.configService.getTasmotaMqttTopic(),
relayN: this.configService.getTasmotaMqttRelayNumber(),
};

this.http
.post(this.configService.getApiURL('plugin/tasmota_mqtt'), tasmotaMqttPayload, this.configService.getHTTPHeaders())
.pipe(catchError(error => this.notificationService.setError("Can't send GCode!", error.message)))
.subscribe();
}

togglePSU(): void {
this.currentPSUState === PSUState.ON ? this.setPSUState(PSUState.OFF) : this.setPSUState(PSUState.ON);
}
Expand Down
66 changes: 64 additions & 2 deletions src/app/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@
class="settings__checkbox-container"
[ngClass]="{
'settings__checkbox-container-disabled': !(
config.plugins.psuControl.enabled || config.plugins.tpLinkSmartPlug.enabled
config.plugins.psuControl.enabled || config.plugins.tpLinkSmartPlug.enabled || config.plugins.tasmota.enabled || config.plugins.tasmotaMqtt.enabled
)
}"
(click)="config.octodash.turnOnPrinterWhenExitingSleep = !config.octodash.turnOnPrinterWhenExitingSleep"
Expand All @@ -323,7 +323,7 @@
class="settings__checkbox-checked"
[ngClass]="{
'settings__checkbox-checked-disabled': !(
config.plugins.psuControl.enabled || config.plugins.tpLinkSmartPlug.enabled
config.plugins.psuControl.enabled || config.plugins.tpLinkSmartPlug.enabled || config.plugins.tasmota.enabled || config.plugins.tasmotaMqtt.enabled
)
}"
*ngIf="config.octodash.turnOnPrinterWhenExitingSleep"
Expand Down Expand Up @@ -596,6 +596,68 @@
required
[disabled]="!config.plugins.tpLinkSmartPlug.enabled"
/>
<span class="settings__heading-2">Tasmota</span>
<div
class="settings__checkbox-container"
(click)="config.plugins.tasmota.enabled = !config.plugins.tasmota.enabled"
>
<span class="settings__checkbox">
<span class="settings__checkbox-checked" *ngIf="config.plugins.tasmota.enabled"></span>
</span>
<span class="settings__checkbox-descriptor">enabled</span>
</div>
<label for="tasmota-ip" class="settings__input-label">IP</label>
<input
type="text"
id="tasmota-ip"
class="settings__input"
name="tasmota-ip"
style="width: 44.94vw"
[(ngModel)]="config.plugins.tasmota.ip"
required
[disabled]="!config.plugins.tasmota.enabled"
/>
<label for="tasmota-idx" class="settings__input-label">Index</label>
<input
type="number"
id="tasmota-idx"
class="settings__input"
name="tasmota-idx"
style="width: 44.94vw"
[(ngModel)]="config.plugins.tasmota.index"
[disabled]="!config.plugins.tasmota.enabled"
/>
<span class="settings__heading-2">Tasmota MQTT</span>
<div
class="settings__checkbox-container"
(click)="config.plugins.tasmotaMqtt.enabled = !config.plugins.tasmotaMqtt.enabled"
>
<span class="settings__checkbox">
<span class="settings__checkbox-checked" *ngIf="config.plugins.tasmotaMqtt.enabled"></span>
</span>
<span class="settings__checkbox-descriptor">enabled</span>
</div>
<label for="tasmotaMqtt-topic" class="settings__input-label">Topic</label>
<input
type="text"
id="tasmotaMqtt-topic"
class="settings__input"
name="tasmotaMqtt-topic"
style="width: 44.94vw"
[(ngModel)]="config.plugins.tasmotaMqtt.topic"
required
[disabled]="!config.plugins.tasmotaMqtt.enabled"
/>
<label for="tasmotaMqtt-relayN" class="settings__input-label">RelayN</label>
<input
type="number"
id="tasmotaMqtt-relayN"
class="settings__input"
name="tasmotaMqtt-relayN"
style="width: 44.94vw"
[(ngModel)]="config.plugins.tasmotaMqtt.relayNumber"
[disabled]="!config.plugins.tasmotaMqtt.enabled"
/>
</div>
</div>
<div class="settings__content settings__content-inactive" #settingsCredits>
Expand Down

0 comments on commit 9adfe9d

Please sign in to comment.