@@ -19,13 +19,11 @@ import {
1919 mdiTextBoxOutline ,
2020 mdiWrench ,
2121} from "@mdi/js" ;
22- import type { PropertyValues , TemplateResult } from "lit" ;
22+ import type { TemplateResult } from "lit" ;
2323import { css , html , LitElement , nothing } from "lit" ;
2424import { customElement , property , state } from "lit/decorators" ;
2525import { classMap } from "lit/directives/class-map" ;
2626import memoizeOne from "memoize-one" ;
27- import { computeDeviceNameDisplay } from "../../../common/entity/compute_device_name" ;
28- import { caseInsensitiveStringCompare } from "../../../common/string/compare" ;
2927import { copyToClipboard } from "../../../common/util/copy-clipboard" ;
3028import "../../../components/ha-dropdown" ;
3129import type { HaDropdownSelectEvent } from "../../../components/ha-dropdown" ;
@@ -35,22 +33,16 @@ import {
3533 fetchApplicationCredentialsConfigEntry ,
3634} from "../../../data/application_credential" ;
3735import { getSignedPath } from "../../../data/auth" ;
38- import type {
39- ConfigEntry ,
40- DisableConfigEntryResult ,
41- SubEntry ,
42- } from "../../../data/config_entries" ;
36+ import type { DisableConfigEntryResult } from "../../../data/config_entries" ;
4337import {
4438 deleteConfigEntry ,
4539 disableConfigEntry ,
4640 enableConfigEntry ,
4741 ERROR_STATES ,
48- getSubEntries ,
4942 RECOVERABLE_STATES ,
5043 reloadConfigEntry ,
5144 updateConfigEntry ,
5245} from "../../../data/config_entries" ;
53- import type { DeviceRegistryEntry } from "../../../data/device/device_registry" ;
5446import type { DiagnosticInfo } from "../../../data/diagnostics" ;
5547import { getConfigEntryDiagnosticsDownloadUrl } from "../../../data/diagnostics" ;
5648import type { EntityRegistryEntry } from "../../../data/entity/entity_registry" ;
@@ -75,7 +67,10 @@ import {
7567 showPromptDialog ,
7668} from "../../lovelace/custom-card-helpers" ;
7769import "./ha-config-entry-device-row" ;
78- import { renderConfigEntryError } from "./ha-config-integration-page" ;
70+ import {
71+ renderConfigEntryError ,
72+ type ConfigEntryData ,
73+ } from "./ha-config-integration-page" ;
7974import "./ha-config-sub-entry-row" ;
8075
8176@customElement ( "ha-config-entry-row" )
@@ -90,22 +85,14 @@ export class HaConfigEntryRow extends LitElement {
9085
9186 @property ( { attribute : false } ) public entities ! : EntityRegistryEntry [ ] ;
9287
93- @property ( { attribute : false } ) public entry ! : ConfigEntry ;
88+ @property ( { attribute : false } ) public data ! : ConfigEntryData ;
9489
9590 @state ( ) private _expanded = true ;
9691
9792 @state ( ) private _devicesExpanded = true ;
9893
99- @state ( ) private _subEntries ?: SubEntry [ ] ;
100-
101- protected willUpdate ( changedProperties : PropertyValues ) : void {
102- if ( changedProperties . has ( "entry" ) ) {
103- this . _fetchSubEntries ( ) ;
104- }
105- }
106-
10794 protected render ( ) {
108- const item = this . entry ;
95+ const item = this . data . entry ;
10996
11097 let stateText : Parameters < typeof this . hass . localize > | undefined ;
11198 let stateTextExtra : TemplateResult | string | undefined ;
@@ -128,15 +115,17 @@ export class HaConfigEntryRow extends LitElement {
128115 stateTextExtra = renderConfigEntryError ( this . hass , item ) ;
129116 }
130117
131- const devices = this . _getDevices ( ) ;
132- const services = this . _getServices ( ) ;
133118 const entities = this . _getEntities ( ) ;
119+ const ownDevices = [ ...this . data . devices , ...this . data . services ] ;
134120
135- const ownDevices = [ ...devices , ...services ] . filter (
136- ( device ) =>
137- ! device . config_entries_subentries [ item . entry_id ] . length ||
138- device . config_entries_subentries [ item . entry_id ] [ 0 ] === null
139- ) ;
121+ const allDevices = [
122+ ...this . data . devices ,
123+ ...this . data . subEntries . flatMap ( ( s ) => s . devices ) ,
124+ ] ;
125+ const allServices = [
126+ ...this . data . services ,
127+ ...this . data . subEntries . flatMap ( ( s ) => s . services ) ,
128+ ] ;
140129
141130 const statusLine : ( TemplateResult | string ) [ ] = [ ] ;
142131
@@ -158,7 +147,7 @@ export class HaConfigEntryRow extends LitElement {
158147 "ui.panel.config.integrations.config_entry.disable_restart_confirm"
159148 ) } .`) ;
160149 }
161- } else if ( ! devices . length && ! services . length && entities . length ) {
150+ } else if ( ! allDevices . length && ! allServices . length && entities . length ) {
162151 statusLine . push (
163152 html `<a
164153 href= ${ `/config/entities/?historyBack=1&config_entry=${ item . entry_id } ` }
@@ -172,7 +161,7 @@ export class HaConfigEntryRow extends LitElement {
172161
173162 const configPanel = this . _configPanel ( item . domain , this . hass . panels ) ;
174163
175- const subEntries = this . _subEntries || [ ] ;
164+ const subEntries = this . data . subEntries ;
176165
177166 return html `<ha- md- lis t>
178167 <ha- md- lis t- item
@@ -246,29 +235,29 @@ export class HaConfigEntryRow extends LitElement {
246235 .label = ${ this . hass . localize ( "ui.common.menu" ) }
247236 .path = ${ mdiDotsVertical }
248237 > </ ha- icon- butto n>
249- ${ devices . length
238+ ${ allDevices . length
250239 ? html `
251240 <a
252- href= ${ devices . length === 1
253- ? `/config/devices/device/${ devices [ 0 ] . id } `
241+ href= ${ allDevices . length === 1
242+ ? `/config/devices/device/${ allDevices [ 0 ] . id } `
254243 : `/config/devices/dashboard?historyBack=1&config_entry=${ item . entry_id } ` }
255244 >
256245 <ha- dropdown- item value= "devices" >
257246 <ha- svg- icon .path = ${ mdiDevices } slot= "icon"> </ ha- svg- icon>
258247 ${ this . hass . localize (
259248 `ui.panel.config.integrations.config_entry.devices` ,
260- { count : devices . length }
249+ { count : allDevices . length }
261250 ) }
262251 <ha- icon- next slot= "details" > </ ha- icon- next>
263252 </ ha- dropdown- item>
264253 </ a>
265254 `
266255 : nothing }
267- ${ services . length
256+ ${ allServices . length
268257 ? html `
269258 <a
270- href= ${ services . length === 1
271- ? `/config/devices/device/${ services [ 0 ] . id } `
259+ href= ${ allServices . length === 1
260+ ? `/config/devices/device/${ allServices [ 0 ] . id } `
272261 : `/config/devices/dashboard?historyBack=1&config_entry=${ item . entry_id } ` }
273262 >
274263 <ha- dropdown- item value= "services" >
@@ -278,7 +267,7 @@ export class HaConfigEntryRow extends LitElement {
278267 > </ ha- svg- icon>
279268 ${ this . hass . localize (
280269 `ui.panel.config.integrations.config_entry.services` ,
281- { count : services . length }
270+ { count : allServices . length }
282271 ) }
283272 <ha- icon- next slot= "details" > </ ha- icon- next>
284273 </ ha- dropdown- item>
@@ -466,15 +455,15 @@ export class HaConfigEntryRow extends LitElement {
466455 </ ha- md- lis t> `
467456 : nothing }
468457 ${ subEntries . map (
469- ( subEntry ) => html `
458+ ( subEntryData ) => html `
470459 <ha- config- sub- entry- row
471460 .hass = ${ this . hass }
472461 .narrow = ${ this . narrow }
473462 .manifest = ${ this . manifest }
474463 .diagnosticHandler = ${ this . diagnosticHandler }
475464 .entities = ${ this . entities }
476465 .entry = ${ item }
477- .subEntry = ${ subEntry }
466+ .data = ${ subEntryData }
478467 data- entry- id= ${ item . entry_id }
479468 > </ ha- config- sub- entry- row>
480469 `
@@ -495,18 +484,6 @@ export class HaConfigEntryRow extends LitElement {
495484 </ ha- md- lis t> ` ;
496485 }
497486
498- private async _fetchSubEntries ( ) {
499- this . _subEntries = this . entry . num_subentries
500- ? ( await getSubEntries ( this . hass , this . entry . entry_id ) ) . sort ( ( a , b ) =>
501- caseInsensitiveStringCompare (
502- a . title ,
503- b . title ,
504- this . hass . locale . language
505- )
506- )
507- : undefined ;
508- }
509-
510487 private _configPanel = memoizeOne (
511488 ( domain : string , panels : HomeAssistant [ "panels" ] ) : string | undefined =>
512489 Object . values ( panels ) . find (
@@ -516,39 +493,9 @@ export class HaConfigEntryRow extends LitElement {
516493
517494 private _getEntities = ( ) : EntityRegistryEntry [ ] =>
518495 this . entities . filter (
519- ( entity ) => entity . config_entry_id === this . entry . entry_id
496+ ( entity ) => entity . config_entry_id === this . data . entry . entry_id
520497 ) ;
521498
522- private _getDevices = ( ) : DeviceRegistryEntry [ ] =>
523- Object . values ( this . hass . devices )
524- . filter (
525- ( device ) =>
526- device . config_entries . includes ( this . entry . entry_id ) &&
527- device . entry_type !== "service"
528- )
529- . sort ( ( a , b ) =>
530- caseInsensitiveStringCompare (
531- computeDeviceNameDisplay ( a , this . hass . localize , this . hass . states ) ,
532- computeDeviceNameDisplay ( b , this . hass . localize , this . hass . states ) ,
533- this . hass . locale . language
534- )
535- ) ;
536-
537- private _getServices = ( ) : DeviceRegistryEntry [ ] =>
538- Object . values ( this . hass . devices )
539- . filter (
540- ( device ) =>
541- device . config_entries . includes ( this . entry . entry_id ) &&
542- device . entry_type === "service"
543- )
544- . sort ( ( a , b ) =>
545- caseInsensitiveStringCompare (
546- computeDeviceNameDisplay ( a , this . hass . localize , this . hass . states ) ,
547- computeDeviceNameDisplay ( b , this . hass . localize , this . hass . states ) ,
548- this . hass . locale . language
549- )
550- ) ;
551-
552499 private _toggleExpand ( ) {
553500 this . _expanded = ! this . _expanded ;
554501 }
@@ -600,7 +547,7 @@ export class HaConfigEntryRow extends LitElement {
600547 } ;
601548
602549 private _showOptions ( ) {
603- showOptionsFlowDialog ( this , this . entry , { manifest : this . manifest } ) ;
550+ showOptionsFlowDialog ( this , this . data . entry , { manifest : this . manifest } ) ;
604551 }
605552
606553 // Return an application credentials id for this config entry to prompt the
@@ -665,7 +612,7 @@ export class HaConfigEntryRow extends LitElement {
665612 }
666613
667614 private _handleReload = async ( ) => {
668- const result = await reloadConfigEntry ( this . hass , this . entry . entry_id ) ;
615+ const result = await reloadConfigEntry ( this . hass , this . data . entry . entry_id ) ;
669616 const locale_key = result . require_restart
670617 ? "reload_restart_confirm"
671618 : "reload_confirm" ;
@@ -678,16 +625,19 @@ export class HaConfigEntryRow extends LitElement {
678625
679626 private _handleReconfigure = async ( ) => {
680627 showConfigFlowDialog ( this , {
681- startFlowHandler : this . entry . domain ,
628+ startFlowHandler : this . data . entry . domain ,
682629 showAdvanced : this . hass . userData ?. showAdvanced ,
683- manifest : await fetchIntegrationManifest ( this . hass , this . entry . domain ) ,
684- entryId : this . entry . entry_id ,
630+ manifest : await fetchIntegrationManifest (
631+ this . hass ,
632+ this . data . entry . domain
633+ ) ,
634+ entryId : this . data . entry . entry_id ,
685635 navigateToResult : true ,
686636 } ) ;
687637 } ;
688638
689639 private _handleCopy = async ( ) => {
690- await copyToClipboard ( this . entry . entry_id ) ;
640+ await copyToClipboard ( this . data . entry . entry_id ) ;
691641 showToast ( this , {
692642 message :
693643 this . hass ?. localize ( "ui.common.copied_clipboard" ) ||
@@ -698,15 +648,15 @@ export class HaConfigEntryRow extends LitElement {
698648 private _handleRename = async ( ) => {
699649 const newName = await showPromptDialog ( this , {
700650 title : this . hass . localize ( "ui.panel.config.integrations.rename_dialog" ) ,
701- defaultValue : this . entry . title ,
651+ defaultValue : this . data . entry . title ,
702652 inputLabel : this . hass . localize (
703653 "ui.panel.config.integrations.rename_input_label"
704654 ) ,
705655 } ) ;
706656 if ( newName === null ) {
707657 return ;
708658 }
709- await updateConfigEntry ( this . hass , this . entry . entry_id , {
659+ await updateConfigEntry ( this . hass , this . data . entry . entry_id , {
710660 title : newName ,
711661 } ) ;
712662 } ;
@@ -722,12 +672,12 @@ export class HaConfigEntryRow extends LitElement {
722672 }
723673
724674 private _handleDisable = async ( ) => {
725- const entryId = this . entry . entry_id ;
675+ const entryId = this . data . entry . entry_id ;
726676
727677 const confirmed = await showConfirmationDialog ( this , {
728678 title : this . hass . localize (
729679 "ui.panel.config.integrations.config_entry.disable_confirm_title" ,
730- { title : this . entry . title }
680+ { title : this . data . entry . title }
731681 ) ,
732682 text : this . hass . localize (
733683 "ui.panel.config.integrations.config_entry.disable_confirm_text"
@@ -762,7 +712,7 @@ export class HaConfigEntryRow extends LitElement {
762712 } ;
763713
764714 private _handleEnable = async ( ) => {
765- const entryId = this . entry . entry_id ;
715+ const entryId = this . data . entry . entry_id ;
766716
767717 let result : DisableConfigEntryResult ;
768718 try {
@@ -787,15 +737,15 @@ export class HaConfigEntryRow extends LitElement {
787737 } ;
788738
789739 private _handleDelete = async ( ) => {
790- const entryId = this . entry . entry_id ;
740+ const entryId = this . data . entry . entry_id ;
791741
792742 const applicationCredentialsId =
793743 await this . _applicationCredentialForRemove ( entryId ) ;
794744
795745 const confirmed = await showConfirmationDialog ( this , {
796746 title : this . hass . localize (
797747 "ui.panel.config.integrations.config_entry.delete_confirm_title" ,
798- { title : this . entry . title }
748+ { title : this . data . entry . title }
799749 ) ,
800750 text : this . hass . localize (
801751 "ui.panel.config.integrations.config_entry.delete_confirm_text"
@@ -824,14 +774,14 @@ export class HaConfigEntryRow extends LitElement {
824774
825775 private _handleSystemOptions = ( ) => {
826776 showConfigEntrySystemOptionsDialog ( this , {
827- entry : this . entry ,
777+ entry : this . data . entry ,
828778 manifest : this . manifest ,
829779 } ) ;
830780 } ;
831781
832782 private _addSubEntry = ( flowType : string ) => {
833- showSubConfigFlowDialog ( this , this . entry , flowType , {
834- startFlowHandler : this . entry . entry_id ,
783+ showSubConfigFlowDialog ( this , this . data . entry , flowType , {
784+ startFlowHandler : this . data . entry . entry_id ,
835785 } ) ;
836786 } ;
837787
0 commit comments