lit-element#PropertyValues TypeScript Examples

The following examples show how to use lit-element#PropertyValues. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: linak-desk-card.ts    From linak-desk-card with MIT License 6 votes vote down vote up
protected shouldUpdate(changedProps: PropertyValues): boolean {
    if (!this.config) {
      return false;
    }

    if (changedProps.has('config')) {
      return true;
    }

    const newHass = changedProps.get('hass') as HomeAssistant | undefined;
    if (newHass) {
      return (
        newHass.states[this.config?.desk] !== this.hass?.states[this.config?.desk]
        || newHass.states[this.config?.connection_sensor]?.state !== this.hass?.states[this.config?.connection_sensor]?.state
        || newHass.states[this.config?.height_sensor]?.state !== this.hass?.states[this.config?.height_sensor]?.state
        || newHass.states[this.config?.moving_sensor]?.state !== this.hass?.states[this.config?.moving_sensor]?.state
      );
    }
    return true;
  }
Example #2
Source File: harmony-card.ts    From harmony-card with MIT License 6 votes vote down vote up
protected shouldUpdate(changedProps: PropertyValues): boolean {
        // has config changes
        if (changedProps.has('config')) {
            return true;
        }


        return this.hasEntityChanged(this, changedProps, 'entity');
    }
Example #3
Source File: harmony-card.ts    From harmony-card with MIT License 6 votes vote down vote up
// Check if Entity changed
    private hasEntityChanged(
        element: any,
        changedProps: PropertyValues,
        entityName
    ): boolean {
        if (element._config!.entity) {
            const oldHass = changedProps.get('hass') as HomeAssistant | undefined;
            if (oldHass) {
                // check if state changed
                if (oldHass.states[element._config![entityName]] !== element.hass!.states[element._config![entityName]]) {
                    return true;
                }
            }
            return true;
        } else {
            return false;
        }
    }
Example #4
Source File: grid-view.ts    From Custom-Grid-View with MIT License 6 votes vote down vote up
protected updated(changedProperties: PropertyValues): void {
    super.updated(changedProperties);

    if (changedProperties.has('hass')) {
      const oldHass = changedProperties.get('hass') as HomeAssistant;

      if ((oldHass && this.hass!.dockedSidebar !== oldHass.dockedSidebar) || (!oldHass && this.hass)) {
        this._updateColumns();
      }

      if (changedProperties.size === 1) {
        return;
      }
    }

    const oldLovelace = changedProperties.get('lovelace') as any | undefined;

    if (
      (changedProperties.has('lovelace') &&
        (oldLovelace?.config !== this.lovelace?.config || oldLovelace?.editMode !== this.lovelace?.editMode)) ||
      changedProperties.has('_columns')
    ) {
      if (!this._layout?.length) {
        this._createLayout();
        return;
      }

      this._createCards();
    }

    if (changedProperties.has('lovelace') && this.lovelace.editMode && !oldLovelace.editMode) {
      this._layoutEdit = this._layout;
    }

    if (changedProperties.has('lovelace') && !this.lovelace.editMode && oldLovelace.editMode) {
      this._layout = (this._config as any).layout;
    }
  }
Example #5
Source File: mini-thermostat.ts    From lovelace-mini-thermostat with MIT License 5 votes vote down vote up
protected shouldUpdate(changedProps: PropertyValues): boolean {
    return UPDATE_PROPS.some(prop => changedProps.has(prop));
  }
Example #6
Source File: select-list-card.ts    From select-list-card with MIT License 5 votes vote down vote up
protected shouldUpdate(changedProps: PropertyValues): boolean {
    return hasConfigOrEntityChanged(this, changedProps, false);
  }