Skip to content

Commit

Permalink
Revert "Expose cover moving state to Home Assistant (#15555)"
Browse files Browse the repository at this point in the history
This reverts commit 56f7f3e.
  • Loading branch information
Koenkk committed Jan 6, 2023
1 parent 1c7817a commit 9fe48e2
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions lib/extension/homeassistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ export default class HomeAssistant extends Extension {
const motorState = allExposes?.find((e) => e.type === 'enum' && e.name === 'motor_state' &&
e.access === ACCESS_STATE);
const running = allExposes?.find((e) => e.type === 'binary' && e.name === 'running');
const moving = allExposes?.find((e) => e.type === 'enum' && e.name === 'moving');

const discoveryEntry: DiscoveryEntry = {
type: 'cover',
Expand All @@ -407,38 +406,24 @@ export default class HomeAssistant extends Extension {
},
};

// For curtains that have `motor_state` or `moving` lookup a possible state names and make this
// For curtains that have `motor_state` lookup a possible state names and make this
// available for discovery. If the curtains only support the `running` value,
// then we use it anyway. The movement direction is calculated (assumed) in this case.
if (motorState || moving) {
if (motorState) {
const openingLookup = ['opening', 'open', 'forward', 'up', 'rising'];
const closingLookup = ['closing', 'close', 'backward', 'back', 'reverse', 'down', 'declining'];
const stoppedLookup = ['stopped', 'stop', 'pause', 'paused'];

const movingState = motorState ? motorState : moving;

const openState = state.values.find((s) => openingLookup.includes(s.toLowerCase()));
const closeState = state.values.find((s) => closingLookup.includes(s.toLowerCase()));
const openingState = movingState.values.find((s) => openingLookup.includes(s.toLowerCase()));
const closingState = movingState.values.find((s) => closingLookup.includes(s.toLowerCase()));
const stoppedState = movingState.values.find((s) => stoppedLookup.includes(s.toLowerCase()));
const openingState = motorState.values.find((s) => openingLookup.includes(s.toLowerCase()));
const closingState = motorState.values.find((s) => closingLookup.includes(s.toLowerCase()));
const stoppedState = motorState.values.find((s) => stoppedLookup.includes(s.toLowerCase()));

if (openingState && closingState && stoppedState) {
discoveryEntry.discovery_payload.state_opening = openingState;
discoveryEntry.discovery_payload.state_closing = closingState;
if (openState && closeState) {
discoveryEntry.discovery_payload.state_open = openState;
discoveryEntry.discovery_payload.state_closed = closeState;
discoveryEntry.discovery_payload.value_template =
`{{ value_json.${movingState.property} if value_json.${movingState.property} and` +
` value_json.${movingState.property} != '${stoppedState}' else` +
` value_json.${featurePropertyWithoutEndpoint(state)} }}`;
} else {
discoveryEntry.discovery_payload.state_stopped = stoppedState;
discoveryEntry.discovery_payload.value_template =
`{{ '${stoppedState}' if not value_json.${movingState.property}` +
` else value_json.${movingState.property} }}`;
}
discoveryEntry.discovery_payload.state_stopped = stoppedState;
discoveryEntry.discovery_payload.value_template = `{% if not value_json.${motorState.property} %}` +
` ${stoppedState} {% else %} {{ value_json.${motorState.property} }} {% endif %}`;
}
} else if (running) {
discoveryEntry.discovery_payload.value_template = `{% if not value_json.${running.property} %} ` +
Expand Down

0 comments on commit 9fe48e2

Please sign in to comment.