node-miio
Version:
Control Mi Home devices, such as Mi Robot Vacuums, Mi Air Purifiers, Mi Smart Home Gateway (Aqara) and more
30 lines (22 loc) • 660 B
JavaScript
const SubDevice = require('./subdevice');
const { Contact } = require('abstract-things/sensors');
const Voltage = require('./voltage');
/**
* Magnet device, emits events `open` and `close` if the state changes.
*/
module.exports = class Magnet extends SubDevice.with(Contact, Voltage) {
constructor(parent, info) {
super(parent, info);
this.miioModel = 'lumi.magnet';
this.defineProperty('status');
}
propertyUpdated(key, value, oldValue) {
if(key === 'status') {
// Change the contact state
const isContact = value === 'close';
this.updateContact(isContact);
}
super.propertyUpdated(key, value, oldValue);
}
};
;