forked from DigiLive/mushroom-strategy
Refactor the code base from Procedural to Object-Oriented Programming. The new code base requires webpack (https://webpack.js.org/) to bundle the code into a single javascript file. Webpack can be installed with npm, using file `package-lock.json` or `package.json`. File `package.json` contains two script entries: * `build` for a *release* build (uses file`webpack.config.js`). * `build-dev` for a *debug* build (uses file `webpack.dev.config.js`). Both of the scripts will bundle the separate package files into a single javascript file in the `dist` directory. Includes fixes and changes: * The release badge in readme now displays the latest release version. * Optimize function `getStateEntities()`. * Implement #11. * Merge Home Assistant and User-defined areas. * Add contributors to readme. * Fix getCountTemplate method. The method only counted states which aren't equal to value `off`. States are now counted by specifying a comparison operator and value. * Document default HACS installation. * Fix overriding sensor card configuration. Having an `entity_config` property in the strategy options resulted in overriding each sensor card. Only the cards listed under this property should be overridden. * Cut redundant properties and constants Method `generateDashboard()` passes redundant values to generateView(). Writing those values into properties and reading them into constants is removed. * Fix undefined sensorState. Not all entities (like a RESTful sensor) are bound to a device. SensorStates did contain states which meet all following conditions: 1. The linked entity is linked to the given area or isn't linked to any area. 2. The linked device is linked to the given area. SensorStates now contains states which meet any* of the following conditions: 1. The linked entity is linked to the given area or isn't linked to any area. 2. The entity is linked to a device, and the linked device is linked to the given area. *) Whichever comes first. * Add undisclosed area. * Add ordering of area-cards. Area cards are now ordered by a custom set position first and then by the area name. * Add global sorting of entities by original_name. * Add global sorting of areas by order and name. * Add global sorting of domains by order and title. * Make production build. Known Issue: Title cards or chips won't switch entities assigned to the undisclosed area.
43 lines
865 B
JavaScript
43 lines
865 B
JavaScript
import {AbstractCard} from "./AbstractCard";
|
|
|
|
/**
|
|
* Switch Card Class
|
|
*
|
|
* Used to create a card for controlling an entity of the switch domain.
|
|
*
|
|
* @class
|
|
* @extends AbstractCard
|
|
*/
|
|
class SwitchCard extends AbstractCard {
|
|
/**
|
|
* Default options of the card.
|
|
*
|
|
* @type {switchCardOptions}
|
|
* @private
|
|
*/
|
|
#defaultOptions = {
|
|
type: "custom:mushroom-entity-card",
|
|
icon: undefined,
|
|
tap_action: {
|
|
action: "toggle",
|
|
},
|
|
};
|
|
|
|
/**
|
|
* Class constructor.
|
|
*
|
|
* @param {hassEntity} entity The hass entity to create a card for.
|
|
* @param {switchCardOptions} [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 {SwitchCard};
|