samuraitruong / yeelight

The nodeJS client library for controlling yeelight over LAN
https://samuraitruong.github.io/yeelight/
MIT License
53 stars 14 forks source link

TypeScript declarations #7

Closed BobFrankston closed 6 years ago

BobFrankston commented 6 years ago

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.

samuraitruong commented 6 years ago

Hi @BobFrankston ,

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

Thanks

BobFrankston commented 6 years ago

Thank you very much.

I’m in learning mode myself about publishing TS apps.

Bob Frankston

http://frankston.com/ http://Frankston.com

From: Truong Nguyen notifications@github.com Sent: Saturday, October 20, 2018 08:22 To: samuraitruong/yeelight yeelight@noreply.github.com Cc: Bob Frankston Github@bob.ma; Mention mention@noreply.github.com Subject: Re: [samuraitruong/yeelight] TypeScript declarations (#7)

Hi @BobFrankston https://github.com/BobFrankston ,

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

Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/samuraitruong/yeelight/issues/7#issuecomment-431575509 , or mute the thread https://github.com/notifications/unsubscribe-auth/AFPHNN3c3UElcIyt3J0I2DQzevOE9kegks5umxVxgaJpZM4XxbRT . https://github.com/notifications/beacon/AFPHNLrFUOiD3nTFZOyn4lkDpnm3Rz8hks5umxVxgaJpZM4XxbRT.gif

samuraitruong commented 6 years ago

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

BobFrankston commented 6 years ago

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();
BobFrankston commented 6 years ago

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

BobFrankston commented 6 years ago

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

samuraitruong commented 6 years ago

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

BobFrankston commented 6 years ago

Thanks. I have lots of devices including LIFX bulbs. I’m not sure what is responding – perhaps Alexa units. Too bad none of this is self-describing. What’s surprising is that it didn’t find the Yee ones which is strange.

Bob Frankston

http://frankston.com/ http://Frankston.com

From: Truong Nguyen notifications@github.com Sent: Sunday, October 21, 2018 17:38 To: samuraitruong/yeelight yeelight@noreply.github.com Cc: Bob Frankston Github@bob.ma; Mention mention@noreply.github.com Subject: Re: [samuraitruong/yeelight] TypeScript declarations (#7)

hi @BobFrankston https://github.com/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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/samuraitruong/yeelight/issues/7#issuecomment-431706284 , or mute the thread https://github.com/notifications/unsubscribe-auth/AFPHNO30Uc2Zp4uM9ERJzFAwlIO1pMPrks5unOkcgaJpZM4XxbRT . https://github.com/notifications/beacon/AFPHNHa7q7hu8GPY9ZC5Lbtvck4Udq1Iks5unOkcgaJpZM4XxbRT.gif

samuraitruong commented 6 years ago

Have you try to reset you yeelight . I got similar issue and it work after reset


From: Bob Frankston notifications@github.com Sent: Monday, October 22, 2018 9:38 AM To: samuraitruong/yeelight Cc: Truong Nguyen; State change Subject: Re: [samuraitruong/yeelight] TypeScript declarations (#7)

Thanks. I have lots of devices including LIFX bulbs. I’m not sure what is responding – perhaps Alexa units. Too bad none of this is self-describing. What’s surprising is that it didn’t find the Yee ones which is strange.

Bob Frankston

http://frankston.com/ http://Frankston.com

From: Truong Nguyen notifications@github.com Sent: Sunday, October 21, 2018 17:38 To: samuraitruong/yeelight yeelight@noreply.github.com Cc: Bob Frankston Github@bob.ma; Mention mention@noreply.github.com Subject: Re: [samuraitruong/yeelight] TypeScript declarations (#7)

hi @BobFrankston https://github.com/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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/samuraitruong/yeelight/issues/7#issuecomment-431706284 , or mute the thread https://github.com/notifications/unsubscribe-auth/AFPHNO30Uc2Zp4uM9ERJzFAwlIO1pMPrks5unOkcgaJpZM4XxbRT . https://github.com/notifications/beacon/AFPHNHa7q7hu8GPY9ZC5Lbtvck4Udq1Iks5unOkcgaJpZM4XxbRT.gif

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/samuraitruong/yeelight/issues/7#issuecomment-431710366, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABINopmBOFB7qCdgpI4Zw7MpL_nyIk1Yks5unPdugaJpZM4XxbRT.

BobFrankston commented 6 years ago

Reset the strip and now it’s finding both the bulb (not reset) and the strip. Strange. So the next question is how to tell if the discovered device is a Yee or not. I presume it’s simple.

Bob Frankston

http://frankston.com/ http://Frankston.com

From: Truong Nguyen notifications@github.com Sent: Sunday, October 21, 2018 18:44 To: samuraitruong/yeelight yeelight@noreply.github.com Cc: Bob Frankston Github@bob.ma; Mention mention@noreply.github.com Subject: Re: [samuraitruong/yeelight] TypeScript declarations (#7)

Have you try to reset you yeelight . I got similar issue and it work after reset


From: Bob Frankston <notifications@github.com mailto:notifications@github.com > Sent: Monday, October 22, 2018 9:38 AM To: samuraitruong/yeelight Cc: Truong Nguyen; State change Subject: Re: [samuraitruong/yeelight] TypeScript declarations (#7)

Thanks. I have lots of devices including LIFX bulbs. I’m not sure what is responding – perhaps Alexa units. Too bad none of this is self-describing. What’s surprising is that it didn’t find the Yee ones which is strange.

Bob Frankston

http://frankston.com/ http://Frankston.com

From: Truong Nguyen <notifications@github.com mailto:notifications@github.com > Sent: Sunday, October 21, 2018 17:38 To: samuraitruong/yeelight <yeelight@noreply.github.com mailto:yeelight@noreply.github.com > Cc: Bob Frankston <Github@bob.ma mailto:Github@bob.ma >; Mention <mention@noreply.github.com mailto:mention@noreply.github.com > Subject: Re: [samuraitruong/yeelight] TypeScript declarations (#7)

hi @BobFrankston https://github.com/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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/samuraitruong/yeelight/issues/7#issuecomment-431706284 , or mute the thread https://github.com/notifications/unsubscribe-auth/AFPHNO30Uc2Zp4uM9ERJzFAwlIO1pMPrks5unOkcgaJpZM4XxbRT . https://github.com/notifications/beacon/AFPHNHa7q7hu8GPY9ZC5Lbtvck4Udq1Iks5unOkcgaJpZM4XxbRT.gif

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/samuraitruong/yeelight/issues/7#issuecomment-431710366, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABINopmBOFB7qCdgpI4Zw7MpL_nyIk1Yks5unPdugaJpZM4XxbRT.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/samuraitruong/yeelight/issues/7#issuecomment-431710648 , or mute the thread https://github.com/notifications/unsubscribe-auth/AFPHNGUpN56JD-ufmCnmde0O0lyUWUNhks5unPiTgaJpZM4XxbRT . https://github.com/notifications/beacon/AFPHNB2Z8PhVQAPGKNwurqEPusa90Cvtks5unPiTgaJpZM4XxbRT.gif

samuraitruong commented 6 years ago

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

BobFrankston commented 6 years ago

Did npm update but still discovering too much.

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

samuraitruong commented 6 years ago

I will update the code to filter out the yeelight only

ATM, you can check the port of device if it is 55443, that is yeelight device

on('deviceAdded', (device) => {

if(device.port === 55443) {................

} );


From: Bob Frankston notifications@github.com Sent: Monday, October 22, 2018 9:58 AM To: samuraitruong/yeelight Cc: Truong Nguyen; State change Subject: Re: [samuraitruong/yeelight] TypeScript declarations (#7)

Reset the strip and now it’s finding both the bulb (not reset) and the strip. Strange. So the next question is how to tell if the discovered device is a Yee or not. I presume it’s simple.

Bob Frankston

http://frankston.com/ http://Frankston.com

From: Truong Nguyen notifications@github.com Sent: Sunday, October 21, 2018 18:44 To: samuraitruong/yeelight yeelight@noreply.github.com Cc: Bob Frankston Github@bob.ma; Mention mention@noreply.github.com Subject: Re: [samuraitruong/yeelight] TypeScript declarations (#7)

Have you try to reset you yeelight . I got similar issue and it work after reset


From: Bob Frankston <notifications@github.com mailto:notifications@github.com > Sent: Monday, October 22, 2018 9:38 AM To: samuraitruong/yeelight Cc: Truong Nguyen; State change Subject: Re: [samuraitruong/yeelight] TypeScript declarations (#7)

Thanks. I have lots of devices including LIFX bulbs. I’m not sure what is responding – perhaps Alexa units. Too bad none of this is self-describing. What’s surprising is that it didn’t find the Yee ones which is strange.

Bob Frankston

http://frankston.com/ http://Frankston.com

From: Truong Nguyen <notifications@github.com mailto:notifications@github.com > Sent: Sunday, October 21, 2018 17:38 To: samuraitruong/yeelight <yeelight@noreply.github.com mailto:yeelight@noreply.github.com > Cc: Bob Frankston <Github@bob.ma mailto:Github@bob.ma >; Mention <mention@noreply.github.com mailto:mention@noreply.github.com > Subject: Re: [samuraitruong/yeelight] TypeScript declarations (#7)

hi @BobFrankston https://github.com/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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/samuraitruong/yeelight/issues/7#issuecomment-431706284 , or mute the thread https://github.com/notifications/unsubscribe-auth/AFPHNO30Uc2Zp4uM9ERJzFAwlIO1pMPrks5unOkcgaJpZM4XxbRT . https://github.com/notifications/beacon/AFPHNHa7q7hu8GPY9ZC5Lbtvck4Udq1Iks5unOkcgaJpZM4XxbRT.gif

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/samuraitruong/yeelight/issues/7#issuecomment-431710366, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABINopmBOFB7qCdgpI4Zw7MpL_nyIk1Yks5unPdugaJpZM4XxbRT.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/samuraitruong/yeelight/issues/7#issuecomment-431710648 , or mute the thread https://github.com/notifications/unsubscribe-auth/AFPHNGUpN56JD-ufmCnmde0O0lyUWUNhks5unPiTgaJpZM4XxbRT . https://github.com/notifications/beacon/AFPHNB2Z8PhVQAPGKNwurqEPusa90Cvtks5unPiTgaJpZM4XxbRT.gif

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/samuraitruong/yeelight/issues/7#issuecomment-431711602, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABINopg4OUDRdKMqQ7SLzIHKMWM6Subhks5unPwWgaJpZM4XxbRT.

BobFrankston commented 6 years ago

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.

samuraitruong commented 6 years ago

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

BobFrankston commented 6 years ago

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.

samuraitruong commented 6 years ago

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

Cheers

BobFrankston commented 6 years ago
    "yeelight-awesome": "^1.0.11"

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