Codereview fixes.

This commit is contained in:
Dermot Duffy
2022-05-08 16:12:28 -07:00
parent 28292483fc
commit a417df5521
3 changed files with 14 additions and 8 deletions
+1 -3
View File
@@ -1252,7 +1252,6 @@ The following will convert this entity into a submenu:
[...] [...]
elements: elements:
- type: custom:frigate-card-menu-submenu-select - type: custom:frigate-card-menu-submenu-select
icon: mdi:lamps
entity: input_select.kitchen_scene entity: input_select.kitchen_scene
``` ```
@@ -1268,11 +1267,10 @@ elements:
scene.kitchen_cooking_scene: scene.kitchen_cooking_scene:
icon: mdi:chef-hat icon: mdi:chef-hat
title: Cooking time! title: Cooking time!
scene.kitchen_dining_scene: scene.kitchen_tv_scene:
icon: mdi:television icon: mdi:television
title: TV! title: TV!
``` ```
</details> </details>
### Overriding card behavior ### Overriding card behavior
+13 -3
View File
@@ -131,6 +131,11 @@ export class FrigateCardSubmenuSelect extends LitElement {
protected _generatedSubmenu?: MenuSubmenu; 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 { protected shouldUpdate(changedProps: PropertyValues): boolean {
// No need to update the submenu unless the select entity has changed. // No need to update the submenu unless the select entity has changed.
const oldHass = changedProps.get('hass') as HomeAssistant | undefined; 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 { protected willUpdate(): void {
if (!this.submenuSelect || !this.hass) { if (!this.submenuSelect || !this.hass) {
return; return;
@@ -161,15 +169,17 @@ export class FrigateCardSubmenuSelect extends LitElement {
// Pull out the dynamic properties (like icon, and title) from the state. // Pull out the dynamic properties (like icon, and title) from the state.
...refreshDynamicStateParameters(this.hass, this.submenuSelect), ...refreshDynamicStateParameters(this.hass, this.submenuSelect),
// Override it with anything explicitly set in the submenuSelect. // Override it with anything explicitly set in the submenuSelect.
...this.submenuSelect, ...this.submenuSelect,
type: 'custom:frigate-card-menu-submenu', type: 'custom:frigate-card-menu-submenu',
items: [], 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']; delete submenu['options'];
for (const option of options) { for (const option of options) {
-2
View File
@@ -444,8 +444,6 @@ export type MenuSubmenu = z.infer<typeof menuSubmenuSchema>;
const menuSubmenuSelectSchema = menuBaseSchema.merge(stateIconSchema).extend({ const menuSubmenuSelectSchema = menuBaseSchema.merge(stateIconSchema).extend({
type: z.literal('custom:frigate-card-menu-submenu-select'), 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(), options: z.record(menuSubmenuItemSchema).optional(),
}); });
export type MenuSubmenuSelect = z.infer<typeof menuSubmenuSelectSchema>; export type MenuSubmenuSelect = z.infer<typeof menuSubmenuSelectSchema>;