refactor: improve device control and listing tool error handling and filtering

- Enhance error handling in control tool with more specific domain validation
- Modify list devices tool to use direct filtering instead of manual iteration
- Add more descriptive success messages for different device domains and services
- Simplify device state filtering logic in list devices tool
This commit is contained in:
jango-blockchained
2025-02-05 09:37:20 +01:00
parent 7e7f83e985
commit 8f8e3bd85e
2 changed files with 22 additions and 22 deletions

View File

@@ -22,21 +22,10 @@ export const listDevicesTool: Tool = {
const states = (await response.json()) as HassState[];
const devices: Record<string, HassState[]> = {
light: [],
climate: []
light: states.filter(state => state.entity_id.startsWith('light.')),
climate: states.filter(state => state.entity_id.startsWith('climate.'))
};
// Group devices by domain with specific order
states.forEach((state) => {
const [domain] = state.entity_id.split(".");
// Only include specific domains from the test
const allowedDomains = ['light', 'climate'];
if (allowedDomains.includes(domain)) {
devices[domain].push(state);
}
});
return {
success: true,
devices,