Skip to content

Commit

Permalink
Merge pull request #6821 from home-assistant/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten committed Sep 7, 2020
2 parents 61dbae8 + f15fbe5 commit 4999f1a
Show file tree
Hide file tree
Showing 65 changed files with 1,616 additions and 501 deletions.
4 changes: 2 additions & 2 deletions hassio/src/addon-view/config/hassio-addon-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class HassioAddonNetwork extends LitElement {
</div>
<div class="card-actions">
<ha-progress-button class="warning" @click=${this._resetTapped}>
Reset to defaults </ha-progress-button
>>
Reset to defaults
</ha-progress-button>
<ha-progress-button @click=${this._saveTapped}>
Save
</ha-progress-button>
Expand Down
5 changes: 3 additions & 2 deletions hassio/src/dashboard/hassio-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ export class HassioUpdate extends LitElement {
try {
await this.hass.callApi<HassioResponse<void>>("POST", item.apiPath);
} catch (err) {
// Only show an error if the status code was not 504, or no status at all (connection terminated)
if (err.status_code && err.status_code !== 504) {
// Only show an error if the status code was not expected (user behind proxy)
// or no status at all(connection terminated)
if (err.status_code && ![502, 503, 504].includes(err.status_code)) {
showAlertDialog(this, {
title: "Update failed",
text: extractApiErrorMessage(err),
Expand Down
5 changes: 4 additions & 1 deletion hassio/src/system/hassio-supervisor-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
setSupervisorOption,
SupervisorOptions,
updateSupervisor,
fetchHassioSupervisorInfo,
} from "../../../src/data/hassio/supervisor";
import {
showAlertDialog,
Expand Down Expand Up @@ -176,10 +177,11 @@ class HassioSupervisorInfo extends LitElement {

try {
const data: Partial<SupervisorOptions> = {
channel: this.supervisorInfo.channel !== "stable" ? "beta" : "stable",
channel: this.supervisorInfo.channel === "stable" ? "beta" : "stable",
};
await setSupervisorOption(this.hass, data);
await reloadSupervisor(this.hass);
this.supervisorInfo = await fetchHassioSupervisorInfo(this.hass);
} catch (err) {
showAlertDialog(this, {
title: "Failed to set supervisor option",
Expand All @@ -195,6 +197,7 @@ class HassioSupervisorInfo extends LitElement {

try {
await reloadSupervisor(this.hass);
this.supervisorInfo = await fetchHassioSupervisorInfo(this.hass);
} catch (err) {
showAlertDialog(this, {
title: "Failed to reload the supervisor",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@polymer/polymer": "3.1.0",
"@thomasloven/round-slider": "0.5.0",
"@types/chromecast-caf-sender": "^1.0.3",
"@types/sortablejs": "^1.10.6",
"@vaadin/vaadin-combo-box": "^5.0.10",
"@vaadin/vaadin-date-picker": "^4.0.7",
"@vue/web-component-wrapper": "^1.2.0",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="home-assistant-frontend",
version="20200904.0",
version="20200907.0",
description="The Home Assistant frontend",
url="https://github.com/home-assistant/home-assistant-polymer",
author="The Home Assistant Authors",
Expand Down
178 changes: 178 additions & 0 deletions src/components/entity/ha-entity-attribute-picker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import "@polymer/paper-input/paper-input";
import "@polymer/paper-item/paper-item";
import "@vaadin/vaadin-combo-box/theme/material/vaadin-combo-box-light";
import { HassEntity } from "home-assistant-js-websocket";
import {
css,
CSSResult,
customElement,
html,
LitElement,
property,
PropertyValues,
query,
TemplateResult,
} from "lit-element";
import { fireEvent } from "../../common/dom/fire_event";
import { PolymerChangedEvent } from "../../polymer-types";
import { HomeAssistant } from "../../types";
import "../ha-icon-button";
import "./state-badge";

export type HaEntityPickerEntityFilterFunc = (entityId: HassEntity) => boolean;

const rowRenderer = (root: HTMLElement, _owner, model: { item: string }) => {
if (!root.firstElementChild) {
root.innerHTML = `
<style>
paper-item {
margin: -10px;
padding: 0;
}
</style>
<paper-item></paper-item>
`;
}
root.querySelector("paper-item")!.textContent = model.item;
};

@customElement("ha-entity-attribute-picker")
class HaEntityAttributePicker extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;

@property() public entityId?: string;

@property({ type: Boolean }) public autofocus = false;

@property({ type: Boolean }) public disabled = false;

@property({ type: Boolean, attribute: "allow-custom-value" })
public allowCustomValue;

@property() public label?: string;

@property() public value?: string;

@property({ type: Boolean }) private _opened = false;

@query("vaadin-combo-box-light") private _comboBox!: HTMLElement;

protected shouldUpdate(changedProps: PropertyValues) {
return !(!changedProps.has("_opened") && this._opened);
}

protected updated(changedProps: PropertyValues) {
if (changedProps.has("_opened") && this._opened) {
const state = this.entityId ? this.hass.states[this.entityId] : undefined;
(this._comboBox as any).items = state
? Object.keys(state.attributes)
: [];
}
}

protected render(): TemplateResult {
if (!this.hass) {
return html``;
}

return html`
<vaadin-combo-box-light
.value=${this._value}
.allowCustomValue=${this.allowCustomValue}
.renderer=${rowRenderer}
@opened-changed=${this._openedChanged}
@value-changed=${this._valueChanged}
>
<paper-input
.autofocus=${this.autofocus}
.label=${this.label ??
this.hass.localize(
"ui.components.entity.entity-attribute-picker.attribute"
)}
.value=${this._value}
.disabled=${this.disabled || !this.entityId}
class="input"
autocapitalize="none"
autocomplete="off"
autocorrect="off"
spellcheck="false"
>
${this.value
? html`
<ha-icon-button
aria-label=${this.hass.localize(
"ui.components.entity.entity-picker.clear"
)}
slot="suffix"
class="clear-button"
icon="hass:close"
@click=${this._clearValue}
no-ripple
>
Clear
</ha-icon-button>
`
: ""}
<ha-icon-button
aria-label=${this.hass.localize(
"ui.components.entity.entity-attribute-picker.show_attributes"
)}
slot="suffix"
class="toggle-button"
.icon=${this._opened ? "hass:menu-up" : "hass:menu-down"}
>
Toggle
</ha-icon-button>
</paper-input>
</vaadin-combo-box-light>
`;
}

private _clearValue(ev: Event) {
ev.stopPropagation();
this._setValue("");
}

private get _value() {
return this.value || "";
}

private _openedChanged(ev: PolymerChangedEvent<boolean>) {
this._opened = ev.detail.value;
}

private _valueChanged(ev: PolymerChangedEvent<string>) {
const newValue = ev.detail.value;
if (newValue !== this._value) {
this._setValue(newValue);
}
}

private _setValue(value: string) {
this.value = value;
setTimeout(() => {
fireEvent(this, "value-changed", { value });
fireEvent(this, "change");
}, 0);
}

static get styles(): CSSResult {
return css`
paper-input > ha-icon-button {
--mdc-icon-button-size: 24px;
padding: 0px 2px;
color: var(--secondary-text-color);
}
[hidden] {
display: none;
}
`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ha-entity-attribute-picker": HaEntityAttributePicker;
}
}
15 changes: 12 additions & 3 deletions src/components/entity/ha-entity-picker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "../ha-icon-button";
import "@polymer/paper-input/paper-input";
import "@polymer/paper-item/paper-icon-item";
import "@polymer/paper-item/paper-item-body";
Expand All @@ -20,6 +19,7 @@ import { computeDomain } from "../../common/entity/compute_domain";
import { computeStateName } from "../../common/entity/compute_state_name";
import { PolymerChangedEvent } from "../../polymer-types";
import { HomeAssistant } from "../../types";
import "../ha-icon-button";
import "./state-badge";

export type HaEntityPickerEntityFilterFunc = (entityId: HassEntity) => boolean;
Expand Down Expand Up @@ -95,6 +95,8 @@ class HaEntityPicker extends LitElement {

@query("vaadin-combo-box-light") private _comboBox!: HTMLElement;

private _initedStates = false;

private _getStates = memoizeOne(
(
_opened: boolean,
Expand Down Expand Up @@ -148,11 +150,18 @@ class HaEntityPicker extends LitElement {
);

protected shouldUpdate(changedProps: PropertyValues) {
if (
changedProps.has("value") ||
changedProps.has("label") ||
changedProps.has("disabled")
) {
return true;
}
return !(!changedProps.has("_opened") && this._opened);
}

protected updated(changedProps: PropertyValues) {
if (changedProps.has("_opened") && this._opened) {
if (!this._initedStates || (changedProps.has("_opened") && this._opened)) {
const states = this._getStates(
this._opened,
this.hass,
Expand All @@ -162,14 +171,14 @@ class HaEntityPicker extends LitElement {
this.includeDeviceClasses
);
(this._comboBox as any).items = states;
this._initedStates = true;
}
}

protected render(): TemplateResult {
if (!this.hass) {
return html``;
}

return html`
<vaadin-combo-box-light
item-value-path="entity_id"
Expand Down
1 change: 1 addition & 0 deletions src/components/ha-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class HaDialog extends MwcDialog {
}
.mdc-dialog .mdc-dialog__surface {
position: var(--dialog-surface-position, relative);
top: var(--dialog-surface-top);
min-height: var(--mdc-dialog-min-height, auto);
}
:host([flexContent]) .mdc-dialog .mdc-dialog__content {
Expand Down
77 changes: 0 additions & 77 deletions src/components/ha-sidebar-sort-styles.ts

This file was deleted.

Loading

0 comments on commit 4999f1a

Please sign in to comment.