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

add fan speed from companion plugin websocket messages #3375

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
add fanspeed from companion plugin websocket messages
  • Loading branch information
jneilliii committed Dec 31, 2022
commit 0a0749a69e9a6b842d2b904b932d16b549821011
4 changes: 3 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ function createWindow() {

if (dev) {
url = 'http://localhost:4200';
window.webContents.openDevTools();
devtools = new BrowserWindow()
window.webContents.setDevToolsWebContents(devtools.webContents)
window.webContents.openDevTools({ mode: 'detach' })
} else {
url = `file://${__dirname}/dist/${locale}/index.html`;
window.setFullScreen(true);
Expand Down
3 changes: 3 additions & 0 deletions src/app/config/config.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export const defaultConfig: Config = {
topic: 'topic',
relayNumber: null,
},
companionPlugin: {
enabled: false,
}
},
octodash: {
customActions: [
Expand Down
1 change: 1 addition & 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;
companionPlugin: Plugin;
}

interface Plugin {
Expand Down
4 changes: 4 additions & 0 deletions src/app/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ export class ConfigService {
return this.config.plugins.displayLayerProgress.enabled;
}

public isCompanionPluginEnabled(): boolean {
return this.config.plugins.companionPlugin.enabled;
}

public isPreheatPluginEnabled(): boolean {
return this.config.plugins.preheatButton.enabled;
}
Expand Down
9 changes: 9 additions & 0 deletions src/app/config/setup/plugins/plugins.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

<div class="setup__plugin-list">
<div class="scroll__thumb-inactive"></div>
<span>
<app-toggle-switch
[value]="companionPlugin"
(valueChange)="companionPluginChange.emit(!companionPlugin)"
>
</app-toggle-switch>
<ng-container i18n="@@plugin-octodash-companion">OctoDash Companion</ng-container>
</span>

<span>
<app-toggle-switch
[value]="displayLayerProgressPlugin"
Expand Down
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() companionPlugin: 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() companionPluginChange = new EventEmitter<boolean>();
}
1 change: 1 addition & 0 deletions src/app/model/octoprint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from './printer-commands.model';
export * from './printer-profile.model';
export * from './socket.model';

export * from './plugins/companion.model';
export * from './plugins/display-layer-progress.model';
export * from './plugins/enclosure.model';
export * from './plugins/filament-manager.model';
Expand Down
17 changes: 13 additions & 4 deletions src/app/services/socket/socket.octoprint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
SocketAuth,
} from '../../model';
import {
CompanionData,
DisplayLayerProgressData,
OctoprintFilament,
OctoprintPluginMessage,
Expand Down Expand Up @@ -81,7 +82,7 @@ export class OctoPrintSocketService implements SocketService {
set: 0,
unit: '°C',
},
fanSpeed: this.configService.isDisplayLayerProgressEnabled() ? 0 : -1,
fanSpeed: this.configService.isDisplayLayerProgressEnabled() || this.configService.isCompanionPluginEnabled() ? 0 : -1,
} as PrinterStatus;
this.printerStatusSubject.next(this.printerStatus);
}
Expand Down Expand Up @@ -168,6 +169,10 @@ export class OctoPrintSocketService implements SocketService {
check: (plugin: string) => ['action_command_prompt', 'action_command_notification'].includes(plugin),
handler: (message: unknown) => this.handlePrinterNotification(message as PrinterNotification),
},
{
check: (plugin: string) => plugin === 'octodash' && this.configService.isCompanionPluginEnabled(),
handler: (message: unknown) => this.extractFanSpeed(message as CompanionData),
},
];

plugins.forEach(plugin => plugin.check(pluginMessage.plugin.plugin) && plugin.handler(pluginMessage.plugin.data));
Expand Down Expand Up @@ -254,9 +259,13 @@ export class OctoPrintSocketService implements SocketService {
this.printerStatusSubject.next(this.printerStatus);
}

public extractFanSpeed(message: DisplayLayerProgressData): void {
this.printerStatus.fanSpeed =
message.fanspeed === 'Off' ? 0 : message.fanspeed === '-' ? 0 : Number(message.fanspeed.replace('%', '').trim());
public extractFanSpeed(message: DisplayLayerProgressData | CompanionData): void {
if (typeof message.fanspeed === 'object') {
this.printerStatus.fanSpeed = Number(Math.round(message.fanspeed["1"]));
} else {
this.printerStatus.fanSpeed =
message.fanspeed === 'Off' ? 0 : message.fanspeed === '-' ? 0 : Number(message.fanspeed.replace('%', '').trim());
}
}

//==== Job Status ====//
Expand Down
9 changes: 9 additions & 0 deletions src/app/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,15 @@
<span i18n="@@settings-plugins">plugins</span>
</span>
<div class="settings__scroll">
<span class="settings__heading-2" i18n="@@settings-display-layer-progress">OctoDash Companion</span>
<div
class="settings__checkbox-container"
(click)="config.plugins.companionPlugin.enabled = !config.plugins.companionPlugin.enabled">
<span class="settings__checkbox">
<span class="settings__checkbox-checked" *ngIf="config.plugins.companionPlugin.enabled"></span>
</span>
<span class="settings__checkbox-descriptor" i18n="@@settings-display-layer-progress-enabled">enabled</span>
</div>
<span class="settings__heading-2" i18n="@@settings-display-layer-progress">Display Layer Progress</span>
<div
class="settings__checkbox-container"
Expand Down