From a417df55212d6a067bbce4e05a92e57e5b5e767a Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Sun, 8 May 2022 16:12:28 -0700 Subject: [PATCH] Codereview fixes. --- README.md | 4 +--- src/components/submenu.ts | 16 +++++++++++++--- src/types.ts | 2 -- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 87d60d34..e87481b0 100644 --- a/README.md +++ b/README.md @@ -1252,7 +1252,6 @@ The following will convert this entity into a submenu: [...] elements: - type: custom:frigate-card-menu-submenu-select - icon: mdi:lamps entity: input_select.kitchen_scene ``` @@ -1268,11 +1267,10 @@ elements: scene.kitchen_cooking_scene: icon: mdi:chef-hat title: Cooking time! - scene.kitchen_dining_scene: + scene.kitchen_tv_scene: icon: mdi:television title: TV! ``` - ### Overriding card behavior diff --git a/src/components/submenu.ts b/src/components/submenu.ts index 41b6e3a4..38be9689 100644 --- a/src/components/submenu.ts +++ b/src/components/submenu.ts @@ -131,6 +131,11 @@ export class FrigateCardSubmenuSelect extends LitElement { protected _generatedSubmenu?: MenuSubmenu; + /** + * Called to determine if the update should proceed. + * @param changedProps + * @returns `true` if the update should proceed, `false` otherwise. + */ protected shouldUpdate(changedProps: PropertyValues): boolean { // No need to update the submenu unless the select entity has changed. const oldHass = changedProps.get('hass') as HomeAssistant | undefined; @@ -142,6 +147,9 @@ export class FrigateCardSubmenuSelect extends LitElement { ); } + /** + * Called when the render function will be called. + */ protected willUpdate(): void { if (!this.submenuSelect || !this.hass) { return; @@ -161,15 +169,17 @@ export class FrigateCardSubmenuSelect extends LitElement { // Pull out the dynamic properties (like icon, and title) from the state. ...refreshDynamicStateParameters(this.hass, this.submenuSelect), - + // Override it with anything explicitly set in the submenuSelect. ...this.submenuSelect, type: 'custom:frigate-card-menu-submenu', items: [], - } + }; - // Remove the options parameter which is unused/unsupported in submenu. + // For cleanliness remove the options parameter which is unused by the + // submenu rendering itself (above). It is only in this method to populate + // the items correctly (below). delete submenu['options']; for (const option of options) { diff --git a/src/types.ts b/src/types.ts index b9c2fa27..a78cdcd5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -444,8 +444,6 @@ export type MenuSubmenu = z.infer; const menuSubmenuSelectSchema = menuBaseSchema.merge(stateIconSchema).extend({ type: z.literal('custom:frigate-card-menu-submenu-select'), - // Please ensure additions to this type are filtered out appropriately in - // `submenu.ts` when this is converted to a MenuSubmenu. options: z.record(menuSubmenuItemSchema).optional(), }); export type MenuSubmenuSelect = z.infer;