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

Improve: auth debugging #7

Merged
merged 7 commits into from
Jun 11, 2024
Merged
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
5 changes: 3 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "athom/homey-app"
}
"extends": "athom/homey-app",
"strict": "off"
}
3 changes: 3 additions & 0 deletions .homeychangelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
},
"0.0.5": {
"en": "Handle networking errors and add debugging feature"
},
"0.0.6": {
"en": "Additional debug for pairing, fix reported crashes"
}
}
2 changes: 1 addition & 1 deletion .homeycompose/app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "com.christerbeke.remeha-home",
"version": "0.0.5",
"version": "0.0.6",
"compatibility": ">=5.0.0",
"sdk": 3,
"platforms": [
Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"_comment": "This file is generated. Please edit .homeycompose/app.json instead.",
"id": "com.christerbeke.remeha-home",
"version": "0.0.5",
"version": "0.0.6",
"compatibility": ">=5.0.0",
"sdk": 3,
"platforms": [
Expand Down
4 changes: 4 additions & 0 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ sourceMapSupport.install()

import { App } from 'homey'

const { Log } = require('homey-log')

class RemehaApp extends App {
async onInit() {
// @ts-ignore TS2339
this.homeyLog = new Log({ homey: this.homey })
this.log('RemehaApp is running...')
}
}
Expand Down
7 changes: 1 addition & 6 deletions drivers/remeha/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class RemehaThermostatDevice extends Device {
this._init()
}

async onDeleted(): Promise<void> {
this._uninit()
}

private async _init(): Promise<void> {
const { accessToken } = this.getStore()
this._client = new RemehaMobileApi(accessToken)
Expand All @@ -38,7 +34,6 @@ class RemehaThermostatDevice extends Device {
}

async _uninit(): Promise<void> {
this.setUnavailable()
clearInterval(this._syncInterval as NodeJS.Timeout)
this._syncInterval = undefined
this._client = undefined
Expand Down Expand Up @@ -70,7 +65,7 @@ class RemehaThermostatDevice extends Device {
if (!debugEnabled) return
const debug = await this._client.debug()
this.setSettings({ apiData: JSON.stringify(debug) })
} catch (error) {}
} catch (error) { }
}

private async _setTargetTemperature(value: number): Promise<void> {
Expand Down
35 changes: 13 additions & 22 deletions drivers/remeha/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,21 @@ class RemehaDriver extends Driver {
private _tokenData: TokenData | null = null

async onPair(session: PairSession) {
session.setHandler('login', this._login.bind(this))
session.setHandler('list_devices', this._listDevices.bind(this))
}

const driver = this

session.setHandler('login', async function (credentials: string): Promise<boolean> {
const authorizer = new RemehaAuth()
const [email, password] = credentials.split(':')
try {
driver._tokenData = await authorizer.login(email, password)
return true
} catch (error) {
return false
}
})
private async _login(credentials: string): Promise<any> {
const authorizer = new RemehaAuth()
const [email, password] = credentials.split(':')
this._tokenData = await authorizer.login(email, password)
}

session.setHandler('list_devices', async function (): Promise<any[]> {
if (!driver._tokenData || !driver._tokenData.accessToken) return []
const api = new RemehaMobileApi(driver._tokenData.accessToken)
try {
const devices = await api.devices()
return devices.map(driver._mapDevice.bind(driver))
} catch (error) {
return []
}
})
private async _listDevices(): Promise<any[]> {
if (!this._tokenData || !this._tokenData.accessToken) return []
const api = new RemehaMobileApi(this._tokenData.accessToken)
const devices = await api.devices()
return devices.map(this._mapDevice.bind(this))
}

private _mapDevice(device: DeviceData): any {
Expand Down
11 changes: 3 additions & 8 deletions drivers/remeha/pair/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
var email = document.getElementById('email').value
var password = document.getElementById('password').value
Homey.showLoadingOverlay()
Homey.emit('login', `${email}:${password}`).then((success) => {
if (success) {
Homey.showView('list_devices')
} else {
Homey.alert(Homey.__('pair.login_error'), 'error')
Homey.done()
}
Homey.emit('login', `${email}:${password}`).then(() => {
Homey.showView('list_devices')
}).catch(error => {
Homey.alert(Homey.__('pair.login_error'), 'error')
Homey.alert(error.message, 'error')
Homey.done()
}).finally(() => {
Homey.hideLoadingOverlay()
Expand Down
93 changes: 93 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
},
"dependencies": {
"fetch-cookie": "^3.0.1",
"homey-log": "^2.1.0",
"node-fetch": "^2.6.1",
"source-map-support": "^0.5.21"
},
"devDependencies": {
"@tsconfig/node16": "^16.1.3",
"@tsconfig/node12": "^1.0.11",
"@tsconfig/node16": "^16.1.3",
"@types/homey": "npm:homey-apps-sdk-v3-types@^0.3.5",
"@types/node": "^20.12.7",
"@types/node-fetch": "^2.6.11",
Expand Down
Loading