Add possibility to hide home elements

Elements of the home view can be hidden by listing them at the strategy
options:

```YAML
strategy:
  type: custom:mushroom-strategy
  options:
    homeView:
      hidden:
        - Greeting
        - AreaTitle
views: []
```
---------

Co-authored-by: Johan Frick <johan.frick@gmail.com>
This commit is contained in:
Ferry Cools
2023-10-23 11:51:02 +02:00
committed by GitHub
parent 6922dd4d0f
commit d8274b1272
3 changed files with 118 additions and 38 deletions

View File

@@ -121,7 +121,7 @@ weather entity for the weather chip.
The options available are: The options available are:
| Name | Type | Default | Description | | Name | Type | Default | Description |
|:---------------------|:--------------------------|:--------------------------------------------------------|:---------------------------------------------------------------| |:---------------------|:--------------------------|:--------------------------------------------------------|:-----------------------------------------------------------------------|
| `areas` | object (optional) | unset | One or more areas in a list, see [areas object](#area-object). | | `areas` | object (optional) | unset | One or more areas in a list, see [areas object](#area-object). |
| `card_options` | object (optional) | unset | Card options for cards, see [Card Options](#card-options). | | `card_options` | object (optional) | unset | Card options for cards, see [Card Options](#card-options). |
| `views` | object (optional) | All default views | See available [Pre-built views](#pre-built-views). | | `views` | object (optional) | All default views | See available [Pre-built views](#pre-built-views). |
@@ -130,6 +130,7 @@ The options available are:
| `extra_cards` | array of cards (optional | unset | List of cards to show below room cards. | | `extra_cards` | array of cards (optional | unset | List of cards to show below room cards. |
| `extra_views` | array of views (optional) | unset | List of views to add to the dashboard. | | `extra_views` | array of views (optional) | unset | List of views to add to the dashboard. |
| `domains` | object (optional) | All supported domains | See [Supported domains](#supported-domains). | | `domains` | object (optional) | All supported domains | See [Supported domains](#supported-domains). |
| `homeView` | object (optional) | unset | Options for the home view, see [Home View Options](#home-view-options) |
#### Example #### Example
@@ -343,6 +344,36 @@ strategy:
views: [] views: []
``` ```
### Home View Options
Home View options will let you configure the Home View.
| Option | type | Description |
|:---------|:------|:----------------------------------------------|
| `hidden` | array | Array of elements to hide from the home view. |
#### hidden
The following elements are supported:
* Chips
* Persons
* Greeting
* AreaTitle
* Areas
#### Example
```YAML
strategy:
type: custom:mushroom-strategy
options:
homeView:
hidden:
- Greeting
- AreaTitle
views: []
```
### Chips ### Chips
![Chips](./docs/chips.png) ![Chips](./docs/chips.png)
@@ -402,6 +433,10 @@ strategy:
switches: switches:
hidden: true hidden: true
icon: mdi:toggle-switch icon: mdi:toggle-switch
homeView:
hidden:
- Greeting
- AreaTitle
chips: chips:
weather_entity: weather.forecast_home weather_entity: weather.forecast_home
climate_count: false climate_count: false
@@ -518,6 +553,7 @@ views: []
## Contributors ## Contributors
* [DigiLive](https://github.com/DigiLive) * [DigiLive](https://github.com/DigiLive)
* [Johan Frick](https://github.com/johanfrick)
<!-- Badges References --> <!-- Badges References -->

View File

@@ -119,6 +119,7 @@
* @property {Object[]} [quick_access_cards] List of cards to show between welcome card and rooms cards. * @property {Object[]} [quick_access_cards] List of cards to show between welcome card and rooms cards.
* @property {Object[]} [extra_cards] List of cards to show below room cards. * @property {Object[]} [extra_cards] List of cards to show below room cards.
* @property {Object[]} [extra_views] List of views to add to the dashboard. * @property {Object[]} [extra_views] List of views to add to the dashboard.
* @property {Object.<homeViewOptions>} [homeView] Options for the home view.
* @memberOf typedefs.generic * @memberOf typedefs.generic
*/ */
@@ -134,6 +135,12 @@
* @memberOf typedefs.generic * @memberOf typedefs.generic
*/ */
/**
* @typedef {Object} homeViewOptions Options for the home view.
* @property {string[]} [hidden] Elements to hide from the home view.
* @memberOf typedefs.generic
*/
/** /**
* @typedef {Object} cardOptions Custom card-configuration for an entity. * @typedef {Object} cardOptions Custom card-configuration for an entity.
* @property {string} type Type of card for the entity * @property {string} type Type of card for the entity
@@ -182,7 +189,7 @@
* @property {string} object_id Object ID of entity. * @property {string} object_id Object ID of entity.
* Example: `kitchen`. * Example: `kitchen`.
* @property {string} name Name of the entity. * @property {string} name Name of the entity.
* Based on `friendly_name` attribute with fall back to object ID. * Based on `friendly_name` attribute with fall-back to object ID.
* Example: `Kitchen Ceiling`. * Example: `Kitchen Ceiling`.
* @property {string} last_updated Time the state was written to the state machine in UTC time. * @property {string} last_updated Time the state was written to the state machine in UTC time.
* Note that writing the exact same state including attributes will not result in this * Note that writing the exact same state including attributes will not result in this
@@ -228,7 +235,7 @@
* @typedef {Object} stateContext State context. * @typedef {Object} stateContext State context.
* @property {string} context_id Unique identifier for the context. * @property {string} context_id Unique identifier for the context.
* @property {string} user_id Unique identifier of the user that started the change. * @property {string} user_id Unique identifier of the user that started the change.
* Will be None if action was not started by a user (i.e. started by an automation) * Will be None if action was not started by a user (i.e., started by an automation)
* @property {string} parent_id Unique identifier of the parent context that started the change, if available. * @property {string} parent_id Unique identifier of the parent context that started the change, if available.
* For example, if an automation is triggered, the context of the trigger will be set as * For example, if an automation is triggered, the context of the trigger will be set as
* parent. * parent.

View File

@@ -48,19 +48,36 @@ class HomeView extends AbstractView {
this.#createAreaCards(), this.#createAreaCards(),
]).then(([chips, personCards, areaCards]) => { ]).then(([chips, personCards, areaCards]) => {
const options = Helper.strategyOptions; const options = Helper.strategyOptions;
const homeViewCards = [ const homeViewCards = [];
{
// Add chips to the view.
if (chips.length) {
homeViewCards.push({
type: "custom:mushroom-chips-card", type: "custom:mushroom-chips-card",
alignment: "center", alignment: "center",
chips: chips, chips: chips,
}, });
{ }
// Add persons to the view
if (personCards.length) {
homeViewCards.push({
type: "horizontal-stack", type: "horizontal-stack",
cards: personCards, cards: personCards,
}, });
{ }
// Add greeting to the view if not hidden.
if (!Helper.strategyOptions.homeView?.hidden?.includes("greeting")) {
homeViewCards.push({
type: "custom:mushroom-template-card", type: "custom:mushroom-template-card",
primary: "{% set time = now().hour %} {% if (time >= 18) %} Good Evening, {{user}}! {% elif (time >= 12) %} Good Afternoon, {{user}}! {% elif (time >= 5) %} Good Morning, {{user}}! {% else %} Hello, {{user}}! {% endif %}", primary:
"{% set time = now().hour %}" +
"{% if (time >= 18) %} Good Evening, {{user}}!" +
"{% elif (time >= 12) %} Good Afternoon, {{user}}!" +
"{% elif (time >= 5) %} Good Morning, {{user}}!" +
"{% else %} Hello, {{user}}!" +
"{% endif %}",
icon: "mdi:hand-wave", icon: "mdi:hand-wave",
icon_color: "orange", icon_color: "orange",
tap_action: { tap_action: {
@@ -72,8 +89,8 @@ class HomeView extends AbstractView {
hold_action: { hold_action: {
action: "none", action: "none",
}, },
}, });
]; }
// Add quick access cards. // Add quick access cards.
if (options.quick_access_cards) { if (options.quick_access_cards) {
@@ -101,6 +118,11 @@ class HomeView extends AbstractView {
* @return {Object[]} A chip object array. * @return {Object[]} A chip object array.
*/ */
async #createChips() { async #createChips() {
if (Helper.strategyOptions.homeView?.hidden?.includes("chips")) {
// Chips section is hidden; Return 0 chips.
return [];
}
const chips = []; const chips = [];
const chipOptions = Helper.strategyOptions.chips; const chipOptions = Helper.strategyOptions.chips;
@@ -154,6 +176,11 @@ class HomeView extends AbstractView {
* @return {Object[]} A card object array. * @return {Object[]} A card object array.
*/ */
#createPersonCards() { #createPersonCards() {
if (Helper.strategyOptions.homeView?.hidden?.includes("persons")) {
// Person section is hidden; Return 0 cards.
return [];
}
const cards = []; const cards = [];
import("../cards/PersonCard").then(personModule => { import("../cards/PersonCard").then(personModule => {
@@ -177,6 +204,11 @@ class HomeView extends AbstractView {
* @return {Object[]} A card object array. * @return {Object[]} A card object array.
*/ */
async #createAreaCards() { async #createAreaCards() {
if (Helper.strategyOptions.homeView?.hidden?.includes("areas")) {
// Area section is hidden; Return 0 cards.
return [];
}
/** /**
* Cards to be stacked vertically. * Cards to be stacked vertically.
* *
@@ -184,14 +216,19 @@ class HomeView extends AbstractView {
* *
* @type {[{}]} * @type {[{}]}
*/ */
const groupedCards = [ const groupedCards = [];
{
type: "custom:mushroom-title-card",
title: "Areas",
},
];
let areaCards = []; let areaCards = [];
// Add title to the area section.
if (!Helper.strategyOptions.homeView?.hidden?.includes("areasTitle")) {
groupedCards.push({
type: "custom:mushroom-title-card",
title: "Areas",
});
}
// Add cards to the area section.
for (const [i, area] of Helper.areas.entries()) { for (const [i, area] of Helper.areas.entries()) {
let module; let module;
let moduleName = let moduleName =