Baylife
September 1, 2023, 7:12pm
1
Hi yall,
Been working on my first app.
I have multiple drivers that have similar logic and therefore wanted to apply some inheritance to to reuse logic in a base driver.
It can compile, but it aint working. Anybody got inheritance working? Or have found a workaround?
class BaseDriver extends Homey.Driver {
...
}
class MyDriver extends BaseDriver {
...
}
spkesDE
September 1, 2023, 7:24pm
2
import HumidifierDeviceBase from "../../lib/HumidifierDeviceBase";
class Classic300s extends HumidifierDeviceBase {
private capabilitiesAddition: string[] = [
"classic300sCapability",
"onoff",
"measure_humidity",
"alarm_water_lacks",
"fanSpeed0to9",
"display_toggle",
"nightlight_toggle"
]
/**
* onInit is called when the device is initialized.
*/
async onInit() {
this.capabilitiesAddition.forEach((c) => this.checkForCapability(c));
This file has been truncated. show original
import Homey from "homey";
import VeSync from "../tsvesync/veSync";
import VeSyncApp from "../app";
import VeSyncHumidifier from "../tsvesync/veSyncHumidifier";
export default class HumidifierDeviceBase extends Homey.Device {
device!: VeSyncHumidifier;
private updateInterval!: NodeJS.Timer;
async onInit() {
await this.getDevice().catch(this.log);
await this.updateDevice().catch(this.error);
if (this.hasCapability("display_toggle"))
this.registerCapabilityListener("display_toggle", async (value) => {
await this.device.setDisplay(value).catch(this.error);
this.log(`Display: ${value}`);
});
if (this.hasCapability("nightlight_toggle"))
this.registerCapabilityListener("nightlight_toggle", async (value) => {
await this.device.setNightLightBrightness(value ? 50 : 0).catch(this.error);
This file has been truncated. show original
It should also work with Drivers, but I’ve never tested it.
Baylife
September 1, 2023, 7:43pm
3
spkesDE:
Classic300s
Ty for some reason the base should be marked as default for it not and not just regular export.
Did you manage to fix it ?