vastra-radiator-valve
Version:
Node.js library to query and configure Vastra's smart radiator valves.
81 lines (80 loc) • 2.75 kB
TypeScript
/// <reference types="node" />
import { IGattPeripheral } from "./bluetooth";
import { RadiatorValvesOptions } from "./scanner";
import { StateFieldInfo } from "./valve-state";
export default class RadiatorValve {
readonly peripheral: IGattPeripheral;
private readonly options;
/** Characteristic used to read data from the device. */
private rx?;
/** Characteristic used to write data to the device. */
private tx?;
private lastSentWakeUpTime;
private logger;
constructor(peripheral: IGattPeripheral, options: Readonly<RadiatorValvesOptions>);
/**
* Attempts to establish a connection with the device.
*
* @param attempt Counts how many attempts have been made so far. For internal use only.
*/
connect(attempt?: number): Promise<void>;
/**
* Closes connection with the peripheral.
*/
disconnect(): Promise<void>;
/**
* Writes data contained in given buffer to the device.
* Make sure to wait for the message to be fully sent by `await`-ing this
* method before writing more data.
*
* @param data Data to write.
*/
private write;
/**
* Writes a request to the device and waits for the response.
*
* @param request Request to send.
* @returns Response.
*/
private sendRequest;
/**
* Sends Wake Up command to the peripheral and waits for a response.
*/
requestWakeUp(): Promise<void>;
/**
* Requests value of a single field from peripheral's state buffer.
* @returns Buffer containing the value.
*/
requestReadField<T>(field: StateFieldInfo<T>): Promise<T>;
/**
* Updates the value of a field.
*
* @param field Field to update.
* @param value New value.
*/
requestWriteField<T>(field: StateFieldInfo<T>, value: T): Promise<void>;
/**
* Requests a snapshot of the entire state buffer from the peripheral.
* @returns Buffer containing the state.
*/
requestStateSnapshot(): Promise<Buffer>;
setName(name: string): Promise<void>;
getName(): Promise<string>;
getSerialNumber(): Promise<string>;
setLocked(locked: boolean): Promise<void>;
getLocked(): Promise<number>;
getBatteryVoltage(): Promise<number>;
getTemperatureDeviation(): Promise<number>;
getCurrentTemperature(): Promise<number>;
/**
* Sets the target temperature.
* It takes up to 9 minutes for the valve to actually apply
* the update in case of this field.
*
* @param value New target temperature.
*/
setTargetTemperature(value: number): Promise<void>;
private getTargetTemperatureField;
getTargetTemperature(): Promise<number>;
getMode(): Promise<number>;
}