Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
entities[data.entity_id].attributes.entity_id.map((entity: string) =>
callService(
connection,
entity.split('.')[0],
state ? 'turn_on' : 'turn_off',
{ entity_id: entity }
).then(
() => {},
err => {
console.error('Error calling service:', err);
}
)
);
export function handleChange(
domain: string,
state: string | boolean,
data?: any,
entities?: HassEntities
) {
process.env.NODE_ENV === 'development' &&
console.log('handleChange:', domain, state, data);
if (typeof state === 'string') {
callService(connection, domain, state, data).then(
() => {},
err => {
console.error('Error calling service:', err);
}
);
} else {
if (domain === 'group' && entities) {
entities[data.entity_id].attributes.entity_id.map((entity: string) =>
callService(
connection,
entity.split('.')[0],
state ? 'turn_on' : 'turn_off',
{ entity_id: entity }
).then(
() => {},
err => {
if (domain === 'group' && entities) {
entities[data.entity_id].attributes.entity_id.map((entity: string) =>
callService(
connection,
entity.split('.')[0],
state ? 'turn_on' : 'turn_off',
{ entity_id: entity }
).then(
() => {},
err => {
console.error('Error calling service:', err);
}
)
);
} else
callService(
connection,
domain,
state ? 'turn_on' : 'turn_off',
data
).then(
() => {},
err => {
console.error('Error calling service:', err);
}
);
}
}
console.log('handleChange:', domain, state, data);
if (typeof state === 'string') {
callService(connection, domain, state, data).then(
() => {
this.setState({ snackMessage: { open: true, text: 'Changed.' } });
},
err => {
console.error('Error calling service:', err);
this.setState({
snackMessage: { open: true, text: 'Error calling service' },
entities: undefined
});
}
);
} else {
callService(
connection,
domain,
state ? 'turn_on' : 'turn_off',
data
).then(
() => {
this.setState({ snackMessage: { open: true, text: 'Changed.' } });
},
err => {
console.error('Error calling service:', err);
this.setState({
snackMessage: { open: true, text: 'Error calling service' },
entities: undefined
});
}
);
handleChange = (domain, state, data = undefined) => {
process.env.NODE_ENV === 'development' &&
console.log('handleChange:', domain, state, data);
if (typeof state === 'string') {
callService(connection, domain, state, data).then(
() => {
this.setState({ snackMessage: { open: true, text: 'Changed.' } });
},
err => {
console.error('Error calling service:', err);
this.setState({
snackMessage: { open: true, text: 'Error calling service' },
entities: undefined
});
}
);
} else {
callService(
connection,
domain,
state ? 'turn_on' : 'turn_off',
async callService(domain, service, data) {
const result = homeassistant.callService(
this.client,
domain,
service,
data
);
return result;
}
_callService(domain, service, data = {}) {
data.entity_id = this._entityId;
return HomeAssistant.callService(this.master.connection, domain, service, data);
}