moifort / homebridge-mi-led-desk-lamp

Mi led Desk Lamp Homebridge
11 stars 7 forks source link

device.brightness is not a function #9

Open Jasonsey opened 3 years ago

Jasonsey commented 3 years ago

I have installed this package successfully. but after add the config. I got the following error

the error message is here:

Error getting brightness TypeError: device.brightness is not a function
    at MiLedDesklamp.getBrightness (/usr/lib/node_modules/homebridge-mi-led-desk-lamp/index.js:92:45)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Taradooddle commented 2 years ago

I was getting a similar error:

Error getting state TypeError: device.power is not a function
    at MiLedDesklamp.getState (/usr/lib/node_modules/homebridge-mi-led-desk-lamp/index.js:68:40)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Error getting brightness TypeError: device.color is not a function
    at MiLedDesklamp.getColorTemperature (/usr/lib/node_modules/homebridge-mi-led-desk-lamp/index.js:115:40)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Error getting brightness TypeError: device.brightness is not a function
    at MiLedDesklamp.getBrightness (/usr/lib/node_modules/homebridge-mi-led-desk-lamp/index.js:92:45)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Looking into it, it appears the miio library hasn't been updated to account for the right device identifier (in my case, "yeelink.light.lamp22"). As a result, I assume the library recognizes it as some sort of generic device, rather than as specifically being a "light" device that has the associated functions this plugin uses (i.e., power, color, and brightness).

The solution was to add a line to miio/lib/models.js after "yeelink.light.mono1" that specifies that the identifier "yeelink.light.lamp22" is a YeelightMono device:

/usr/lib/node_modules/homebridge-mi-led-desk-lamp/node_modules/miio/lib/models.js:
@@ -52,6 +52,7 @@
    'yeelink.light.lamp1': YeelightMono,
    'yeelink.light.mono1': YeelightMono,
 +  'yeelink.light.lamp22': YeelightMono,
    'yeelink.light.color1': YeelightColor,
    'yeelink.light.strip1': YeelightColor,