bblacey / ezlo-hub-kit

SDK for Ezlo Innovation's Home Automation Hubs/Controllers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hub.devices('Name of device') Not returning all items, and too many devices

csinatsch opened this issue · comments

Hello! Thanks for everything you've provided with this kit :). I've been trying to implement it into a project and noticed that the code sample for "Dim the foyer lamp by 50%" Doesn't seem to work properly. I did some further digging and noticed that hub.devices('Name of Device') does not return just the items for a specific device.

When I run:
let device = hub.devices('Test Bench Light');
console.log(await device)
The output I get is:

[
  {
    _id: '5fcf935e120b951747d3639b',
    deviceId: '5fcf935e120b951747d3639a',
    hasGetter: true,
    hasSetter: true,
    name: 'switch',
    show: true,
    value: false,
    valueFormatted: 'false',
    valueType: 'bool'
  },
  {
    _id: '5fcf9c70120b951747d363a2',
    deviceId: '5fcf9c70120b951747d363a0',
    hasGetter: true,
    hasSetter: true,
    name: 'switch',
    show: true,
    value: false,
    valueFormatted: 'false',
    valueType: 'bool'
  },
  {
    _id: '601598ca120b951237a15270',
    deviceId: '601598ca120b951237a1526c',
    hasGetter: true,
    hasSetter: true,
    name: 'switch',
    show: true,
    value: false,
    valueFormatted: 'false',
    valueType: 'bool'
  }
]
[
  {
    _id: '5fcf935e120b951747d3639a',
    batteryPowered: false,
    category: 'dimmable_light',
    deviceTypeId: 'sengled_E11-G13',
    gatewayId: '5fcf8ffb120b951747d36399',
    info: { manufacturer: 'sengled', model: 'E11-G13' },
    name: 'Zigbee Light 1',
    parentDeviceId: '',
    persistent: false,
    reachable: false,
    ready: true,
    roomId: '',
    security: 'no',
    status: 'idle',
    subcategory: 'dimmable_bulb',
    type: 'device'
  },
  {
    _id: '5fcf9c70120b951747d363a0',
    batteryPowered: false,
    category: 'dimmable_light',
    deviceTypeId: 'sengled_E11-G13',
    gatewayId: '5fcf8ffb120b951747d36399',
    info: { manufacturer: 'sengled', model: 'E11-G13' },
    name: 'Test Bench Light',
    parentDeviceId: '',
    persistent: false,
    reachable: true,
    ready: true,
    roomId: '',
    security: 'no',
    status: 'idle',
    subcategory: 'dimmable_bulb',
    type: 'device'
  },
  {
    _id: '601598ca120b951237a1526c',
    batteryPowered: false,
    category: 'dimmable_light',
    deviceTypeId: 'ETI_Zigbee CCT Downlight',
    gatewayId: '5fcf8ffb120b951747d36399',
    info: { manufacturer: 'ETI', model: 'Zigbee CCT Downlight' },
    name: 'Zigbee Downlight',
    parentDeviceId: '',
    persistent: false,
    reachable: false,
    ready: true,
    roomId: '60131307120b9516a145b165',
    security: 'no',
    status: 'idle',
    subcategory: 'dimmable_colored',
    type: 'device'
  }
]

It found all the switch items for all my devices, but not the dimmer items which the online Ezlo api tester is able to find. It also lists all devices instead of just the "Test Bench Light"

This is running in a nodejs project.
Thank you!
-Christian

Hi Cristian,

I'm glad you are finding the kit useful and that you are integrating it into a project. I'm not quite sure why you are seeing those results. The code is pretty straightforward and matches on the exact device name that must be unique.

Which ezlo hardware and firmware version are you using on your hub?

It would also be useful if you use the ezlo api tool to query the hub devices and post them in this issue - please use GitHub/Markdown code formatting to improve legibility (as an example, I updated your original comment to use code-formatting).

I now see the problem. If you look at the docs, they mention "Consistent Hub Property accessor pattern". Plural property accessor patterns return the property collection where the singular form returns the individual property. So in your case, you are calling devices() instead of device(name: <id>).

Just change your call to device('Test Bench Light') and you should be good. So you want to do something like the following:

let device = await hub.device('Test Bench Light')
console.log(device)

Note, in the above code, the api is 'hub.device', not 'hub.devices'

Ahhh I see now,
that worked, Thanks!
-Christian