@constructorfleet/ultimate-govee
Version:
Library for interacting with Govee devices written in Typescript.
39 lines • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PresenceState = exports.PresenceStateName = void 0;
const _ultimate_govee_common_1 = require("../../../common");
const device_state_1 = require("./device.state");
const PresenceStateName = (type) => {
return `presence-${type}`;
};
exports.PresenceStateName = PresenceStateName;
class PresenceState extends device_state_1.DeviceOpState {
constructor(device, presenceType, opType = _ultimate_govee_common_1.OpType.REPORT, ...identifier) {
super({ opType, identifier }, device, (0, exports.PresenceStateName)(presenceType), undefined);
this.presenceType = presenceType;
}
parseOpCommand(opCommand) {
const [detected, distanceByte1, distanceByte0] = opCommand.slice(0, 3);
const distance = (0, _ultimate_govee_common_1.total)([distanceByte1, distanceByte0]);
let duration;
if (opCommand.length > 14) {
duration = (0, _ultimate_govee_common_1.total)(opCommand.slice(-12, -8));
}
this.stateValue.next({
type: this.presenceType,
detected: detected === 0x01,
distance: {
unit: 'cm',
value: distance,
},
duration: duration === undefined
? undefined
: {
unit: 's',
value: duration,
},
});
}
}
exports.PresenceState = PresenceState;
//# sourceMappingURL=presence.state.js.map