lpgera / dirigera

An unofficial TypeScript client library for IKEA's DIRIGERA smart home hub
https://www.npmjs.com/package/dirigera
MIT License
47 stars 2 forks source link

HTTPError on air purifier device #8

Closed KiterWork closed 5 months ago

KiterWork commented 5 months ago

Heyo! Back again lol

I just bought an air purifier that should be controllable with dirigera, i have gotten it to turn on and off its statusLight using the setStatusLight function but the setMotorState function as shown in the example code in github is throwing the following error

HTTPError [DirigeraError]: {"error":"Error","message":"\"attributes\" does not match any of the allowed types"}
    at Request.<anonymous> (file:///C:/Users/kiter/Desktop/ikea/node_modules/got/dist/source/as-promise/index.js:86:42)
    at Object.onceWrapper (node:events:633:26)
    at Request.emit (node:events:530:35)
    at Request._onResponseBase (file:///C:/Users/kiter/Desktop/ikea/node_modules/got/dist/source/core/index.js:603:22)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Request._onResponse (file:///C:/Users/kiter/Desktop/ikea/node_modules/got/dist/source/core/index.js:645:13) {
  input: undefined,
  code: 'ERR_NON_2XX_3XX_RESPONSE',

This also gets thrown when i try to use the following code

  await ikeaClient.devices.setAttributes({
            id: `5dba0600-d190-4d28-868d-fb70837b4973_1`,
            attributes: {
                motorState: 100
            },
        })

But im willing to accept that last part as incompetence on my end xd Wouldnt be the first time. Im hoping you have some insight as to why this wouldnt work, or maybe i can be your test by proxy if you need :))

lpgera commented 5 months ago

Hey there! 🙂

There are a couple of device categories which I don't own, including the air purifiers, so I've not tested this part of the library. Which means that there's a good chance that something's off within the library this time. 😄

I'd highly appreciate if you could test the setFanMode and the setChildLock functions as well and report back if you face any issues.

Circling back to the setMotorState problem, I've found a couple of dumps in other repositories which indicate that the input value should be between 0 and 50. Have you tested the function within that range as well?

KiterWork commented 5 months ago

Will test those 2 in the morning! I set motorstate to 10 and 100 I think, but can't say I'm 100% sure. Will set up some tests to check!

KiterWork commented 5 months ago

So yes, the max speed is 50 for the motorState setChildLock and setFanMode seem to work perfectly, no errors at all!

KiterWork commented 5 months ago

And the second i press send on that it errors with

HTTPError [DirigeraError]: {"error":"Error","message":"\"attributes\" does not match any of the allowed types"}
    at Request.<anonymous> (file:///C:/Users/kiter/Desktop/ikea/node_modules/got/dist/source/as-promise/index.js:86:42)
    at Object.onceWrapper (node:events:633:26)
    at Request.emit (node:events:530:35)
    at Request._onResponseBase (file:///C:/Users/kiter/Desktop/ikea/node_modules/got/dist/source/core/index.js:603:22)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Request._onResponse (file:///C:/Users/kiter/Desktop/ikea/node_modules/got/dist/source/core/index.js:645:13) {
  input: undefined,
  code: 'ERR_NON_2XX_3XX_RESPONSE',

In the error it also shows

    body: '[{"attributes":{"fanMode":"manual"}}]',

So just manual doesnt work for setFanMode

lpgera commented 5 months ago

Just to make sure I understand:

Can you check if all of the above is correct? 🙂

If everything's correct, then could you also test if the following fanMode values work?

TypeScript may scream at you because these aren't allowed in the current typings, so just throw a // @ts-ignore above the line for the sake of testing.

KiterWork commented 5 months ago

That is all correct, as well as the list low, medium, high, on and off. I didnt see any change with on, but it also doesnt throw any errors. I turned the fan off using fanMode off, then tried to turn it back on with fanMode: on and that did not turn it back to the setting it was before. Id have to do fanMode: high to get it back to the high state which it was before turning it off

KiterWork commented 5 months ago

The motorState for low is 10, medium is 30 and high is 50. Ill enclose the output of client.airPurifiers.get for my device, incase that helps you at all

{
  id: '5dba0600-d190-4d28-868d-fb70837b4973_1',
  type: 'airPurifier',
  deviceType: 'airPurifier',
  createdAt: '2024-02-01T10:19:24.000Z',
  isReachable: true,
  lastSeen: '2024-02-02T21:18:06.000Z',
  attributes: {
    customName: 'Air purifier',
    firmwareVersion: '1.1.001',
    hardwareVersion: '1',
    manufacturer: 'IKEA of Sweden',
    model: 'STARKVIND Air purifier',
    productCode: 'E2007',
    serialNumber: '84BA20FFFEE29787',
    fanMode: 'low',
    fanModeSequence: 'lowMediumHighAuto',
    motorRuntime: 0,
    motorState: 10,
    filterAlarmStatus: false,
    filterElapsedTime: 1850,
    filterLifetime: 259200,
    childLock: false,
    statusLight: false,
    currentPM25: 9,
    identifyPeriod: 0,
    identifyStarted: '2000-01-01T00:00:00.000Z',
    permittingJoin: false,
    otaPolicy: 'autoUpdate',
    otaProgress: 0,
    otaScheduleEnd: '00:00',
    otaScheduleStart: '00:00',
    otaState: 'readyToCheck',
    otaStatus: 'upToDate'
  },
  capabilities: {
    canSend: [],
    canReceive: [
      'customName',
      'fanMode',
      'fanModeSequence',
      'motorState',
      'childLock',
      'statusLight'
    ]
  },
  room: {
    id: '135aedd3-a385-466a-a5f4-b2d13bfb2e46',
    name: 'Bedroom',
    color: 'ikea_yellow_no_24',
    icon: 'rooms_bed'
  },
  deviceSet: [],
  remoteLinks: [],
  isHidden: false
}
lpgera commented 5 months ago

Awesome, thank you very much for testing everything! I'm going to update the relevant types and docs, and publish a new version of the library soon.

lpgera commented 5 months ago

New typings are available in version 0.15.3 🎉 I'm closing this one.

By the way, if you happen to own a motion sensor or roller blinds with remote controls, then a similar testing with those would be a great contribution to the library!