samuraitruong/yeelight

TypeScript declarations

BobFrankston opened this issue · 18 comments

Great package.

The yeelight-awesome sample worked fine in JavaScript but when I used TypeScript syntax

import {Discover, IDevice} from 'yeelight-awesome';

I'm told there is no declaration file.
image

I very much appreciate that the package is in TypeScript so I presume there is a simple npm install issue.

BTW, the instructions tell me I need to put the bulb into LAN mode. I didn't find the setting but, fortunately, it jus worked anyway. Maybe the app has been updated.

Hi @BobFrankston ,

Yes, I know that issue, I need to create the typescript module file. I will do it within next week

Thanks

HHi @BobFrankston ,

#8 Will fix this, I just add a quick declaration file, I will enhance it later with more document

Please test and lets me know it works for you, Then we can close this issue. Thanks

Make sure you are on version 1.0.10

The good news is that the definition worked. I redid the TS app based on the JS example. The bad news is that this time it discovered a number of devices but not the Yeelight. The devices it discovered were marked as "Amazon" so Yeelight and Amazon may be responding to the same SSDP query.

When I did use an explicit address I got ECONNREFUSED.

So I tried scanByIp (note that the range of addresses can be >255). But it made no difference -- it still did a full scan. (Another note - a lot of uncaught promises).

Note that the JavaScript version worked yesterday, so I don't know why the change in behavior.

In case it helps this is my test app. Notice that I wired in the address of my bulb (found using Unifi) and commented out various tests scenarios.

import { Discover, IDevice, IDiscoverConfig, Yeelight, Color as ylColor } from 'yeelight-awesome';
// https://www.npmjs.com/package/yeelight-awesome

const discover = new Discover({ port: 1982, debug: true });

function log(msg: string) {
    const dt = new Date();
    console.log(`${dt.toLocaleTimeString()} ${dt.getMilliseconds().toString().padStart(3)} ${msg}`)
}

function tester() {
    try {
        discover.on('deviceAdded', device => {
            log(`Device ${JSON.stringify(device)} found`);
            if (!device.host.endsWith(".44")) return;   // Not Yeelight
            const yeelight = new Yeelight({ lightIp: device.host, lightPort: device.port });
            yeelight.on('connected', () => {
                log(`Light ${device.host} connected`)
                yeelight.setRGB(new ylColor(0xff, 0x80, 0x00), "sudden", 0);
                // setInterval(() => yeelight.toggle(), 5000);
            });
            yeelight.connect();
        })
        log(`Starting discovery`);
        discover.start();
        // discover.scanByIp(44,44);

        // const yx = new Yeelight({lightIp: "192.55.226.44", lightPort: 55443});
        // yx.on('connected', () => {
        //     yx.setRGB(new ylColor(0xff, 0x80, 0x00), "sudden", 0);
        //     // setInterval(() => yeelight.toggle(), 5000);
        // });
        // yx.connect();

    }
    catch (e) {
        console.error(`Yee ${e}`);
    }
}

tester();

Just noticed (in another app) how to enable access
image

I can now control the light by explicitly creating rather than discovery.

hi @BobFrankston ,

SSDP only search for wifi_blub, If amazon device response to that search command too then it may error.

What type of device you have on network?

I will fix this issue tonight, Basically, I just check if the location start with yeelight

Thanks again for report the issue

I just push the change, now it will correct the SSDP discover. deviceAdded event only emit when the device is Yeelight

Did npm update but still discovering too much.

I'm also interested in notification messages. It doesn' seem they are implemented.

Alas, they are all reporting 55443.

This is what I know so far

192.55.226.108:55443  84-d6-d0-07-d6-09 Amazon
192.55.226.027:55443  b0-fc-0d-79-83-90 Amazon
192.55.226.064:55443  18-74-2e-5a-80-79 Amazon
192.55.226.065:55443  00-fc-8b-0a-38-86 Amazon
192.55.226.016:55443  fc-a1-83-20-14-b0 Amazon
192.55.226.054:55443  fc-a1-83-32-e9-e1 Amazon
192.55.226.244:55443  78-11-dc-69-0c-59 XIAOMI (Yee strip)
192.55.226.044        7c-49-eb-ac-cb-5f XIAOMI (Yee bulb -- not discovered this time)

https://linuxnet.ca/ieee/oui/nmap-mac-prefixes has prefixes, Xiaomei is spelled Xiami

Still trying to figure out which device but the Fire and Echo devices don't show their IP address.

Hi, 55443 is yeelight or any xiaomi device. Update code to v1.0.11 it will fix non yeelight device to be discovered

55443 isn't reserved and, unfortunately, Amazon seems to use it too

https://community.bt.com/t5/Home-setup-Wi-Fi-network/Amazon-Echo-Echo-Show-Problems/td-p/1863869

I guess I can treat timeout as an indication it's not a Yeelight. One problem is that when that happens I get uncaught promises while will become fatal in Node. Also it's good to create an Error object rather than throwing a string on an error.

hi @BobFrankston , Please update to v 1.0.11 it will not detect the amazon echo as yeelight anymore.

Cheers

    "yeelight-awesome": "^1.0.11"

I can just work around not so not a big issue at this point.