diff --git a/src/elements/lc-config-card.js b/src/elements/lc-config-card.js deleted file mode 100644 index 7e444cc..0000000 --- a/src/elements/lc-config-card.js +++ /dev/null @@ -1,427 +0,0 @@ -import { LitElement, html, css, nothing } from 'lit'; - -class LandroidConfigCard extends LitElement { - static properties = { - hass: { type: Object }, - config: { type: Object }, - deviceName: { type: String }, - }; - - /** - * Lifecycle method to update the component when it is connected to the DOM. - * - * Calls the LitElement `connectedCallback` method. - * - * @return {void} This function does not return anything. - * @see https://lit.dev/docs/components/lifecycle/#connectedcallback - */ - connectedCallback() { - super.connectedCallback(); - this.addEventListener('hass-updated', () => this.requestUpdate()); - } - - /** - * Lifecycle method to clean up when the component is disconnected from the DOM. - * - * Calls the LitElement `disconnectedCallback` method. - * - * @return {void} This function does not return anything. - * @see https://lit.dev/docs/components/lifecycle/#disconnectedcallback - */ - disconnectedCallback() { - super.disconnectedCallback(); - this.removeEventListener('hass-updated', () => this.requestUpdate()); - } - - /** - * Lifecycle method to update the component after the first render. - * - * This function is called automatically by LitElement after the component - * has been rendered for the first time. It sets the `_firstRendered` property - * of the component to `true`, indicating that the component has been rendered - * at least once. - * - * @return {void} This function does not return a value. - * @see https://lit.dev/docs/components/lifecycle/#firstupdated - */ - firstUpdated() { - this._firstRendered = true; - } - - /** - * Lifecycle method to indicate if the component should update. - * - * This method is called every time a property of the component changes. - * It is used to determine if the component should re-render when a property - * value changes. - * - * @param {Map} changedProps - Map of changed properties. - * - * @return {void} This function does not return a value. - * @see https://lit.dev/docs/components/lifecycle/#updated - */ - updated(changedProps) { - if (changedProps.has('hass')) { - console.log('Объект hass обновлен:', this.hass); - this.requestUpdate(); // Обновляем компонент при каждом изменении `hass` - } - } - - /** - * Lifecycle method to indicate if the component should update. - * - * This method is called by LitElement whenever a property of the component - * changes. It returns `true` if the component should update, and `false` - * otherwise. - * - * We update the component if the `hass`, `config`, or `deviceName` properties - * change. - * - * @param {Map} changedProps - Map of changed properties. - * @return {boolean} True if the component should update, false otherwise. - * @see https://lit.dev/docs/components/lifecycle/#shouldupdate - */ - shouldUpdate(changedProps) { - return ( - changedProps.has('hass') || - changedProps.has('config') || - changedProps.has('deviceName') - ); - } - - /** - * Styles for the component. - * - * The styles are scoped to the component and are used to style the - * component's host element. The styles are defined using LitElement's - * `css` tag function. - * - * @return {CSSResult} The styles for the component. - */ - static get styles() { - return css` - :host { - height: 100%; - display: flex; - flex-direction: column; - padding: var(--lc-spacing); - border-top: 1px solid var(--lc-divider-color); - } - - #states { - flex: 1 1 0%; - } - - #states > * { - margin: 8px 0px; - } - - #states > :first-child { - margin-top: 0px; - } - - #states > *:last-child { - margin-bottom: 0; - } - - #states > div > * { - overflow: clip visible; - } - - #states > div { - position: relative; - } - - .icon { - padding: 0px 18px 0px 8px; - } - - /* hui-input-number-entity-row */ - .flex { - display: flex; - align-items: center; - justify-content: flex-end; - flex-grow: 2; - } - - .state { - min-width: 45px; - text-align: end; - } - - .slider { - flex-grow: 2; - width: 100px; - max-width: 200px; - } - - ha-textfield { - text-align: end; - } - - ha-slider { - width: 100%; - max-width: 200px; - } - - ha-select { - width: 100%; - } - `; - } - - /** - * Renders the UI for the LandroidConfigCard component based on the current configuration. - * - * This function checks if the configuration and its entities are present. - * It then maps over the entities and renders the appropriate elements - * depending on the domain of each entity (button, number, select, switch). - * The rendered elements are wrapped inside a div with the id "states". - * - * @return {TemplateResult|nothing} The rendered HTML template or `nothing` if no config is available. - */ - render() { - if (!this.config || !this.config.entities) return nothing; - - const entities = this.config.entities.map((entityId) => { - const domain = entityId.split('.')[0]; - switch (domain) { - case 'button': - return this.renderButtonEntity(entityId); - case 'number': - return this.renderNumberEntity(entityId); - case 'select': - return this.renderSelectEntity(entityId); - case 'switch': - return this.renderToggleSwitchEntity(entityId); - default: - return nothing; - } - }); - - return html` -