Digital-Alchemy-TS / hass

Typescript APIs for Home Assistant. Includes rest & websocket bindings
https://docs.digital-alchemy.app
MIT License
8 stars 2 forks source link

Areas and Floors should also search through devices, not just direct entities #62

Closed allout58 closed 2 months ago

allout58 commented 2 months ago

🪤 Context

I would to be able to find all my entities in an area or floor. All of my entities are added through their devices, not directly

📬 Caveats

I don't foresee any issues with this, I'm not sure you would ever want to exclude the devices while keeping just the directly attached entities.

🩻 Additional details

Sample code:

  const areas = await hass.area.list();
  for (const ar of areas) {
    const lights = hass.refBy.area(ar.area_id);
    logger.info(`Area ${ar.name}::${ar.area_id}: ` + JSON.stringify(lights.map(it => it.entity_id)));
  }

  const floors = await hass.floor.list();
  for (const ar of floors) {
    const lights = hass.refBy.floor(ar.floor_id);
    logger.info(`Floor ${ar.name}::${ar.floor_id}: ` + JSON.stringify(lights.map(it => it.entity_id)));
  }
zoe-codez commented 2 months ago

hass.idBy.area now considers entities attached to devices registered to the area, which have not had their areas overridden. This affected methods:

type-writer will automatically pick up on the updates next rebuild