Skip to content

Commit

Permalink
Scene: In device.set-value, convert string to number (#2013)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles authored Jan 29, 2024
1 parent a428cd5 commit d87cabc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server/lib/scene/scene.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ const actionsFunc = {
throw new AbortScene('ACTION_VALUE_NOT_A_NUMBER');
}

return self.device.setValue(device, deviceFeature, value);
const valueInNumber = Number(value);

return self.device.setValue(device, deviceFeature, valueInNumber);
},
[ACTIONS.LIGHT.TURN_ON]: async (self, action, scope) => {
await Promise.map(action.devices, async (deviceSelector) => {
Expand Down
39 changes: 39 additions & 0 deletions server/test/lib/scene/scene.executeActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,45 @@ describe('scene.executeActions', () => {
11,
);
});
it('should execute action device.setValue with string', async () => {
const example = {
stop: fake.resolves(null),
};

stateManager.setState('service', 'example', example);
stateManager.setState('deviceFeature', 'my-device-feature', {
device_id: 'device-id',
});
stateManager.setState('deviceById', 'device-id', {
id: 'device-id',
features: [],
});
const device = {
setValue: fake.resolves(null),
};
await executeActions(
{ stateManager, event, device },
[
[
{
type: ACTIONS.DEVICE.SET_VALUE,
device_feature: 'my-device-feature',
value: '11',
},
],
],
{},
);
assert.calledWith(
device.setValue,
{
id: 'device-id',
features: [],
},
{ device_id: 'device-id' },
11,
);
});
it('should execute action device.setValue', async () => {
const example = {
stop: fake.resolves(null),
Expand Down

0 comments on commit d87cabc

Please sign in to comment.