Skip to content

Commit

Permalink
Merge branch 'dev' into data_size
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten authored Jan 2, 2023
2 parents 42aca78 + fe87466 commit 8f2f19a
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 67 deletions.
2 changes: 0 additions & 2 deletions demo/src/ha-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class HaDemo extends HomeAssistantAppEl {
entity_category: null,
has_entity_name: false,
unique_id: "co2_intensity",
aliases: [],
},
{
config_entry_id: "co2signal",
Expand All @@ -87,7 +86,6 @@ class HaDemo extends HomeAssistantAppEl {
entity_category: null,
has_entity_name: false,
unique_id: "grid_fossil_fuel_percentage",
aliases: [],
},
]);

Expand Down
1 change: 0 additions & 1 deletion gallery/src/pages/misc/integration-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ const createEntityRegistryEntries = (
platform: "updater",
has_entity_name: false,
unique_id: "updater",
aliases: [],
},
];

Expand Down
2 changes: 1 addition & 1 deletion src/components/entity/state-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class StateInfo extends LitElement {

const name = computeStateName(this.stateObj);

return html` <state-badge
return html`<state-badge
.stateObj=${this.stateObj}
.stateColor=${true}
.color=${this.color}
Expand Down
2 changes: 1 addition & 1 deletion src/data/entity_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export interface EntityRegistryEntry {
original_name?: string;
unique_id: string;
translation_key?: string;
aliases: string[];
}

export interface ExtEntityRegistryEntry extends EntityRegistryEntry {
capabilities: Record<string, unknown>;
original_icon?: string;
device_class?: string;
original_device_class?: string;
aliases: string[];
}

export interface UpdateEntityRegistryEntryResult {
Expand Down
5 changes: 0 additions & 5 deletions src/panels/config/automation/ha-automation-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,15 +541,10 @@ export class HaAutomationTrace extends LitElement {
justify-content: center;
display: flex;
}
.info {
flex: 1;
background-color: var(--card-background-color);
}
.linkButton {
color: var(--primary-text-color);
}
.trace-link {
text-decoration: none;
}
Expand Down
62 changes: 39 additions & 23 deletions src/panels/config/cloud/alexa/cloud-alexa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
mdiFormatListChecks,
mdiSync,
} from "@mdi/js";
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
Expand Down Expand Up @@ -43,20 +42,20 @@ import {
} from "../../../../data/cloud";
import {
EntityRegistryEntry,
subscribeEntityRegistry,
getExtendedEntityRegistryEntry,
updateEntityRegistryEntry,
} from "../../../../data/entity_registry";
import { showDomainTogglerDialog } from "../../../../dialogs/domain-toggler/show-dialog-domain-toggler";
import "../../../../layouts/hass-loading-screen";
import "../../../../layouts/hass-subpage";
import { SubscribeMixin } from "../../../../mixins/subscribe-mixin";
import { haStyle } from "../../../../resources/styles";
import type { HomeAssistant } from "../../../../types";
import { showEntityAliasesDialog } from "../../entities/entity-aliases/show-dialog-entity-aliases";

const DEFAULT_CONFIG_EXPOSE = true;
const IGNORE_INTERFACES = ["Alexa.EndpointHealth"];

@customElement("cloud-alexa")
class CloudAlexa extends SubscribeMixin(LitElement) {
class CloudAlexa extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;

@property()
Expand Down Expand Up @@ -171,10 +170,17 @@ class CloudAlexa extends SubscribeMixin(LitElement) {
secondary-line
@click=${this._showMoreInfo}
>
${entity.interfaces
.filter((ifc) => !IGNORE_INTERFACES.includes(ifc))
.map((ifc) => ifc.replace(/(Alexa.|Controller)/g, ""))
.join(", ")}
${entity.entity_id in this.hass.entities
? html`<button
class="link"
.entityId=${entity.entity_id}
@click=${this._openAliasesSettings}
>
${this.hass.localize(
"ui.panel.config.cloud.alexa.manage_aliases"
)}
</button>`
: ""}
</state-info>
${!emptyFilter
? html`${iconButton}`
Expand Down Expand Up @@ -323,23 +329,33 @@ class CloudAlexa extends SubscribeMixin(LitElement) {
if (changedProps.has("cloudStatus")) {
this._entityConfigs = this.cloudStatus.prefs.alexa_entity_configs;
}
}
if (
changedProps.has("hass") &&
changedProps.get("hass")?.entities !== this.hass.entities
) {
const categories = {};

protected override hassSubscribe(): (
| UnsubscribeFunc
| Promise<UnsubscribeFunc>
)[] {
return [
subscribeEntityRegistry(this.hass.connection, (entries) => {
const categories = {};
for (const entry of Object.values(this.hass.entities)) {
categories[entry.entity_id] = entry.entity_category;
}

for (const entry of entries) {
categories[entry.entity_id] = entry.entity_category;
}
this._entityCategories = categories;
}
}

this._entityCategories = categories;
}),
];
private async _openAliasesSettings(ev) {
ev.stopPropagation();
const entityId = ev.target.entityId;
const entry = await getExtendedEntityRegistryEntry(this.hass, entityId);
if (!entry) {
return;
}
showEntityAliasesDialog(this, {
entity: entry,
updateEntry: async (updates) => {
await updateEntityRegistryEntry(this.hass, entry.entity_id, updates);
},
});
}

private async _fetchData() {
Expand Down
69 changes: 44 additions & 25 deletions src/panels/config/cloud/google-assistant/cloud-google-assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
mdiFormatListChecks,
mdiSync,
} from "@mdi/js";
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
Expand Down Expand Up @@ -41,7 +40,8 @@ import {
} from "../../../../data/cloud";
import {
EntityRegistryEntry,
subscribeEntityRegistry,
getExtendedEntityRegistryEntry,
updateEntityRegistryEntry,
} from "../../../../data/entity_registry";
import {
fetchCloudGoogleEntities,
Expand All @@ -51,15 +51,15 @@ import { showDomainTogglerDialog } from "../../../../dialogs/domain-toggler/show
import { showAlertDialog } from "../../../../dialogs/generic/show-dialog-box";
import "../../../../layouts/hass-loading-screen";
import "../../../../layouts/hass-subpage";
import { SubscribeMixin } from "../../../../mixins/subscribe-mixin";
import { haStyle } from "../../../../resources/styles";
import { buttonLinkStyle, haStyle } from "../../../../resources/styles";
import type { HomeAssistant } from "../../../../types";
import { showToast } from "../../../../util/toast";
import { showEntityAliasesDialog } from "../../entities/entity-aliases/show-dialog-entity-aliases";

const DEFAULT_CONFIG_EXPOSE = true;

@customElement("cloud-google-assistant")
class CloudGoogleAssistant extends SubscribeMixin(LitElement) {
class CloudGoogleAssistant extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;

@property() public cloudStatus!: CloudStatusLoggedIn;
Expand Down Expand Up @@ -174,15 +174,23 @@ class CloudGoogleAssistant extends SubscribeMixin(LitElement) {
secondary-line
@click=${this._showMoreInfo}
>
${entity.traits
.map((trait) => trait.substr(trait.lastIndexOf(".") + 1))
.join(", ")}
${entity.entity_id in this.hass.entities
? html`<button
class="link"
.entityId=${entity.entity_id}
@click=${this._openAliasesSettings}
>
${this.hass.localize(
"ui.panel.config.cloud.google.manage_aliases"
)}
</button>`
: ""}
</state-info>
${!emptyFilter
? html`${iconButton}`
: html`<ha-button-menu
corner="BOTTOM_START"
.entityId=${stateObj.entity_id}
.entityId=${entity.entity_id}
@action=${this._exposeChanged}
>
${iconButton}
Expand Down Expand Up @@ -308,7 +316,7 @@ class CloudGoogleAssistant extends SubscribeMixin(LitElement) {
</h3>
${!this.narrow
? this.hass!.localize(
"ui.panel.config.cloud.alexa.exposed",
"ui.panel.config.cloud.google.exposed",
"selected",
selected
)
Expand All @@ -329,7 +337,7 @@ class CloudGoogleAssistant extends SubscribeMixin(LitElement) {
</h3>
${!this.narrow
? this.hass!.localize(
"ui.panel.config.cloud.alexa.not_exposed",
"ui.panel.config.cloud.google.not_exposed",
"selected",
this._entities.length - selected
)
Expand All @@ -354,23 +362,33 @@ class CloudGoogleAssistant extends SubscribeMixin(LitElement) {
if (changedProps.has("cloudStatus")) {
this._entityConfigs = this.cloudStatus.prefs.google_entity_configs;
}
}
if (
changedProps.has("hass") &&
changedProps.get("hass")?.entities !== this.hass.entities
) {
const categories = {};

protected override hassSubscribe(): (
| UnsubscribeFunc
| Promise<UnsubscribeFunc>
)[] {
return [
subscribeEntityRegistry(this.hass.connection, (entries) => {
const categories = {};
for (const entry of Object.values(this.hass.entities)) {
categories[entry.entity_id] = entry.entity_category;
}

for (const entry of entries) {
categories[entry.entity_id] = entry.entity_category;
}
this._entityCategories = categories;
}
}

this._entityCategories = categories;
}),
];
private async _openAliasesSettings(ev) {
ev.stopPropagation();
const entityId = ev.target.entityId;
const entry = await getExtendedEntityRegistryEntry(this.hass, entityId);
if (!entry) {
return;
}
showEntityAliasesDialog(this, {
entity: entry,
updateEntry: async (updates) => {
await updateEntityRegistryEntry(this.hass, entry.entity_id, updates);
},
});
}

private _configIsDomainExposed(
Expand Down Expand Up @@ -583,6 +601,7 @@ class CloudGoogleAssistant extends SubscribeMixin(LitElement) {
static get styles(): CSSResultGroup {
return [
haStyle,
buttonLinkStyle,
css`
mwc-list-item > [slot="meta"] {
margin-left: 4px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { fireEvent } from "../../../../common/dom/fire_event";
import {
EntityRegistryEntry,
EntityRegistryEntryUpdateParams,
ExtEntityRegistryEntry,
} from "../../../../data/entity_registry";

export interface EntityAliasesDialogParams {
entity: EntityRegistryEntry;
entity: ExtEntityRegistryEntry;
updateEntry: (
updates: Partial<EntityRegistryEntryUpdateParams>
) => Promise<unknown>;
Expand Down
13 changes: 13 additions & 0 deletions src/panels/config/entities/entity-registry-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ const OVERRIDE_NUMBER_UNITS = {

const OVERRIDE_SENSOR_UNITS = {
current: ["A", "mA"],
data_rate: [
"bit/s",
"kbit/s",
"Mbit/s",
"Gbit/s",
"B/s",
"kB/s",
"MB/s",
"GB/s",
"KiB/s",
"MiB/s",
"GiB/s",
],
data_size: [
"bit",
"kbit",
Expand Down
1 change: 0 additions & 1 deletion src/panels/config/entities/ha-config-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,6 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
selectable: false,
entity_category: null,
has_entity_name: false,
aliases: [],
});
}
if (changed) {
Expand Down
5 changes: 0 additions & 5 deletions src/panels/config/script/ha-script-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,15 +527,10 @@ export class HaScriptTrace extends LitElement {
:host([narrow]) .graph {
max-width: 100%;
}
.info {
flex: 1;
background-color: var(--card-background-color);
}
.linkButton {
color: var(--primary-text-color);
}
.trace-link {
text-decoration: none;
}
Expand Down
4 changes: 3 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2634,7 +2634,7 @@
"enable_state_reporting": "Enable State Reporting",
"info_state_reporting": "If you enable state reporting, Home Assistant will send all state changes of exposed entities to Amazon. This allows you to always see the latest states in the Alexa app and use the state changes to create routines.",
"state_reporting_error": "Unable to {enable_disable} report state.",
"manage_entities": "Manage Entities",
"manage_entities": "[%key:ui::panel::config::cloud::account::google::manage_entities%]",
"enable": "enable",
"disable": "disable",
"not_configured_title": "Alexa is not activated",
Expand Down Expand Up @@ -2685,6 +2685,7 @@
"follow_domain": "[%key:ui::panel::config::cloud::google::follow_domain%]",
"exposed": "[%key:ui::panel::config::cloud::google::exposed%]",
"not_exposed": "[%key:ui::panel::config::cloud::google::not_exposed%]",
"manage_aliases": "[%key:ui::panel::config::cloud::google::manage_aliases%]",
"expose": "Expose to Alexa",
"sync_entities": "Synchronize entities",
"sync_entities_error": "Failed to sync entities:"
Expand All @@ -2710,6 +2711,7 @@
"follow_domain": "Follow domain",
"exposed": "{selected} exposed",
"not_exposed": "{selected} not exposed",
"manage_aliases": "Manage aliases",
"sync_to_google": "Synchronizing changes to Google.",
"sync_entities": "Synchronize entities",
"sync_entities_error": "Failed to sync entities:",
Expand Down

0 comments on commit 8f2f19a

Please sign in to comment.