fix: restrict blind direction reversal to 3D appearance

This commit is contained in:
jhartworks committed 2026-11-10 10:31:41 +01:00
1 parent b9a095bc6e
commit 7a9b2c0a38
19 files changed
+721 -629

No files matched your search

+6 -7
View File
@@ -150,24 +150,23 @@ function coverClosed(hass: HomeAssistant, id: string | null | undefined, inverte
const cover = id ? hass.states[id] : undefined;
if (!cover || isUnavailable(cover)) return id ? 0 : null;
const percent = cover.attributes.current_position;
if (typeof percent === "number") { const closed = 1 - Math.min(100, Math.max(0, percent)) / 100; return inverted && !cover.attributes.nf_cover_control ? 1 - closed : closed; }
if (cover.state === "closed") return inverted && !cover.attributes.nf_cover_control ? 0 : 1;
if (cover.state === "open") return inverted && !cover.attributes.nf_cover_control ? 1 : 0;
if (typeof percent === "number") { const closed = 1 - Math.min(100, Math.max(0, percent)) / 100; return inverted ? 1 - closed : closed; }
if (cover.state === "closed") return inverted ? 0 : 1;
if (cover.state === "open") return inverted ? 1 : 0;
return cover.state === "opening" || cover.state === "closing" ? 0.5 : 0;
}
/** How far the slats of a venetian blind are open (0 shut, 1 level), from its tilt position; null when it reports none. */
function slatsOpen(hass: HomeAssistant, id: string | null | undefined, separate?: string | null, inverted = false): number | null {
const main = hass.states[id || ""];
if (main?.attributes.nf_cover_control) return typeof main.attributes.current_tilt_position === "number" ? main.attributes.current_tilt_position / 100 : null;
const a = hass.states[separate || id || ""]?.attributes;
const tilt = a?.current_tilt_position ?? (separate ? a?.current_position : undefined);
const combined = !!main?.attributes.nf_cover_control;
const a = combined ? main!.attributes : hass.states[separate || id || ""]?.attributes;
const tilt = a?.current_tilt_position ?? (!combined && separate ? a?.current_position : undefined);
const value = typeof tilt === "number" ? Math.min(100, Math.max(0, tilt)) : separate ? positionPercent(hass, separate) : null;
return value === null ? null : (inverted ? 100 - value : value) / 100;
}
function blindClosedFraction(hass: HomeAssistant, e: OpeningEntities): number | null {
if (hass.states[e.cover || ""]?.attributes.nf_cover_control) return coverClosed(hass, e.cover);
const reported = reportedPosition(hass, e.position);
if (reported !== null) { const closed = e.positionInverted ? reported : 1 - reported; return e.coverInverted ? 1 - closed : closed; }
const cover = e.cover ? hass.states[e.cover] : undefined;