From 16f7f4b848405dbaae4363ee4528b9c3d9c443b0 Mon Sep 17 00:00:00 2001 From: farmio Date: Fri, 17 May 2024 20:29:01 +0200 Subject: [PATCH] remove SchemaOptions --- src/services/websocket.service.ts | 13 +--------- src/types/entity_data.ts | 12 ---------- src/views/entities_create.ts | 40 +++++++------------------------ 3 files changed, 10 insertions(+), 55 deletions(-) diff --git a/src/services/websocket.service.ts b/src/services/websocket.service.ts index ff6577b7..69210386 100644 --- a/src/services/websocket.service.ts +++ b/src/services/websocket.service.ts @@ -10,10 +10,8 @@ import { import { CreateEntityData, CreateEntityResult, - EditEntityData, UpdateEntityData, DeviceCreateData, - SchemaOptions, } from "../types/entity_data"; export const getKnxInfoData = (hass: HomeAssistant): Promise => @@ -58,15 +56,6 @@ export const getKnxProject = (hass: HomeAssistant): Promise = /** * Entity store calls. */ -export const getPlatformSchemaOptions = ( - hass: HomeAssistant, - platform: string, -): Promise => - hass.callWS({ - type: "knx/get_platform_schema_options", - platform: platform, - }); - export const validateEntity = ( hass: HomeAssistant, entityData: CreateEntityData | UpdateEntityData, @@ -100,7 +89,7 @@ export const deleteEntity = (hass: HomeAssistant, entityId: string) => entity_id: entityId, }); -export const getEntityConfig = (hass: HomeAssistant, entityId: string): Promise => +export const getEntityConfig = (hass: HomeAssistant, entityId: string): Promise => hass.callWS({ type: "knx/get_entity_config", entity_id: entityId, diff --git a/src/types/entity_data.ts b/src/types/entity_data.ts index 32000df6..4624c2f9 100644 --- a/src/types/entity_data.ts +++ b/src/types/entity_data.ts @@ -39,23 +39,11 @@ export interface UpdateEntityData extends CreateEntityData { entity_id: string; } -export interface EditEntityData extends CreateEntityData { - schema_options: SchemaOptions | null; -} - export interface DeviceCreateData { name: string; area_id?: string; } -export interface SchemaOptions { - entity?: EntitySchemaOptions; -} - -export interface EntitySchemaOptions { - // nothing yet -} - // ################# // Validation result // ################# diff --git a/src/views/entities_create.ts b/src/views/entities_create.ts index 27fea81a..98c95d02 100644 --- a/src/views/entities_create.ts +++ b/src/views/entities_create.ts @@ -23,15 +23,9 @@ import { createEntity, updateEntity, getEntityConfig, - getPlatformSchemaOptions, validateEntity, } from "services/websocket.service"; -import type { - EntityData, - SchemaOptions, - ErrorDescription, - CreateEntityResult, -} from "types/entity_data"; +import type { EntityData, ErrorDescription, CreateEntityResult } from "types/entity_data"; import { platformConstants } from "../utils/common"; import { validDPTsForSchema } from "../utils/dpt"; @@ -56,7 +50,7 @@ export class KNXCreateEntity extends LitElement { @state() private _config?: EntityData; - @state() private _schemaOptions?: SchemaOptions; + @state() private _loading = false; @state() private _validationErrors?: ErrorDescription[]; @@ -100,33 +94,24 @@ export class KNXCreateEntity extends LitElement { // knx/entities/create -> path: ""; knx/entities/create/ -> path: "/" // knx/entities/create/light -> path: "/light" const entityPlatform = this.route.path.split("/")[1]; - if (!entityPlatform) { - this._schemaOptions = undefined; - } else if (entityPlatform !== this.entityPlatform) { - getPlatformSchemaOptions(this.hass, entityPlatform).then((schemaOptions) => { - logger.debug("schemaOptions", schemaOptions); - this._schemaOptions = schemaOptions ?? {}; - }); - } this.entityPlatform = entityPlatform; + this._loading = false; } else if (intent === "edit") { // knx/entities/edit/light.living_room -> path: "/light.living_room" this.entityId = this.route.path.split("/")[1]; + this._loading = true; getEntityConfig(this.hass, this.entityId) .then((entityConfigData) => { - const { - platform: entityPlatform, - data: config, - schema_options: schemaOptions, - } = entityConfigData; + const { platform: entityPlatform, data: config } = entityConfigData; this.entityPlatform = entityPlatform; this._config = config; - this._schemaOptions = schemaOptions ?? {}; }) .catch((err) => { logger.warn("Fetching entity config failed.", err); - this._schemaOptions = {}; // used as marker for loaded -> not undefined this.entityPlatform = undefined; // used as error marker + }) + .finally(() => { + this._loading = false; }); } // const urlParams = new URLSearchParams(mainWindow.location.search); @@ -136,7 +121,7 @@ export class KNXCreateEntity extends LitElement { } protected render(): TemplateResult { - if (!this.hass || !this.knx.project || !this._intent) { + if (!this.hass || !this.knx.project || !this._intent || this._loading) { return html` `; } if (this._intent === "edit") return this._renderEdit(); @@ -144,9 +129,6 @@ export class KNXCreateEntity extends LitElement { } private _renderCreate(): TemplateResult { - if (!!this.entityPlatform && !this._schemaOptions) { - return html` `; - } if (!this.entityPlatform) { return this._renderTypeSelection(); } @@ -159,9 +141,6 @@ export class KNXCreateEntity extends LitElement { } private _renderEdit(): TemplateResult { - if (!this._schemaOptions) { - return html` `; - } if (!this.entityPlatform) { return this._renderNotFound(); } @@ -232,7 +211,6 @@ export class KNXCreateEntity extends LitElement { .knx=${this.knx} .platform=${platformInfo} .config=${this._config} - .schemaOptions=${this._schemaOptions} .validationErrors=${this._validationErrors} @knx-entity-configuration-changed=${this._configChanged} >