@tantchen/fritzapi
Version:
Home automation node API for Fritz!Box, Fritz!DECT and FRITZ!Powerline devices
280 lines (279 loc) • 7.97 kB
TypeScript
/**
* smartFritz - Fritz goes smartHome
*
* AVM SmartHome nodeJS Control - for AVM Fritz!Box and Dect200 Devices
*
* @author Andreas Goetz <cpuidle@gmx.de>
*
* Forked from: https://github.com/nischelwitzer/smartfritz
* nischi - first version: July 2014
*
* based on: Node2Fritz by steffen.timm on 05.12.13 for Fritz!OS > 05.50
* and thk4711 (code https://github.com/pimatic/pimatic/issues/38)
*
* AVM Documentation is at https://avm.de/service/schnittstellen/
*/
import { AVMDevice, ColorName, IBase, IExt, IState, ITemp, OSInfo } from './utils';
export default class Fritz {
protected sid: string | null;
protected username: string;
protected password: string;
protected url: string;
protected deviceList: AVMDevice[] | null;
/**
* Default constructor
* @param username
* @param password
* @param url if not set default is 'http://fritz.box'
*/
constructor(username: string, password: string, url?: string);
/**
* get SID
*/
getSID(): Promise<string>;
/**
* Request helper
* @param request
* @param options
* @private
*/
private static httpRequest;
/**
* Execute Fritz API command for device specified by AIN
*/
executeCommand<T>(sid: boolean, command: string | null, ain: string | null, path?: string, ...param: string[]): Promise<T>;
/**
* get session id
* @param username
* @param password
* @private
*/
private getSessionID;
/**
* check if session id is OK
*/
checkSession(): Promise<boolean>;
/**
* get OS version
*/
getOSVersion(): Promise<string | null>;
/**
* get full FritzBox config
*/
getDataSheet(): Promise<OSInfo>;
/**
* get template information (XML)
*/
getTemplateListInfos(): Promise<string>;
/**
* get template information (json)
*/
getTemplateList: IBase<any[]>;
/**
* apply template
* @param ain
*/
applyTemplate(ain: string): Promise<unknown>;
/**
* get basic device info (XML)
* @param ain
*/
getBasicDeviceStats(ain: string): Promise<unknown>;
/**
* get detailed device information (XML)
*/
getDeviceListInfos(): Promise<string>;
/**
* get device list
*/
getDeviceList(): Promise<AVMDevice[]>;
/**
* get device list by filter criteria
* @param filter
*/
getDeviceListFiltered(filter: any): Promise<AVMDevice[]>;
/**
* get single device
* @param ain
*/
getDevice(ain: string): Promise<AVMDevice | null>;
/**
* get temperature- both switches and thermostats are supported, but not powerline modules
* @param ain
*/
getTemperature(ain: string): Promise<number>;
/**
* get presence from deviceListInfo
* @param ain
*/
getPresence(ain: string): Promise<boolean>;
/**
* get switch list
*/
getSwitchList(): Promise<any[]>;
/**
* get switch state
* @param ain
*/
getSwitchState: IExt<boolean>;
/**
* turn an outlet on. returns the state the outlet was set to
* @param ain
*/
setSwitchOn: IExt<boolean>;
/**
* turn an outlet off. returns the state the outlet was set to
* @param ain
*/
setSwitchOff: IExt<boolean>;
/**
* toggle an outlet. returns the state the outlet was set to
* @param ain
*/
setSwitchToggle: IExt<boolean>;
/**
* get the total enery consumption. returns the value in Wh
* @param ain
*/
getSwitchEnergy: IExt<number>;
/**
* get the current enery consumption of an outlet. returns the value in mW
* @param ain
*/
getSwitchPower: IExt<number | null>;
/**
* get the outet presence status
* @param ain
*/
getSwitchPresence: IExt<boolean>;
/**
* get switch name
* @param ain
*/
getSwitchName: IExt<string>;
/**
* get the thermostat list
*/
getThermostatList: IBase<any>;
/**
* set target temperature (Solltemperatur)
* @param ain
* @param temp
*/
setTempTarget(ain: string, temp: number): Promise<number>;
/**
* get target temperature (Solltemperatur)
* @param ain
*/
getTempTarget: IExt<ITemp>;
/**
* get night temperature (Absenktemperatur)
* @param ain
*/
getTempNight: IExt<ITemp>;
/**
* get comfort temperature (Komforttemperatur)
* @param ain
*/
getTempComfort: IExt<ITemp>;
/**
* ------------------------------------------------
*/
/**
* Not yet tested - deactivated for now
*/
/**
* activate boost with end time or deactivate boost
* @param ain
* @param endtime
*/
setHkrBoost(ain: string, endtime: number): Promise<number>;
/**
* activate window open with end time or deactivate boost
* @param ain
* @param endtime
*/
setHkrWindowOpen(ain: string, endtime: number): Promise<void>;
/**
* activate window open with end time or deactivate boost
* @param deviceId
* @param offset
*/
setHkrOffset(deviceId: string, offset: number): Promise<number>;
/**
* ------------------------------------------------
*/
/**
* get a list of all button devices
*/
getButtonList: IBase<string[]>;
/**
* get a list of all bulbs
*/
getBulbList: IBase<string[]>;
/**
* get a list of bulbs which support colors
*/
getColorBulbList: IBase<string[]>;
/**
* switch the device on, of or toggle its current state
* @param ain
* @param state
*/
setSimpleOnOff(ain: string, state: IState): Promise<IState>;
/**
* Dimm the device, allowed values are 0 - 255
* @param ain
* @param level
*/
setLevel(ain: string, level: number): Promise<number>;
/**
* Dimm the device, allowed values are 0 - 100
* @param ain
* @param levelInPercent
*/
setLevelPercentage(ain: string, levelInPercent: number): Promise<number>;
/**
* Set the color and saturation of a color bulb
* Valid color values are:
* red, orange, yellow, lime, green, turquoise, cyan,
* lightblue, blue, purple, magenta and pink
* Valid satindex values are: 0, 1 or 2
* @param ain
* @param color
* @param satindex
* @param duration
*/
setColor(ain: string, color: ColorName, satindex: number, duration: number): Promise<ColorName>;
/**
* Set the color temperature of a bulb.
* @param ain
* @param temperature Valid values are 2700, 3000, 3400,3800, 4200, 4700, 5300, 5900 and 6500.
* @param duration
*/
setColorTemperature(ain: string, temperature: number, duration: number): Promise<6500 | 5900 | 5300 | 4700 | 4200 | 3800 | 3400 | 3000 | 2700>;
setBlind(ain: string, blindState: string | number): Promise<string | number>;
/**
* get battery charge
* Attention: this function queries the whole device list to get the value for one device.
* If multiple device will be queried for the battery status, a better approach would be to
* get the device list once and then filter out the devices of interest.
* @param ain
*/
getBatteryCharge: IExt<unknown | null>;
/**
* Get the window open flag of a thermostat
* Attention: this function queries the whole device list to get the value for one device.
* If multiple device will be queried for the window open status, a better approach would
* be to get the device list once and then filter out the devices of interest.
* @param ain
*/
getWindowOpen: IExt<boolean>;
parseGuestWlanHTML(html: string): void;
getGuestWlan(): Promise<any>;
setGuestWlan(enable: boolean): Promise<void>;
/**
* get phone devices
*/
getPhoneList(): Promise<unknown>;
}