-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix slow opening nodes and other issues with select2
- Loading branch information
Showing
10 changed files
with
228 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { RED } from '../globals'; | ||
import Websocket from '../homeAssistant/Websocket'; | ||
import { | ||
HassAreas, | ||
HassDevices, | ||
HassEntityRegistryEntry, | ||
} from '../types/home-assistant'; | ||
|
||
export function getAreaNameByEntityId( | ||
entityId: string, | ||
areas: HassAreas, | ||
devices: HassDevices, | ||
entities: HassEntityRegistryEntry[] | ||
) { | ||
const areaId = getAreaIdByEntityId(entityId, areas, devices, entities); | ||
return getAreaNameByAreaId(areaId, areas); | ||
} | ||
|
||
function getAreaNameByAreaId(areaId: string | null, areas: HassAreas) { | ||
if (areaId && areas?.length) { | ||
const area = areas.find((a) => a.area_id === areaId); | ||
if (area) { | ||
return area.name; | ||
} | ||
} | ||
|
||
return RED._('ha-device.ui.no_area'); | ||
} | ||
|
||
function getAreaIdByEntityId( | ||
entityId: string, | ||
areas: HassAreas, | ||
devices: HassDevices, | ||
entities: HassEntityRegistryEntry[] | ||
) { | ||
const entity = getEntityById(entityId, entities); | ||
|
||
if (entity?.area_id) { | ||
return entity.area_id; | ||
} | ||
|
||
if (areas?.length) { | ||
const area = areas.find((area) => { | ||
const device = getDeviceByEntityId(entityId, devices, entities); | ||
return device?.area_id === area.area_id; | ||
}); | ||
|
||
if (area) { | ||
return area.area_id; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function getDeviceByEntityId( | ||
entityId: string, | ||
devices: HassDevices, | ||
entities: HassEntityRegistryEntry[] | ||
) { | ||
const entity = getEntityById(entityId, entities); | ||
|
||
if (entity?.device_id && devices?.length) { | ||
const device = devices.find((device) => entity.device_id === device.id); | ||
if (device) { | ||
return device; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function getEntityById( | ||
entityId: string, | ||
entities: HassEntityRegistryEntry[] | ||
): HassEntityRegistryEntry | null { | ||
if (entityId && entities) { | ||
return entities.find((e) => e.entity_id === entityId) ?? null; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
export function getRegistryData(HassWS: Websocket) { | ||
return { | ||
areas: HassWS.getAreas(), | ||
devices: HassWS.getDevices(), | ||
entities: HassWS.getEntities(), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.