Skip to content

Commit

Permalink
remove SchemaOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
farmio committed Jul 25, 2024
1 parent 6a115f3 commit 16f7f4b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 55 deletions.
13 changes: 1 addition & 12 deletions src/services/websocket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import {
import {
CreateEntityData,
CreateEntityResult,
EditEntityData,
UpdateEntityData,
DeviceCreateData,
SchemaOptions,
} from "../types/entity_data";

export const getKnxInfoData = (hass: HomeAssistant): Promise<KNXInfoData> =>
Expand Down Expand Up @@ -58,15 +56,6 @@ export const getKnxProject = (hass: HomeAssistant): Promise<KNXProjectRespone> =
/**
* Entity store calls.
*/
export const getPlatformSchemaOptions = (
hass: HomeAssistant,
platform: string,
): Promise<SchemaOptions | null> =>
hass.callWS({
type: "knx/get_platform_schema_options",
platform: platform,
});

export const validateEntity = (
hass: HomeAssistant,
entityData: CreateEntityData | UpdateEntityData,
Expand Down Expand Up @@ -100,7 +89,7 @@ export const deleteEntity = (hass: HomeAssistant, entityId: string) =>
entity_id: entityId,
});

export const getEntityConfig = (hass: HomeAssistant, entityId: string): Promise<EditEntityData> =>
export const getEntityConfig = (hass: HomeAssistant, entityId: string): Promise<CreateEntityData> =>
hass.callWS({
type: "knx/get_entity_config",
entity_id: entityId,
Expand Down
12 changes: 0 additions & 12 deletions src/types/entity_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
// #################
Expand Down
40 changes: 9 additions & 31 deletions src/views/entities_create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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[];

Expand Down Expand Up @@ -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);
Expand All @@ -136,17 +121,14 @@ 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` <hass-loading-screen></hass-loading-screen> `;
}
if (this._intent === "edit") return this._renderEdit();
return this._renderCreate();
}

private _renderCreate(): TemplateResult {
if (!!this.entityPlatform && !this._schemaOptions) {
return html` <hass-loading-screen></hass-loading-screen> `;
}
if (!this.entityPlatform) {
return this._renderTypeSelection();
}
Expand All @@ -159,9 +141,6 @@ export class KNXCreateEntity extends LitElement {
}

private _renderEdit(): TemplateResult {
if (!this._schemaOptions) {
return html` <hass-loading-screen></hass-loading-screen> `;
}
if (!this.entityPlatform) {
return this._renderNotFound();
}
Expand Down Expand Up @@ -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}
>
Expand Down

0 comments on commit 16f7f4b

Please sign in to comment.