From 575f9c8caab99b834251b6de27a727c2fd946313 Mon Sep 17 00:00:00 2001 From: Piotr Machowski Date: Fri, 31 Mar 2023 01:49:32 +0200 Subject: [PATCH] Improve hiding modes selector --- src/const.ts | 10 +++++ src/xiaomi-vacuum-map-card.ts | 83 +++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 39 deletions(-) diff --git a/src/const.ts b/src/const.ts index 42cd27bd..531534f8 100644 --- a/src/const.ts +++ b/src/const.ts @@ -1,3 +1,7 @@ +import { MapModeConfig } from "./types/types"; +import { SelectionType } from "./model/map_mode/selection-type"; +import { RepeatsType } from "./model/map_mode/repeats-type"; + export const CARD_VERSION = "v@VACUUM_MAP_CARD_VERSION_PLACEHOLDER@"; export const CARD_CUSTOM_ELEMENT_NAME = "xiaomi-vacuum-map-card"; export const EDITOR_CUSTOM_ELEMENT_NAME = "xiaomi-vacuum-map-card-editor"; @@ -14,3 +18,9 @@ export const EVENT_SERVICE_CALL_GET = "map-card-service-call-get"; export const EVENT_SERVICE_CALL = "map-card-service-call"; export const EVENT_LOVELACE_DOM = "ll-custom"; export const EVENT_LOVELACE_DOM_DETAIL = "xiaomi_vacuum_map_card"; + +export const EMPTY_MAP_MODE: MapModeConfig = { + run_immediately: true, + selection_type: SelectionType[SelectionType.ROOM], + repeats_type: RepeatsType[RepeatsType.NONE] +} \ No newline at end of file diff --git a/src/xiaomi-vacuum-map-card.ts b/src/xiaomi-vacuum-map-card.ts index 1ab43761..f244bf61 100644 --- a/src/xiaomi-vacuum-map-card.ts +++ b/src/xiaomi-vacuum-map-card.ts @@ -28,6 +28,7 @@ import { DISCONNECTED_IMAGE, DISCONNECTION_TIME, EDITOR_CUSTOM_ELEMENT_NAME, + EMPTY_MAP_MODE, EVENT_AUTOGENERATED_CONFIG, EVENT_AUTOGENERATED_CONFIG_GET, EVENT_LOVELACE_DOM, @@ -373,45 +374,49 @@ export class XiaomiVacuumMapCard extends LitElement { ${conditional(!validCalibration, () => this._showInvalidCalibrationWarning())} -
- ${conditional( - validCalibration && (modes.length > 1 || mapControls.length > 0), - () => html` -
-
- ${conditional(modes.length > 1, () => - ModesMenuRenderer.render(modes, this.selectedMode, selected => - this._setCurrentMode(selected), - this._modesDropdownMenu - ), - )} - ${conditional( - mapControls.length > 0, - () => html`
${mapControls}
`, - )} + ${conditional( + modes.length > 1 || mapControls.length > 0 || (icons?.length??0) !== 0 || (tiles?.length ?? 0) !== 0, + () => html` +
+ ${conditional( + validCalibration && (modes.length > 1 || mapControls.length > 0), + () => html` +
+
+ ${conditional(modes.length > 1, () => + ModesMenuRenderer.render(modes, this.selectedMode, selected => + this._setCurrentMode(selected), + this._modesDropdownMenu + ), + )} + ${conditional( + mapControls.length > 0, + () => html`
${mapControls}
`, + )} +
-
- `, - )} - ${conditional( - (icons?.length ?? 0) !== 0, - () => html` -
-
- ${icons?.map(icon => IconRenderer.render(icon, this))} + `, + )} + ${conditional( + (icons?.length ?? 0) !== 0, + () => html` +
+
+ ${icons?.map(icon => IconRenderer.render(icon, this))} +
-
- `, - )} - ${conditional( - (tiles?.length ?? 0) !== 0, - () => html` -
- ${tiles?.map(sensor => TileRenderer.render(sensor, this.internalVariables, this))} -
- `, - )} -
+ `, + )} + ${conditional( + (tiles?.length ?? 0) !== 0, + () => html` +
+ ${tiles?.map(sensor => TileRenderer.render(sensor, this.internalVariables, this))} +
+ `, + )} +
` + )} ${ToastRenderer.render("map-card")} `; @@ -531,9 +536,9 @@ export class XiaomiVacuumMapCard extends LitElement { if (this.hass) this._updateCalibration(config); const vacuumPlatform = config.vacuum_platform ?? "default"; this.modes = ( - (config.map_modes?.length ?? 0) === 0 + (config.map_modes?.length ?? -1) === -1 ? PlatformGenerator.generateDefaultModes(vacuumPlatform) - : config.map_modes ?? [] + : config.map_modes ?? [EMPTY_MAP_MODE] ).map(m => new MapMode(vacuumPlatform, m, this.config.language)); this.presetIndex = index;