Merge pull request #4671 from home-assistant/device-page-fixes

Device info page fixes
This commit is contained in:
Bram Kragten 2020-01-30 14:51:40 +01:00 committed by GitHub
commit 2f86b6ec3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 204 additions and 186 deletions

View File

@ -55,6 +55,10 @@ export class HaChips extends LitElement {
static get styles(): CSSResult { static get styles(): CSSResult {
return css` return css`
${unsafeCSS(chipStyles)} ${unsafeCSS(chipStyles)}
.mdc-chip {
background-color: rgba(var(--rgb-primary-text-color), 0.15);
color: var(--primary-text-color);
}
`; `;
} }
} }

View File

@ -1,4 +1,11 @@
import { LitElement, TemplateResult, html, property } from "lit-element"; import {
LitElement,
TemplateResult,
html,
property,
CSSResult,
css,
} from "lit-element";
import { HomeAssistant } from "../../../../types"; import { HomeAssistant } from "../../../../types";
import { DeviceAutomation } from "../../../../data/device_automation"; import { DeviceAutomation } from "../../../../data/device_automation";
@ -76,4 +83,12 @@ export abstract class HaDeviceAutomationCard<
data[this.type] = [automation]; data[this.type] = [automation];
showAutomationEditor(this, data); showAutomationEditor(this, data);
} }
static get styles(): CSSResult {
return css`
h3 {
color: var(--primary-text-color);
}
`;
}
} }

View File

@ -113,7 +113,9 @@ export class DialogDeviceAutomation extends LitElement {
` `
: ""} : ""}
` `
: html``} : this.hass.localize(
"ui.panel.config.devices.automation.no_device_automations"
)}
</div> </div>
<mwc-button slot="primaryAction" @click="${this._close}"> <mwc-button slot="primaryAction" @click="${this._close}">
Close Close
@ -126,54 +128,17 @@ export class DialogDeviceAutomation extends LitElement {
this._params = undefined; this._params = undefined;
} }
static get styles(): CSSResult[] { static get styles(): CSSResult {
return [ return css`
css`
ha-dialog { ha-dialog {
--mdc-dialog-title-ink-color: var(--primary-text-color); --mdc-dialog-title-ink-color: var(--primary-text-color);
--justify-action-buttons: space-between;
} }
@media only screen and (min-width: 600px) { @media only screen and (min-width: 600px) {
ha-dialog { ha-dialog {
--mdc-dialog-min-width: 600px; --mdc-dialog-min-width: 600px;
} }
} }
.form { `;
padding-bottom: 24px;
}
.location {
display: flex;
}
.location > * {
flex-grow: 1;
min-width: 0;
}
.location > *:first-child {
margin-right: 4px;
}
.location > *:last-child {
margin-left: 4px;
}
ha-location-editor {
margin-top: 16px;
}
ha-user-picker {
margin-top: 16px;
}
mwc-button.warning {
--mdc-theme-primary: var(--google-red-500);
}
.error {
color: var(--google-red-500);
}
a {
color: var(--primary-color);
}
p {
color: var(--primary-text-color);
}
`,
];
} }
} }

View File

