maxinminax / node-mihome

Control Mi Home devices, such as Mi Robot Vacuums, Mi Air Purifiers, Mi Smart Home Gateway (Aqara) and more
MIT License
121 stars 34 forks source link

Use group generic device for unsupported device models #8

Closed 0x2206 closed 3 years ago

0x2206 commented 4 years ago

Currently, when you try to use unsupported model, so file with precisely the same name is not found in /lib/devices/, it raises error. How about being less restrictive and fall back to (more generic) device group then?

As an example, I want to communicate with (currently unsupported) Mi Air Purifier Pro (model: zhimi.airpurifier.v6), which has the same props to get and set as (currently supported) model: zhimi.airpurifier.v7. I propose to have more generic, virtual model like zhimi.airpurifier which is used in such situations.

In fact, that more generic model will be based on simpler air purifier, as:

  1. pro models have two motors, while more basic units have one,
  2. older units do not read RFID on filters so do not return filter type,
  3. etc.

but that is implementation detail.

maxinminax commented 4 years ago

For unsupported devices, you can made a new class same as the device class which you can find in /lib/devices. So if you have other models and can test, you can made the PR, I will merge it asap

0x2206 commented 4 years ago

Yes, adding lacking device implementation is exactly what I did with my fork. As for now locally.

What I mean is, imagine there is another device like vacuum cleaner released to the market next week. I am pretty sure most props and actions would be the same as for current vacuums. But that new vacuum won't work until someone adds new class to /lib/devices/. What I propose is to have a fallback in such situations. Consumers of this lib would use fallback implementation until dedicated one is added. What do you think?

maxinminax commented 3 years ago

Anyone can implement the Device class to create new model

const Device = require('node-miio/device-miio');
class GenericDevice extends Device {
  // example class can find in folder /lib/devices
}
const device = new GenericDevice(options);
// use device as normal