matterbridge-tado-hw
Version:
A Matterbridge plugin that connects Tado° V2/V3/V3+ hot water control to the Matter smart home ecosystem
66 lines • 2.43 kB
JavaScript
// Matterbridge plugin for Tado hot water control
// Copyright © 2025 Alexander Thoukydides
import { Tado } from 'node-tado-client';
import { logError } from './utils.js';
import { TadoHWZone } from './tado-zone-hw.js';
// Authorise Tado API and enumerate hot water zones
export class TadoAPI {
log;
config;
persist;
tado;
ready;
zones;
// Create a new Tado instance
constructor(log, config, persist) {
this.log = log;
this.config = config;
this.persist = persist;
this.tado = new Tado();
this.ready = this.initAsync();
}
// Authenticate with Tado
async initAsync() {
// Save tokens when they are refreshed
this.tado.setTokenCallback(tokens => void this.saveToken(tokens));
// Retrieve any saved tokens
const token = await this.persist.getItem('tado_token');
// Attempt OAuth authorisation
const [verify, tokenPromise] = await this.tado.authenticate(token?.refresh_token);
if (verify) {
this.log.info(`Authorise Tado account access (within ${verify.expires_in} seconds):`);
this.log.info(` ${verify.verification_uri_complete}`);
}
await tokenPromise;
this.log.info('Tado account access authorised');
}
// Save tokens when they are refreshed
async saveToken(token) {
try {
this.log.info(`Tado tokens refreshed (expires ${token.expiry.toISOString()})`);
await this.persist.setItem('tado_token', token);
}
catch (err) {
logError(this.log, 'Save Tado token', err);
}
}
// Get the hot water control zones
async getHWZones() {
await this.ready;
// Iterate through the homes in the account
const me = await this.tado.getMe();
this.zones = [];
for (const home of me.homes) {
// Obtain a list of hot water zones in this home
const zones = await this.tado.getZones(home.id);
const zonesHW = zones.filter(zone => zone.type === 'HOT_WATER');
// Instantiate a controller for each hot water zone
for (const zone of zonesHW) {
const tadoHWZone = new TadoHWZone(this.log, this.config, this.tado, home.id, zone);
this.zones.push(tadoHWZone);
}
}
return this.zones;
}
}
//# sourceMappingURL=tado.js.map