const controlService = require('../../utils/control-service') const { createPageToast } = require('../../utils/page-toast') Page({ data: controlService.getState(), onLoad() { this.pageToast = createPageToast(this, this.data) controlService.init() this.unsubscribeControl = controlService.subscribe((nextState) => { this.setData(nextState) this.pageToast.showFromState(nextState) }) }, onShow() { if (this.pageToast) { this.pageToast.setActive(true) } controlService.syncSharedInputs() }, onHide() { if (this.pageToast) { this.pageToast.setActive(false) } }, onUnload() { if (this.pageToast) { this.pageToast.destroy() this.pageToast = null } if (this.unsubscribeControl) { this.unsubscribeControl() this.unsubscribeControl = null } }, onSpeedCommandInput(event) { controlService.updateSpeedCommandInput(event.detail.value) }, onSpeedCommandBlur(event) { controlService.updateSpeedCommandBlur(event.detail.value) }, readControlStatus() { if (!this.data.connectedDevice) return controlService.readControlStatus() }, onControlButtonTap(event) { if (!this.data.connectedDevice) return controlService.sendControlCommand(event.currentTarget.dataset.key) } })