Skip to content
faustyn-p edited this page Aug 30, 2020 · 1 revision

Interface file: 'yeelight-service/lib/yeelight.interface'

Example (log to console after changing power state failed):

import { YeelightService } from 'yeelight-service';
import {
    IYeelight,
    IYeelightDevice,
    IYeelightMethodResponse,
    YeelightMethodStatusEnum
} from 'yeelight-service/lib/yeelight.interface';

const yeelightService: IYeelight = new YeelightService();
yeelightService.getDeviceByModel('lamp1').subscribe((device: IYeelightDevice) => {
    device.setPower('on').then((result: IYeelightMethodResponse) => {
        if (result.status === YeelightMethodStatusEnum.OK) {
            return;
        }

        if (result.errorMessage) {
            console.log(result.errorMessage);
            return;
        }

        console.log(`Unexpected error occured. Error code: ${ result.status }`);
    });
});