Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/ha-cover-controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class HaCoverControls extends LitElement {

@state() private _entityObj?: CoverEntity;

protected updated(changedProperties: PropertyValues): void {
super.updated(changedProperties);
public willUpdate(changedProperties: PropertyValues): void {
super.willUpdate(changedProperties);

if (changedProperties.has("stateObj")) {
this._entityObj = new CoverEntity(this.hass, this.stateObj);
Expand Down
4 changes: 2 additions & 2 deletions src/components/ha-cover-tilt-controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class HaCoverTiltControls extends LitElement {

@state() private _entityObj?: CoverEntity;

protected updated(changedProperties: PropertyValues): void {
super.updated(changedProperties);
public willUpdate(changedProperties: PropertyValues): void {
super.willUpdate(changedProperties);

if (changedProperties.has("stateObj")) {
this._entityObj = new CoverEntity(this.hass, this.stateObj);
Expand Down
15 changes: 11 additions & 4 deletions src/components/user/ha-user-badge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import {
css,
CSSResultGroup,
html,
LitElement,
PropertyValues,
TemplateResult,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
import { styleMap } from "lit/directives/style-map";
Expand Down Expand Up @@ -32,13 +39,13 @@ class UserBadge extends LitElement {

private _personEntityId?: string;

protected updated(changedProps) {
super.updated(changedProps);
public willUpdate(changedProps: PropertyValues<this>) {
super.willUpdate(changedProps);
if (changedProps.has("user")) {
this._getPersonPicture();
return;
}
const oldHass = changedProps.get("hass");
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
if (
this._personEntityId &&
oldHass &&
Expand Down
10 changes: 4 additions & 6 deletions src/panels/calendar/ha-full-calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ export class HAFullCalendar extends LitElement {

@property() public initialView: FullCalendarView = "dayGridMonth";

@state() private calendar?: Calendar;
private calendar?: Calendar;

@state() private _activeView?: FullCalendarView;
@state() private _activeView = this.initialView;

public updateSize(): void {
this.calendar?.updateSize();
Expand Down Expand Up @@ -181,8 +181,8 @@ export class HAFullCalendar extends LitElement {
`;
}

protected updated(changedProps: PropertyValues): void {
super.updated(changedProps);
public willUpdate(changedProps: PropertyValues): void {
super.willUpdate(changedProps);

if (!this.calendar) {
return;
Expand Down Expand Up @@ -216,8 +216,6 @@ export class HAFullCalendar extends LitElement {
initialView: this.initialView,
};

this._activeView = this.initialView;

config.dateClick = (info) => this._handleDateClick(info);
config.eventClick = (info) => this._handleEventClick(info);

Expand Down
8 changes: 5 additions & 3 deletions src/panels/calendar/ha-panel-calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ class PanelCalendar extends LitElement {

private _end?: Date;

protected firstUpdated(changedProps: PropertyValues): void {
super.firstUpdated(changedProps);
this._calendars = getCalendars(this.hass);
public willUpdate(changedProps: PropertyValues): void {
super.willUpdate(changedProps);
if (!this.hasUpdated) {
this._calendars = getCalendars(this.hass);
}
}

protected render(): TemplateResult {
Expand Down
18 changes: 17 additions & 1 deletion src/panels/lovelace/cards/hui-humidifier-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,27 @@ export class HuiHumidifierCard extends LitElement implements LovelaceCard {
}

if (!oldHass || oldHass.states[this._config.entity] !== stateObj) {
this._setHum = this._getSetHum(stateObj);
this._rescale_svg();
}
}

public willUpdate(changedProps: PropertyValues) {
if (!this.hass || !this._config || !changedProps.has("hass")) {
return;
}

const stateObj = this.hass.states[this._config.entity];
if (!stateObj) {
return;
}

const oldHass = changedProps.get("hass") as HomeAssistant | undefined;

if (!oldHass || oldHass.states[this._config.entity] !== stateObj) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!oldHass || oldHass.states[this._config.entity] !== stateObj) {
if (!oldHass || !deepEqual(oldHass.states[this._config.entity], stateObj)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do a deepEqual? 🤔

this._setHum = this._getSetHum(stateObj);
}
}

private _rescale_svg() {
// Set the viewbox of the SVG containing the set humidity to perfectly
// fit the text
Expand Down
52 changes: 35 additions & 17 deletions src/panels/lovelace/cards/hui-media-control-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,15 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
}

protected firstUpdated(): void {
this._measureCard();
this._attachObserver();
}

protected updated(changedProps: PropertyValues): void {
super.updated(changedProps);
public willUpdate(changedProps: PropertyValues): void {
super.willUpdate(changedProps);

if (!this.hasUpdated) {
this._measureCard();
}

if (
!this._config ||
Expand All @@ -352,6 +355,35 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
return;
}

const oldHass = changedProps.get("hass") as HomeAssistant | undefined;

const oldImage =
oldHass?.states[this._config.entity]?.attributes.entity_picture_local ||
oldHass?.states[this._config.entity]?.attributes.entity_picture;

if (!this._image) {
this._foregroundColor = undefined;
this._backgroundColor = undefined;
return;
}

if (this._image !== oldImage) {
this._setColors();
}
}

protected updated(changedProps: PropertyValues) {
if (
!this._config ||
!this.hass ||
!this._stateObj ||
(!changedProps.has("_config") && !changedProps.has("hass"))
) {
return;
}

const stateObj = this._stateObj;

const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
const oldConfig = changedProps.get("_config") as
| MediaControlCardConfig
Expand Down Expand Up @@ -384,20 +416,6 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
clearInterval(this._progressInterval);
this._progressInterval = undefined;
}

const oldImage =
oldHass?.states[this._config.entity]?.attributes.entity_picture_local ||
oldHass?.states[this._config.entity]?.attributes.entity_picture;

if (!this._image) {
this._foregroundColor = undefined;
this._backgroundColor = undefined;
return;
}

if (this._image !== oldImage) {
this._setColors();
}
}

private get _image() {
Expand Down
18 changes: 17 additions & 1 deletion src/panels/lovelace/cards/hui-thermostat-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,27 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard {
}

if (!oldHass || oldHass.states[this._config.entity] !== stateObj) {
this._setTemp = this._getSetTemp(stateObj);
this._rescale_svg();
}
}

public willUpdate(changedProps: PropertyValues) {
if (!this.hass || !this._config || !changedProps.has("hass")) {
return;
}

const stateObj = this.hass.states[this._config.entity];
if (!stateObj) {
return;
}

const oldHass = changedProps.get("hass") as HomeAssistant | undefined;

if (!oldHass || oldHass.states[this._config.entity] !== stateObj) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!oldHass || oldHass.states[this._config.entity] !== stateObj) {
if (!oldHass || !deepEqual(oldHass.states[this._config.entity], stateObj)) {

this._setTemp = this._getSetTemp(stateObj);
}
}

private _rescale_svg() {
// Set the viewbox of the SVG containing the set temperature to perfectly
// fit the text
Expand Down
8 changes: 6 additions & 2 deletions src/panels/lovelace/cards/hui-weather-forecast-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
return hasConfigOrEntityChanged(this, changedProps);
}

public willUpdate(): void {
if (!this.hasUpdated) {
this._measureCard();
}
}

protected firstUpdated(): void {
this._measureCard();
this._attachObserver();
}

Expand All @@ -129,7 +134,6 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
(changedProps.has("_config") && oldConfig!.theme !== this._config.theme)
) {
applyThemesOnElement(this, this.hass.themes, this._config.theme);
this.requestUpdate();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/components/hui-graph-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class HuiGraphBase extends LitElement {
`;
}

protected updated(changedProps: PropertyValues) {
public willUpdate(changedProps: PropertyValues) {
if (!this.coordinates) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
this._resizeObserver?.unobserve(this);
}

public willUpdate(): void {
if (!this.hasUpdated) {
this._measureCard();
}
}

protected firstUpdated(): void {
this._measureCard();
this._attachObserver();
}

Expand Down