Skip to content

Commit

Permalink
Add channel trait
Browse files Browse the repository at this point in the history
  • Loading branch information
atrovato committed Nov 21, 2022
1 parent d5f1588 commit 3b6353e
Showing 1 changed file with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } = require('../../../../utils/constants');

/**
* @see https://developers.google.com/assistant/smarthome/traits/channel
*/
const volumeTrait = {
key: 'action.devices.traits.Channel',
features: [
{
category: DEVICE_FEATURE_CATEGORIES.TELEVISION,
type: DEVICE_FEATURE_TYPES.TELEVISION.CHANNEL,
},
{
category: DEVICE_FEATURE_CATEGORIES.TELEVISION,
type: DEVICE_FEATURE_TYPES.TELEVISION.CHANNEL_UP,
},
{
category: DEVICE_FEATURE_CATEGORIES.TELEVISION,
type: DEVICE_FEATURE_TYPES.TELEVISION.CHANNEL_DOWN,
},
{
category: DEVICE_FEATURE_CATEGORIES.TELEVISION,
type: DEVICE_FEATURE_TYPES.TELEVISION.VOLUME_MUTE,
},
],
generateAttributes: (device) => {
const { has_feedback: hasFeedback = false } = device.features.find(
(feature) =>
feature.category === DEVICE_FEATURE_CATEGORIES.TELEVISION &&
feature.type === DEVICE_FEATURE_TYPES.TELEVISION.CHANNEL,
);

return {
commandOnlyVolume: !hasFeedback,
};
},
states: [],
commands: {
'action.devices.commands.selectChannel': {
mute: {
writeValue: (paramValue) => {
return paramValue ? 1 : 0;
},
getFeatures: () => {
return [
{
category: DEVICE_FEATURE_CATEGORIES.TELEVISION,
type: DEVICE_FEATURE_TYPES.TELEVISION.VOLUME_MUTE,
},
];
},
},
},
'action.devices.commands.setVolume': {
volumeLevel: {
writeValue: (paramValue) => {
return paramValue;
},
getFeatures: () => {
return [
{
category: DEVICE_FEATURE_CATEGORIES.TELEVISION,
type: DEVICE_FEATURE_TYPES.TELEVISION.VOLUME,
},
];
},
},
},
'action.devices.commands.volumeRelative': {
relativeSteps: {
writeValue: () => {
return 1;
},
getFeatures: (paramValue) => {
const feature = {
category: DEVICE_FEATURE_CATEGORIES.TELEVISION,
type: DEVICE_FEATURE_TYPES.TELEVISION.VOLUME_UP,
};
if (paramValue < 0) {
feature.type = DEVICE_FEATURE_TYPES.TELEVISION.VOLUME_DOWN;
}

return Array(Math.abs(paramValue)).fill(feature);
},
},
},
},
};

module.exports = {
volumeTrait,
};

0 comments on commit 3b6353e

Please sign in to comment.