Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alexa integration should not return read_only devices #1539

Merged
merged 1 commit into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/services/alexa/lib/alexa.onReportState.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function onReportState(body) {
device.features.forEach((feature) => {
const func = get(readValues, `${feature.category}.${feature.type}`);
const mapping = get(mappings, `${feature.category}.capabilities.${feature.type}`);
if (func && mapping) {
if (func && mapping && feature.read_only === false) {
properties.push({
namespace: mapping.interface,
name: get(mapping, 'properties.supported.0.name'),
Expand Down
11 changes: 7 additions & 4 deletions server/services/alexa/lib/syncDeviceConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ function syncDeviceConverter(device) {
if (displayCategory && endpoint.displayCategories.indexOf(displayCategory) === -1) {
endpoint.displayCategories.push(displayCategory);
}
// we get the capability if handled
const capability = get(mappings, `${value.category}.capabilities.${value.type}`);
if (capability) {
endpoint.capabilities.push(capability);
// read only devices are not returned
if (value.read_only === false) {
// we get the capability if handled
const capability = get(mappings, `${value.category}.capabilities.${value.type}`);
if (capability) {
endpoint.capabilities.push(capability);
}
}
});

Expand Down
40 changes: 40 additions & 0 deletions server/test/services/alexa/lib/alexa.onDiscovery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('alexa.onDiscovery', () => {
external_id: 'device-1-external-id',
features: [
{
read_only: false,
category: 'light',
type: 'binary',
},
Expand Down Expand Up @@ -77,4 +78,43 @@ describe('alexa.onDiscovery', () => {
expect(result).to.deep.eq(expectedResult);
assert.calledOnce(gladys.stateManager.state.device.device_1.get);
});
it('return not return read_only devices', async () => {
gladys.stateManager.state.device = {
device_1: {
get: fake.returns({
name: 'Device 1',
selector: 'device-1',
external_id: 'device-1-external-id',
features: [
{
read_only: true,
category: 'light',
type: 'binary',
},
],
model: 'device-model',
room: {
name: 'living-room',
},
}),
},
};

const alexaHandler = new AlexaHandler(gladys, serviceId);
const result = alexaHandler.onDiscovery();
const expectedResult = {
event: {
header: {
namespace: 'Alexa.Discovery',
name: 'Discover.Response',
payloadVersion: '3',
messageId: get(result, 'event.header.messageId'),
},
payload: {
endpoints: [],
},
},
};
expect(result).to.deep.eq(expectedResult);
});
});
6 changes: 6 additions & 0 deletions server/test/services/alexa/lib/alexa.onExecute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ const DEVICE_1_LIGHT = {
external_id: 'device-1-external-id',
features: [
{
read_only: false,
category: 'light',
type: 'brightness',
},
{
read_only: false,
category: 'light',
type: 'binary',
},
Expand All @@ -34,6 +36,7 @@ const DEVICE_1_SWITCH = {
external_id: 'device-1-external-id',
features: [
{
read_only: false,
category: 'switch',
type: 'binary',
},
Expand Down Expand Up @@ -340,6 +343,7 @@ describe('alexa.onExecute', () => {
external_id: 'device-1-external-id',
features: [
{
read_only: false,
category: 'switch',
type: 'binary',
},
Expand Down Expand Up @@ -384,6 +388,7 @@ describe('alexa.onExecute', () => {
stateManager: {
get: () => {
return {
read_only: false,
category: 'light',
type: 'binary',
};
Expand All @@ -397,6 +402,7 @@ describe('alexa.onExecute', () => {
external_id: 'device-1-external-id',
features: [
{
read_only: false,
category: 'light',
type: 'binary',
},
Expand Down
1 change: 1 addition & 0 deletions server/test/services/alexa/lib/alexa.onReportState.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('alexa.onReportState', () => {
external_id: 'device-1-external-id',
features: [
{
read_only: false,
category: 'light',
type: 'binary',
last_value: 1,
Expand Down