@ -41,6 +41,7 @@ import { RelatedResult, findRelated } from "../../../data/search";
import { SceneEntities, showSceneEditor } from "../../../data/scene"; import { SceneEntities, showSceneEditor } from "../../../data/scene";
import { navigate } from "../../../common/navigate"; import { navigate } from "../../../common/navigate";
import { showDeviceAutomationDialog } from "./device-detail/show-dialog-device-automation"; import { showDeviceAutomationDialog } from "./device-detail/show-dialog-device-automation";
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
export interface EntityRegistryStateEntry extends EntityRegistryEntry { export interface EntityRegistryStateEntry extends EntityRegistryEntry {
stateName?: string; stateName?: string;
@ -152,12 +153,14 @@ export class HaConfigDevicePage extends LitElement {
</div> </div>
<div class="right"> <div class="right">
<div class="column"> <div class="column">
${
isComponentLoaded(this.hass, "automation")
? html`
<ha-card <ha-card
.header=${this.hass.localize( .header=${this.hass.localize(
"ui.panel.config.devices.automation.automations" "ui.panel.config.devices.automation.automations"
)} )}
>${ >${this._related?.automation?.length
this._related?.automation?.length
? this._related.automation.map((automation) => { ? this._related.automation.map((automation) => {
const state = this.hass.states[automation]; const state = this.hass.states[automation];
return state return state
@ -193,8 +196,7 @@ export class HaConfigDevicePage extends LitElement {
"ui.panel.config.devices.automation.no_automations" "ui.panel.config.devices.automation.no_automations"
)}</paper-item )}</paper-item
> >
` `}
}
<div class="card-actions"> <div class="card-actions">
<mwc-button @click=${this._showAutomationDialog}> <mwc-button @click=${this._showAutomationDialog}>
${this.hass.localize( ${this.hass.localize(
@ -203,14 +205,19 @@ export class HaConfigDevicePage extends LitElement {
</mwc-button> </mwc-button>
</div> </div>
</ha-card> </ha-card>
`
: ""
}
</div> </div>
<div class="column"> <div class="column">
${
isComponentLoaded(this.hass, "scene")
? html`
<ha-card <ha-card
.header=${this.hass.localize( .header=${this.hass.localize(
"ui.panel.config.devices.scene.scenes" "ui.panel.config.devices.scene.scenes"
)} )}
>${ >${this._related?.scene?.length
this._related?.scene?.length
? this._related.scene.map((scene) => { ? this._related.scene.map((scene) => {
const state = this.hass.states[scene]; const state = this.hass.states[scene];
return state return state
@ -222,7 +229,8 @@ export class HaConfigDevicePage extends LitElement {
.disabled=${!state.attributes.id} .disabled=${!state.attributes.id}
> >
<paper-item-body> <paper-item-body>
${state.attributes.friendly_name || scene} ${state.attributes.friendly_name ||
scene}
</paper-item-body> </paper-item-body>
<ha-icon-next></ha-icon-next> <ha-icon-next></ha-icon-next>
</paper-item> </paper-item>
@ -245,21 +253,30 @@ export class HaConfigDevicePage extends LitElement {
"ui.panel.config.devices.scene.no_scenes" "ui.panel.config.devices.scene.no_scenes"
)}</paper-item )}</paper-item
> >
` `}
} ${entities.length
? html`
<div class="card-actions"> <div class="card-actions">
<mwc-button @click=${this._createScene}> <mwc-button @click=${this._createScene}>
${this.hass.localize( ${this.hass.localize(
"ui.panel.config.devices.scene.create" "ui.panel.config.devices.scene.create"
)} </mwc-button> )}
</mwc-button>
</div> </div>
`
: ""}
</ha-card> </ha-card>
`
: ""
}
${
isComponentLoaded(this.hass, "script")
? html`
<ha-card <ha-card
.header=${this.hass.localize( .header=${this.hass.localize(
"ui.panel.config.devices.script.scripts" "ui.panel.config.devices.script.scripts"
)} )}
>${ >${this._related?.script?.length
this._related?.script?.length
? this._related.script.map((script) => { ? this._related.script.map((script) => {
const state = this.hass.states[script]; const state = this.hass.states[script];
return state return state
@ -269,7 +286,8 @@ export class HaConfigDevicePage extends LitElement {
@click=${this._openScript} @click=${this._openScript}
> >
<paper-item-body> <paper-item-body>
${state.attributes.friendly_name || script} ${state.attributes.friendly_name ||
script}
</paper-item-body> </paper-item-body>
<ha-icon-next></ha-icon-next> <ha-icon-next></ha-icon-next>
</paper-item> </paper-item>
@ -282,14 +300,18 @@ export class HaConfigDevicePage extends LitElement {
"ui.panel.config.devices.script.no_scripts" "ui.panel.config.devices.script.no_scripts"
)}</paper-item )}</paper-item
> >
` `}
}
<div class="card-actions"> <div class="card-actions">
<mwc-button @click=${this._showScriptDialog}> <mwc-button @click=${this._showScriptDialog}>
${this.hass.localize("ui.panel.config.devices.script.create")} ${this.hass.localize(
"ui.panel.config.devices.script.create"
)}
</mwc-button> </mwc-button>
</div> </div>
</ha-card> </ha-card>
`
: ""
}
</div> </div>
</div> </div>
</div> </div>

View File

@ -50,6 +50,10 @@ class HaConfigScene extends HassRouterPage {
}); });
}); });
public disconnectedCallback() {
super.disconnectedCallback();
}
protected updatePageEl(pageEl, changedProps: PropertyValues) { protected updatePageEl(pageEl, changedProps: PropertyValues) {
pageEl.hass = this.hass; pageEl.hass = this.hass;
pageEl.narrow = this.narrow; pageEl.narrow = this.narrow;
@ -65,6 +69,7 @@ class HaConfigScene extends HassRouterPage {
(!changedProps || changedProps.has("route")) && (!changedProps || changedProps.has("route")) &&
this._currentPage === "edit" this._currentPage === "edit"
) { ) {
pageEl.creatingNew = undefined;
const sceneId = this.routeTail.path.substr(1); const sceneId = this.routeTail.path.substr(1);
pageEl.creatingNew = sceneId === "new" ? true : false; pageEl.creatingNew = sceneId === "new" ? true : false;
pageEl.scene = pageEl.scene =

View File

@ -86,7 +86,7 @@ export class HaSceneEditor extends SubscribeMixin(LitElement) {
@property() private _entityRegistryEntries: EntityRegistryEntry[] = []; @property() private _entityRegistryEntries: EntityRegistryEntry[] = [];
private _storedStates: SceneEntities = {}; private _storedStates: SceneEntities = {};
private _unsubscribeEvents?: () => void; private _unsubscribeEvents?: () => void;
private _deviceEntityLookup: DeviceEntitiesLookup = {}; @property() private _deviceEntityLookup: DeviceEntitiesLookup = {};
private _activateContextId?: string; private _activateContextId?: string;
private _getEntitiesDevices = memoizeOne( private _getEntitiesDevices = memoizeOne(
@ -411,8 +411,8 @@ export class HaSceneEditor extends SubscribeMixin(LitElement) {
entities: {}, entities: {},
...initData, ...initData,
}; };
if (initData) {
this._initEntities(this._config); this._initEntities(this._config);
if (initData) {
this._dirty = true; this._dirty = true;
} }
} }
@ -433,6 +433,12 @@ export class HaSceneEditor extends SubscribeMixin(LitElement) {
) { ) {
this._deviceEntityLookup[entity.device_id].push(entity.entity_id); this._deviceEntityLookup[entity.device_id].push(entity.entity_id);
} }
if (
this._entities.includes(entity.entity_id) &&
!this._devices.includes(entity.device_id)
) {
this._devices = [...this._devices, entity.device_id];
}
} }
} }
} }

View File

@ -1286,7 +1286,8 @@
}, },
"actions": { "actions": {
"caption": "When something is triggered..." "caption": "When something is triggered..."
} },
"no_device_automations": "There are no automations available for this device."
}, },
"script": { "script": {
"scripts": "Scripts", "scripts": "Scripts",