Skip to content

Commit

Permalink
Update exposes.js
Browse files Browse the repository at this point in the history
Fix Philips 'hold_release' issue.
  • Loading branch information
asgothian committed Jan 2, 2025
1 parent 7b78589 commit fe30441
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions lib/exposes.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,12 +681,15 @@ function createFromExposes(model, def) {
if (!Array.isArray(expose.values)) break;
const hasHold = expose.values.find((actionName) => actionName.includes('hold'));
const hasRelease = expose.values.find((actionName) => actionName.includes('release'));
const hasPress = expose.values.find((actionName) => actionName.includes('press'));
const hasPressRelease = expose.values.find((actionName) => actionName.includes('press_release'));
for (const actionName of expose.values) {
// is release state ? - skip
if (hasHold && hasRelease && actionName.includes('release')) continue;
// is hold state ?
if (hasHold && hasRelease && actionName.includes('hold')) {
const releaseActionName = actionName.replace('hold', 'release');
const releaseActionName2 = actionName.concat('_release');
state = {
id: actionName.replace(/\*/g, ''),
prop: 'action',
Expand All @@ -696,10 +699,25 @@ function createFromExposes(model, def) {
write: false,
read: true,
type: 'boolean',
getter: payload => payload.action === actionName ? true : (payload.action === releaseActionName ? false : undefined),
getter: payload => payload.action === actionName ? true : (payload.action === releaseActionName || payload.action === releaseActionName2 ? false : undefined),
};
} else if (hasPress && hasPressRelease && actionName.includes('press')) {
let getterKey = actionName.concat('_release');

Check failure on line 705 in lib/exposes.js

View workflow job for this annotation

GitHub Actions / check-and-lint

Expected indentation of 32 spaces but found 8 tabs
if (expose.values.indexOf(getterKey) < 0) getterKey = actionName;
state = {

Check failure on line 707 in lib/exposes.js

View workflow job for this annotation

GitHub Actions / check-and-lint

Expected indentation of 32 spaces but found 8 tabs
id: actionName.replace(/\*/g, ''),
prop: 'action',
name: actionName,
icon: undefined,
role: 'button',
write: false,
read: true,
type: 'boolean',
getter: payload => payload.action === getterKey ? true : undefined,
isEvent: true,
};
} else {
state = {
state = {
id: actionName.replace(/\*/g, ''),
prop: 'action',
name: actionName,
Expand All @@ -710,8 +728,8 @@ function createFromExposes(model, def) {
type: 'boolean',
getter: payload => payload.action === actionName ? true : undefined,
isEvent: true,
};
}
};

Check failure on line 731 in lib/exposes.js

View workflow job for this annotation

GitHub Actions / check-and-lint

Expected indentation of 32 spaces but found 8 tabs
};
pushToStates(state, expose.access);
}
state = null;
Expand Down

0 comments on commit fe30441

Please sign in to comment.