From f76a596572e7f08e483eaaf4cc02c9b003f32d4c Mon Sep 17 00:00:00 2001 From: Johan Frick Date: Tue, 31 Oct 2023 14:41:37 +0100 Subject: [PATCH] Add Mushroom Number Card (#79) A Mushroom Number Card for number and input_number entities. --- README.md | 13 +++++++------ src/cards/NumberCard.js | 37 +++++++++++++++++++++++++++++++++++++ src/cards/typedefs.js | 5 +++++ src/optionDefaults.js | 7 ++++++- 4 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 src/cards/NumberCard.js diff --git a/README.md b/README.md index a7c62ff..4589e95 100644 --- a/README.md +++ b/README.md @@ -316,16 +316,17 @@ The following domains are supported and enabled by default: * media_player * sensor * binary_sensor +* number * default (Miscellaneous) For these domains, the following options are supported: -| Option | type | Description | -|:---------------|:--------|:---------------------------------------------------------------------------| -| `title` | string | Title of the domain in a view. | -| `showControls` | boolean | Weather to show controls int a view, to switch all entities of the domain. | -| `hidden` | boolean | Set to `true` to exclude the view from the dashboard. | -| `order` | number | Ordering position of the domain entities in a view. | +| Option | type | Description | +|:---------------|:--------|:--------------------------------------------------------------------------| +| `title` | string | Title of the domain in a view. | +| `showControls` | boolean | Weather to show controls in a view, to switch all entities of the domain. | +| `hidden` | boolean | Set to `true` to exclude the domain from the dashboard. | +| `order` | number | Ordering position of the domain entities in a view. | #### Example diff --git a/src/cards/NumberCard.js b/src/cards/NumberCard.js new file mode 100644 index 0000000..273c772 --- /dev/null +++ b/src/cards/NumberCard.js @@ -0,0 +1,37 @@ +import {AbstractCard} from "./AbstractCard"; + +/** + * Number Card Class + * + * Used to create a card for controlling an entity of the number domain. + * + * @class + * @extends AbstractCard + */ +class NumberCard extends AbstractCard { + /** + * Default options of the card. + * + * @type {numberCardOptions} + * @private + */ + #defaultOptions = { + type: "custom:mushroom-number-card", + icon: undefined, + }; + + /** + * Class constructor. + * + * @param {hassEntity} entity The hass entity to create a card for. + * @param {numberCardOptions} [options={}] Options for the card. + * @throws {Error} If the Helper module isn't initialized. + */ + constructor(entity, options = {}) { + super(entity); + + this.mergeOptions(this.#defaultOptions, options); + } +} + +export {NumberCard}; diff --git a/src/cards/typedefs.js b/src/cards/typedefs.js index bb031cb..cfe29f3 100644 --- a/src/cards/typedefs.js +++ b/src/cards/typedefs.js @@ -60,6 +60,11 @@ * @memberOf typedefs.cards */ +/** + * @typedef {abstractOptions & Object} numberCardOptions Number Card options. + * @memberOf typedefs.cards + */ + /** * @typedef {abstractOptions & Object} switchCardOptions Switch Card options. * @property {{tap_action: switchTapAction}} [action] Home assistant action to perform on tap. diff --git a/src/optionDefaults.js b/src/optionDefaults.js index 5420797..88acb6f 100644 --- a/src/optionDefaults.js +++ b/src/optionDefaults.js @@ -111,5 +111,10 @@ export const optionDefaults = { showControls: false, hidden: false, }, + number: { + title: "Numbers", + showControls: false, + hidden: false, + }, } -} +};