dvcrn / cocoro-sdk

Unofficial TypeScript SDK for the SHARP Cocoro API
6 stars 1 forks source link

add air purifier #3

Closed shossk closed 2 years ago

shossk commented 2 years ago

Closes #2

dvcrn commented 2 years ago

Looking good! I just don't have a way to test it here. I assume you tried all of these settings with your purifier, right?

shossk commented 2 years ago

Looking good! I just don't have a way to test it here. I assume you tried all of these settings with your purifier, right?

Yes! The air purifier in my house is working just fine because of this!

dvcrn commented 2 years ago

For the public interface of this sdk, we're currently getting devices like this:

const devices = await cocoro.queryDevices();
const device = devices[0];

Is it doable to automatically deduct when a device is a purifier or aircon?

Maybe we could add a separate type field for each one

console.log(device.kind); // => Device.Purifier | Device.Aircon
shossk commented 2 years ago

Do you mean you are looking for a property that can distinguish between an air purifier and an air conditioner?

There is a deviceType as part of the boxinfo, and it looks like you're only looking at part of the boxinfo right now.

I'm sorry if I'm wrong...

{
  "box": [
    {
      "echonetData": [
        {
          "labelData": {
            "deviceType": "AIR_CLEANER"
          }
        }
      ]
    }
  ]
}
dvcrn commented 2 years ago

Ah perfect. Okay can you do one last change? Then we can merge this 👍

In the constructor to device, can you add a new property forkind? https://github.com/dvcrn/cocoro-sdk/blob/master/src/cocoro.ts#L122-L134 If deviceType == 'AIR_CLEANER', set it to a new enum type Device.AirCleaner

shossk commented 2 years ago

I've finished adding them!

Added an OR condition for the devices array, remove it if it is not needed. I'm not sure if it's because I added the OR condition, but the completion doesn't work anymore. I can see the devices, but the Purifier completion does not work. Do you have any idea why?

dvcrn commented 2 years ago

Thanks! Looks good enough to me. I'll fix that on my end!

Thanks a lot for taking the time to add support for this! It's been very helpful!

dvcrn commented 2 years ago

@shossk I've created a separate PR to cleanup some of the code and make things more generic. Can you give it a try to see if your device still works? https://github.com/dvcrn/cocoro-sdk/pull/4

Regarding autocomplete, you need to type-assert the device as Purifier, so (device as Purifier)

shossk commented 2 years ago

@dvcrn Thanks for the cleanups, they work perfectly!