Skip to content

Commit

Permalink
feat(alarm): show keypad only for disarming
Browse files Browse the repository at this point in the history
  • Loading branch information
rogelio-o committed Oct 25, 2022
1 parent 631b1d9 commit 5a0f502
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
31 changes: 16 additions & 15 deletions docs/cards/alarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ A alarm control panel card allow you to control a alarm panel entity.

All the options are available in the lovelace editor but you can use `yaml` if you want.

| Name | Type | Default | Description |
| :------------------ | :-------------------------------------------------- | :----------------------------- | :---------------------------------------------------------------------------------- |
| `entity` | string | Required | Alarm control panel entity |
| `icon` | string | Optional | Custom icon |
| `name` | string | Optional | Custom name |
| `layout` | string | Optional | Layout of the card. Vertical, horizontal and default layout are supported |
| `fill_container` | boolean | `false` | Fill container or not. Useful when card is in a grid, vertical or horizontal layout |
| `primary_info` | `name` `state` `last-changed` `last-updated` `none` | `name` | Info to show as primary info |
| `secondary_info` | `name` `state` `last-changed` `last-updated` `none` | `state` | Info to show as secondary info |
| `icon_type` | `icon` `entity-picture` `none` | `icon` | Type of icon to display |
| `states` | list | `["armed_home", "armed_away"]` | List of arm states to display |
| `show_keypad` | boolean | `false` | Show the keypad |
| `tap_action` | action | `more-info` | Home assistant action to perform on tap |
| `hold_action` | action | `more-info` | Home assistant action to perform on hold |
| `double_tap_action` | action | `more-info` | Home assistant action to perform on double_tap |
| Name | Type | Default | Description |
| :------------------- | :-------------------------------------------------- | :----------------------------- | :---------------------------------------------------------------------------------- |
| `entity` | string | Required | Alarm control panel entity |
| `icon` | string | Optional | Custom icon |
| `name` | string | Optional | Custom name |
| `layout` | string | Optional | Layout of the card. Vertical, horizontal and default layout are supported |
| `fill_container` | boolean | `false` | Fill container or not. Useful when card is in a grid, vertical or horizontal layout |
| `primary_info` | `name` `state` `last-changed` `last-updated` `none` | `name` | Info to show as primary info |
| `secondary_info` | `name` `state` `last-changed` `last-updated` `none` | `state` | Info to show as secondary info |
| `icon_type` | `icon` `entity-picture` `none` | `icon` | Type of icon to display |
| `states` | list | `["armed_home", "armed_away"]` | List of arm states to display |
| `show_keypad` | boolean | `false` | Show the keypad |
| `show_keypad_disarm` | boolean | `false` | Show the keypad for disarming |
| `tap_action` | action | `more-info` | Home assistant action to perform on tap |
| `hold_action` | action | `more-info` | Home assistant action to perform on hold |
| `double_tap_action` | action | `more-info` | Home assistant action to perform on double_tap |
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type AlarmControlPanelCardConfig = LovelaceCardConfig &
ActionsSharedConfig & {
states?: string[];
show_keypad?: boolean;
show_keypad_disarm?: boolean;
};

export const alarmControlPanelCardCardConfigStruct = assign(
Expand All @@ -22,5 +23,6 @@ export const alarmControlPanelCardCardConfigStruct = assign(
object({
states: optional(array()),
show_keypad: optional(boolean()),
show_keypad_disarm: optional(boolean()),
})
);
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const computeSchema = memoizeOne((localize: LocalizeFunc, icon?: string): HaForm
]) as [string, string][],
},
{ name: "show_keypad", selector: { boolean: {} } },
{ name: "show_keypad_disarm", selector: { boolean: {} } },
...computeActionsFormSchema(actions),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ export class AlarmControlPanelCard extends MushroomBaseCard implements LovelaceC
const entity_id = this._config?.entity;
if (entity_id) {
const entity = this.hass.states[entity_id];
return hasCode(entity) && (this._config?.show_keypad ?? false);
console.log(`Is disarmed: ${isDisarmed(entity)}`);
console.log(`Show keypad disarm: ${this._config?.show_keypad_disarm ?? false}`);
return (
hasCode(entity) &&
((this._config?.show_keypad ?? false) ||
((this._config?.show_keypad_disarm ?? false) && !isDisarmed(entity)))
);
}
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"show_tilt_position_control": "Tilt control?"
},
"alarm_control_panel": {
"show_keypad": "Show keypad"
"show_keypad": "Show keypad",
"show_keypad_disarm": "Show keypad for disarming"
},
"template": {
"primary": "Primary information",
Expand Down Expand Up @@ -160,4 +161,4 @@
}
}
}
}
}
5 changes: 3 additions & 2 deletions src/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"show_position_control": "¿Control de posición?"
},
"alarm_control_panel": {
"show_keypad": "Mostrar teclado"
"show_keypad": "Mostrar teclado",
"show_keypad_disarm": "Mostrar teclado para desarmar"
},
"template": {
"primary": "Información primaria",
Expand Down Expand Up @@ -143,4 +144,4 @@
}
}
}
}
}

0 comments on commit 5a0f502

Please sign in to comment.