Compare commits

..
1 Commits
Author SHA1 Message Date
Paul Bottein a5f491a385 Swipe to open or close the tilt of tilt-only covers 2026-11-26 15:22:06 +01:00
4 changed files with 51 additions and 24 deletions

No files matched your search

@@ -22,7 +22,6 @@ import {
coverHasPositionControls,
coverHasTiltControls,
coverModeAttribute,
coverSupportsPosition,
coverSupportsSetValue,
defaultCoverMode,
} from "../../../data/cover";
@@ -164,7 +163,7 @@ class MoreInfoCover extends LitElement {
if (!request || this._drag) {
return undefined;
}
if (request.mode === "position" && !coverSupportsPosition(this.stateObj!)) {
if (!coverSupportsSetValue(this.stateObj!, request.mode)) {
return this._hint(request.value ? "requested_open" : "requested_closed");
}
return this._hint("requested", {
+17 -2
View File
@@ -149,6 +149,8 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
@property({ type: Boolean, reflect: true }) public large = false;
@state() private _fill = false;
// The dialog grows with the camera's or image's picture, as high as there
// is room for
@state() private _mediaAspectRatio?: number;
@@ -215,6 +217,7 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
this._detailsYamlMode = false;
this.large = params.large ?? false;
this._fill = false;
this._open = true;
this._loadEntityRegistryEntry();
}
@@ -698,7 +701,13 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
return html`
<ha-adaptive-dialog
.open=${this._open}
.width=${this.large || mediaAspectRatio ? "large" : "medium"}
.width=${
this._fill
? "full"
: this.large || mediaAspectRatio
? "large"
: "medium"
}
class=${classMap({
camera: domain === "camera",
image: domain === "image",
@@ -742,7 +751,7 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
></ha-icon-button-prev>
`
}
<span slot="headerTitle" class="title">
<span slot="headerTitle" @click=${this._enlarge} class="title">
${
breadcrumb.length > 0
? !__DEMO__ && isAdmin
@@ -1159,6 +1168,12 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
this._cameraControlsHeight = ev.detail.height;
}
private _enlarge() {
withViewTransition(() => {
this._fill = !this._fill;
});
}
private _handleOpened() {
window.addEventListener("dialog-closed", this._enableEscapeKeyClose);
window.addEventListener("show-dialog", this._disableEscapeKeyClose);
@@ -27,7 +27,6 @@ import {
coverCurrentValue,
coverHasTiltControls,
coverModeAttribute,
coverSupportsPosition,
coverSupportsSetValue,
coverSupportsTiltPosition,
coverTiltOpenness,
@@ -78,6 +77,17 @@ const pillHandle = (cx: number, cy: number, vertical: boolean) =>
const swipeResistance = (distance: number) =>
SWIPE_RESISTANCE * (1 - Math.exp(-Math.max(0, distance) / 30));
const OPEN_CLOSE_FEATURES: Record<
CoverControlMode,
Record<CoverSwipe["action"], CoverEntityFeature>
> = {
position: { open: CoverEntityFeature.OPEN, close: CoverEntityFeature.CLOSE },
tilt: {
open: CoverEntityFeature.OPEN_TILT,
close: CoverEntityFeature.CLOSE_TILT,
},
};
const modeSprings = (): ModeSprings => ({
position: new PercentSpring(),
tilt: new PercentSpring(),
@@ -190,11 +200,11 @@ export class HaStateControlCover extends LitElement {
}
private get _openCloseOnly(): boolean {
const features = OPEN_CLOSE_FEATURES[this.mode];
return (
this.mode === "position" &&
!coverSupportsPosition(this.stateObj) &&
(supportsFeature(this.stateObj, CoverEntityFeature.OPEN) ||
supportsFeature(this.stateObj, CoverEntityFeature.CLOSE))
!this._canSetValue &&
(supportsFeature(this.stateObj, features.open) ||
supportsFeature(this.stateObj, features.close))
);
}
@@ -208,7 +218,9 @@ export class HaStateControlCover extends LitElement {
private get _interactive(): boolean {
return (
this.stateObj.state !== UNAVAILABLE &&
(this._canSetValue || (this._openCloseOnly && !this._valueUnknown))
(this._canSetValue ||
(this._openCloseOnly &&
coverCurrentValue(this.stateObj, this.mode) !== undefined))
);
}
@@ -412,11 +424,7 @@ export class HaStateControlCover extends LitElement {
}
private _swipeAction(): CoverSwipe["action"] {
const end =
this.request?.mode === "position"
? this.request.value
: this._drawingGoal("position");
return end >= 50 ? "close" : "open";
return this._handleGoal(this.mode) >= 50 ? "close" : "open";
}
private _startSwipe(
@@ -424,14 +432,10 @@ export class HaStateControlCover extends LitElement {
shape: CoverShape,
startPointer: number
) {
const mode = this.mode;
const action = this._swipeAction();
const closing = action === "close";
if (
!supportsFeature(
this.stateObj,
closing ? CoverEntityFeature.CLOSE : CoverEntityFeature.OPEN
)
) {
if (!supportsFeature(this.stateObj, OPEN_CLOSE_FEATURES[mode][action])) {
return;
}
const direction = closing ? -1 : 1;
@@ -462,13 +466,13 @@ export class HaStateControlCover extends LitElement {
const passedHalfway = Boolean(this._drag?.swipe?.passedHalfway);
this._setDrag(undefined);
if (passedHalfway) {
fireEvent(this, "cover-command", { mode: "position", action });
fireEvent(this, "cover-command", { mode, action });
}
},
tap: (e) => {
const pointer = this._pointerValue(e, shape);
if (pointer !== undefined && pointer >= 50 !== closing) {
fireEvent(this, "cover-command", { mode: "position", action });
fireEvent(this, "cover-command", { mode, action });
}
},
cancel: () => this._setDrag(undefined),
+10 -1
View File
@@ -1,6 +1,7 @@
import type { PropertyValues } from "lit";
import type { HASSDomEvent } from "../common/dom/fire_event";
import { mainWindow } from "../common/dom/get_main_window";
import { computeDomain } from "../common/entity/compute_domain";
import { replaceCurrentUrl } from "../common/navigate";
import {
createMoreInfoUrl,
@@ -11,6 +12,8 @@ import type { MoreInfoDialogParams } from "../dialogs/more-info/ha-more-info-dia
import type { Constructor } from "../types";
import type { HassBaseEl } from "./hass-base-mixin";
const LARGE_MORE_INFO_DOMAINS = ["camera"];
declare global {
// for fire event
interface HASSDomEvents {
@@ -44,7 +47,13 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
{
entityId: ev.detail.entityId,
view,
large: ev.detail.large,
large:
ev.detail.large ??
(ev.detail.entityId
? LARGE_MORE_INFO_DOMAINS.includes(
computeDomain(ev.detail.entityId)
)
: false),
data: ev.detail.data,
returnUrl,
},