From 9fe48e2a888ad951bf79482cce5b6c4fb8f333e1 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Tue, 3 Jan 2023 10:58:47 +0100 Subject: [PATCH] Revert "Expose cover `moving` state to Home Assistant (#15555)" This reverts commit 56f7f3e1bdb2f4f6266d712884cee026bc32c98d. --- lib/extension/homeassistant.ts | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/lib/extension/homeassistant.ts b/lib/extension/homeassistant.ts index 41713d0f0..7c9dad1ce 100644 --- a/lib/extension/homeassistant.ts +++ b/lib/extension/homeassistant.ts @@ -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', @@ -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} %} ` +