Skip to content

Commit

Permalink
Select card fixes (#941)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Jan 10, 2023
1 parent 3945c82 commit 7ed1e46
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .hass_dev/lovelace-mushroom-showcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ views:
- !include views/media-player-view.yaml
- !include views/vacuum-view.yaml
- !include views/lock-view.yaml
- !include views/humidifier-view.yaml
- !include views/humidifier-view.yaml
- !include views/select-view.yaml
13 changes: 13 additions & 0 deletions .hass_dev/packages/select.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
input_select:
who_cooks:
name: Who cooks today
options:
- Paulus
- Anne Therese
initial: Anne Therese
icon: mdi:panda
living_room_preset:
options:
- Visitors
- Visitors with kids
- Home Alone
68 changes: 68 additions & 0 deletions .hass_dev/views/select-view.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
title: Select
icon: mdi:form-dropdown
cards:
- type: grid
title: Basic
cards:
- type: custom:mushroom-select-card
entity: input_select.who_cooks
- type: custom:mushroom-select-card
entity: input_select.who_cooks
name: Custom name and icon
icon: mdi:robot-outline
columns: 2
square: false
- type: grid
title: Infos
cards:
- type: custom:mushroom-select-card
entity: input_select.who_cooks
primary_info: state
secondary_info: name
- type: custom:mushroom-select-card
entity: input_select.who_cooks
primary_info: name
secondary_info: last-changed
- type: custom:mushroom-select-card
entity: input_select.who_cooks
primary_info: name
secondary_info: last-updated
- type: custom:mushroom-select-card
entity: input_select.who_cooks
primary_info: name
secondary_info: none
- type: custom:mushroom-select-card
entity: input_select.who_cooks
icon_type: none
columns: 2
square: false
- type: grid
title: Icon colors
cards:
- type: custom:mushroom-select-card
entity: input_select.who_cooks
icon_color: red
- type: custom:mushroom-select-card
entity: input_select.who_cooks
icon_color: green
columns: 2
square: false
- type: vertical-stack
title: Layout
cards:
- type: grid
columns: 2
square: false
cards:
- type: custom:mushroom-select-card
entity: input_select.who_cooks
- type: grid
columns: 2
square: false
cards:
- type: custom:mushroom-select-card
entity: input_select.who_cooks
layout: "vertical"
- type: custom:mushroom-select-card
entity: input_select.who_cooks
layout: "horizontal"
8 changes: 4 additions & 4 deletions src/cards/select-card/select-card-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { SelectCardConfig, selectCardConfigStruct } from "./select-card-config";

const actions: UiAction[] = ["more-info", "navigate", "url", "call-service", "none"];

const computeSchema = memoizeOne((version: string, icon?: string): HaFormSchema[] => [
const computeSchema = memoizeOne((icon?: string): HaFormSchema[] => [
{ name: "entity", selector: { entity: { domain: SELECT_ENTITY_DOMAINS} } },
{ name: "name", selector: { text: {} } },
{
Expand All @@ -29,7 +29,7 @@ const computeSchema = memoizeOne((version: string, icon?: string): HaFormSchema[
],
},
...APPEARANCE_FORM_SCHEMA,
...computeActionsFormSchema(version, actions),
...computeActionsFormSchema(actions),
]);

@customElement(SELECT_CARD_EDITOR_NAME)
Expand All @@ -38,7 +38,7 @@ export class SelectCardEditor extends MushroomBaseElement implements LovelaceCar

connectedCallback() {
super.connectedCallback();
void loadHaComponents(this.hass.connection.haVersion);
void loadHaComponents();
}

public setConfig(config: SelectCardConfig): void {
Expand All @@ -63,7 +63,7 @@ export class SelectCardEditor extends MushroomBaseElement implements LovelaceCar
const entityState = this._config.entity ? this.hass.states[this._config.entity] : undefined;
const entityIcon = entityState ? stateIcon(entityState) : undefined;
const icon = this._config.icon || entityIcon;
const schema = computeSchema(this.hass.connection.haVersion, icon);
const schema = computeSchema(icon);

return html`
<ha-form
Expand Down

0 comments on commit 7ed1e46

Please sign in to comment.