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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user