diff --git a/lib/entities/button.ts b/lib/entities/button.ts index 310be06..00071de 100644 --- a/lib/entities/button.ts +++ b/lib/entities/button.ts @@ -6,7 +6,7 @@ * @license Apache License 2.0, see LICENSE for more details. */ -import { CommandHandler, Entity, EntityType, EntityName } from "./entity.js"; +import { CommandHandler, Entity, EntityType, EntityName, EntityDescription } from "./entity.js"; import log from "../loggers.js"; export enum ButtonStates { @@ -35,6 +35,8 @@ export enum ButtonCommands { } export interface ButtonParams { + icon?: string; + description?: EntityDescription; state?: ButtonStates; area?: string; cmdHandler?: CommandHandler; @@ -59,11 +61,17 @@ export class Button extends Entity { * @param id The entity identifier. Must be unique inside the integration driver. * @param name The human-readable name of the entity. * Either a string, which will be mapped to English, or a Map / Object containing multiple language strings. - * @param {ButtonParams} [params] Entity parameters. + * @param {ButtonParams} [params] Button-entity parameters. * @throws AssertionError if invalid parameters are specified. */ - constructor(id: string, name: EntityName, { state = ButtonStates.Available, area, cmdHandler }: ButtonParams = {}) { + constructor( + id: string, + name: EntityName, + { icon, description, state = ButtonStates.Available, area, cmdHandler }: ButtonParams = {} + ) { super(id, name, EntityType.Button, { + icon, + description, features: ["press"], attributes: { state: state diff --git a/lib/entities/climate.ts b/lib/entities/climate.ts index d1c4c6c..3d3df07 100644 --- a/lib/entities/climate.ts +++ b/lib/entities/climate.ts @@ -6,7 +6,7 @@ * @license Apache License 2.0, see LICENSE for more details. */ -import { CommandHandler, Entity, EntityType, EntityName } from "./entity.js"; +import { CommandHandler, Entity, EntityType, EntityName, EntityDescription } from "./entity.js"; import log from "../loggers.js"; // Climate entity states @@ -167,6 +167,8 @@ export enum TemperatureUnit { // Define types for the parameters in the constructor export interface ClimateParams { + icon?: string; + description?: EntityDescription; features?: ClimateFeatures[]; attributes?: Partial>; deviceClass?: string; @@ -190,15 +192,24 @@ export class Climate extends Entity { * @param {string} id The entity identifier. Must be unique inside the integration driver. * @param {EntityName} name The human-readable name of the entity. * Either a string, which will be mapped to English, or a Map / Object containing multiple language strings. - * @param {ClimateParams} [params] Entity parameters. + * @param {ClimateParams} [params] Climate-entity parameters. * @throws AssertionError if invalid parameters are specified. */ constructor( id: string, name: EntityName, - { features, attributes, deviceClass, options, area, cmdHandler }: ClimateParams = {} + { icon, description, features, attributes, deviceClass, options, area, cmdHandler }: ClimateParams = {} ) { - super(id, name, EntityType.Climate, { features, attributes, deviceClass, options, area, cmdHandler }); + super(id, name, EntityType.Climate, { + icon, + description, + features, + attributes, + deviceClass, + options, + area, + cmdHandler + }); log.debug(`Climate entity created with id: ${this.id}`); } diff --git a/lib/entities/cover.ts b/lib/entities/cover.ts index 66f5e25..9140848 100644 --- a/lib/entities/cover.ts +++ b/lib/entities/cover.ts @@ -6,7 +6,7 @@ * @license Apache License 2.0, see LICENSE for more details. */ -import { CommandHandler, Entity, EntityType, EntityName } from "./entity.js"; +import { CommandHandler, Entity, EntityType, EntityName, EntityDescription } from "./entity.js"; import log from "../loggers.js"; // Cover entity states @@ -158,6 +158,8 @@ export enum CoverOptions {} // Define types for the parameters in the constructor export interface CoverParams { + icon?: string; + description?: EntityDescription; features?: CoverFeatures[]; attributes?: Partial>; deviceClass?: CoverDeviceClasses; @@ -182,15 +184,24 @@ export class Cover extends Entity { * @param {string} id The entity identifier. Must be unique inside the integration driver. * @param {EntityName} name The human-readable name of the entity. * Either a string, which will be mapped to English, or a Map / Object containing multiple language strings. - * @param {CoverParams} [params] Entity parameters. + * @param {CoverParams} [params] Cover-entity parameters. * @throws AssertionError if invalid parameters are specified. */ constructor( id: string, name: EntityName, - { features, attributes, deviceClass, options, area, cmdHandler }: CoverParams = {} + { icon, description, features, attributes, deviceClass, options, area, cmdHandler }: CoverParams = {} ) { - super(id, name, EntityType.Cover, { features, attributes, deviceClass, options, area, cmdHandler }); + super(id, name, EntityType.Cover, { + icon, + description, + features, + attributes, + deviceClass, + options, + area, + cmdHandler + }); log.debug(`Cover entity created with id: ${this.id}`); } diff --git a/lib/entities/entities.ts b/lib/entities/entities.ts index 41d447c..78816d7 100644 --- a/lib/entities/entities.ts +++ b/lib/entities/entities.ts @@ -120,6 +120,8 @@ export class Entities extends EventEmitter { * Returned properties are: * - entity_id * - entity_type + * - icon + * - description * - device_id * - features * - name @@ -138,6 +140,8 @@ export class Entities extends EventEmitter { const entity = { entity_id: value.id, entity_type: value.entity_type, + icon: value.icon, + description: value.description, device_id: value.device_id, features: value.features, name: value.name, diff --git a/lib/entities/entity.ts b/lib/entities/entity.ts index 1106d64..82f50e5 100644 --- a/lib/entities/entity.ts +++ b/lib/entities/entity.ts @@ -34,6 +34,7 @@ export enum EntityType { } export type EntityName = string | { [key: string]: string }; +export type EntityDescription = string | { [key: string]: string }; export type EntityAttributes = { [key: string]: string | number | boolean | string[] }; export type EntityOptions = { [key: string]: string | number | boolean | object }; export type EntityCommandParams = { [key: string]: string | number | boolean }; @@ -41,6 +42,8 @@ export type EntityCommandParams = { [key: string]: string | number | boolean }; export type CommandHandler = (entity: Entity, command: string, params?: EntityCommandParams) => Promise; export interface EntityParams { + icon?: string; + description?: EntityDescription; features?: string[]; attributes?: EntityAttributes; deviceClass?: string; @@ -56,6 +59,10 @@ export class Entity { public name: EntityName; /** Entity device type name: one of the supported entities. */ public entity_type: EntityType; + /** Optional icon of the entity. If not specified, a default icon is used based on the entity type. */ + public icon?: string; + /** Optional description of the entity. */ + public description?: EntityDescription; /** Optional associated device, if the integration driver supports multiple devices. */ public device_id?: string; @@ -84,13 +91,24 @@ export class Entity { id: string, name: string | { [key: string]: string }, entityType: EntityType, - { features = [], attributes = { state: "UNKNOWN" }, deviceClass, options, area, cmdHandler }: EntityParams = {} + { + icon, + description, + features = [], + attributes = { state: "UNKNOWN" }, + deviceClass, + options, + area, + cmdHandler + }: EntityParams = {} ) { this.id = id; const languageName = toLanguageObject(name); assert(languageName); this.name = languageName || "?"; + this.icon = icon; + this.description = toLanguageObject(description) || undefined; this.entity_type = entityType; this.features = features; diff --git a/lib/entities/light.ts b/lib/entities/light.ts index 71968ab..e36853c 100644 --- a/lib/entities/light.ts +++ b/lib/entities/light.ts @@ -6,7 +6,7 @@ * @license Apache License 2.0, see LICENSE for more details. */ -import { CommandHandler, Entity, EntityType, EntityName } from "./entity.js"; +import { CommandHandler, Entity, EntityType, EntityName, EntityDescription } from "./entity.js"; import log from "../loggers.js"; /** @@ -117,6 +117,8 @@ export enum LightOptions { } export interface LightParams { + icon?: string; + description?: EntityDescription; features?: LightFeatures[]; attributes?: Partial>; deviceClass?: string; @@ -139,15 +141,24 @@ export class Light extends Entity { * @param {string} id The entity identifier. Must be unique inside the integration driver. * @param {EntityName} name The human-readable name of the entity. * Either a string, which will be mapped to English, or a Map / Object containing multiple language strings. - * @param {LightParams} [params] Entity parameters. + * @param {LightParams} [params] Light-entity parameters. * @throws AssertionError if invalid parameters are specified. */ constructor( id: string, name: EntityName, - { features, attributes, deviceClass, options, area, cmdHandler }: LightParams = {} + { icon, description, features, attributes, deviceClass, options, area, cmdHandler }: LightParams = {} ) { - super(id, name, EntityType.Light, { features, attributes, deviceClass, options, area, cmdHandler }); + super(id, name, EntityType.Light, { + icon, + description, + features, + attributes, + deviceClass, + options, + area, + cmdHandler + }); log.debug(`Light entity created with id: ${this.id}`); } diff --git a/lib/entities/media_player.ts b/lib/entities/media_player.ts index 0e69835..ffccb42 100644 --- a/lib/entities/media_player.ts +++ b/lib/entities/media_player.ts @@ -6,7 +6,7 @@ * @license Apache License 2.0, see LICENSE for more details. */ -import { Entity, EntityType, CommandHandler, EntityName } from "./entity.js"; +import { Entity, EntityType, CommandHandler, EntityName, EntityDescription } from "./entity.js"; import log from "../loggers.js"; import { Pagination, Paging, StatusCodes } from "../api_definitions.js"; @@ -733,6 +733,8 @@ export enum RepeatMode { } export interface MediaPlayerParams { + icon?: string; + description?: EntityDescription; features?: MediaPlayerFeatures[]; attributes?: Partial< Record @@ -758,15 +760,24 @@ export class MediaPlayer extends Entity { * @param {string} id The entity identifier. Must be unique inside the integration driver. * @param {EntityName} name The human-readable name of the entity. * Either a string, which will be mapped to English, or a Map / Object containing multiple language strings. - * @param {MediaPlayerParams} [params] Entity parameters. + * @param {MediaPlayerParams} [params] Media-player-entity parameters. * @throws AssertionError if invalid parameters are specified. */ constructor( id: string, name: EntityName, - { features, attributes, deviceClass, options, area, cmdHandler }: MediaPlayerParams = {} + { icon, description, features, attributes, deviceClass, options, area, cmdHandler }: MediaPlayerParams = {} ) { - super(id, name, EntityType.MediaPlayer, { features, attributes, deviceClass, options, area, cmdHandler }); + super(id, name, EntityType.MediaPlayer, { + icon, + description, + features, + attributes, + deviceClass, + options, + area, + cmdHandler + }); log.debug(`MediaPlayer entity created with id: ${this.id}`); } diff --git a/lib/entities/remote.ts b/lib/entities/remote.ts index f035f5a..9c48218 100644 --- a/lib/entities/remote.ts +++ b/lib/entities/remote.ts @@ -6,7 +6,7 @@ * @license Apache License 2.0, see LICENSE for more details. */ -import { CommandHandler, Entity, EntityType, EntityName, EntityOptions } from "./entity.js"; +import { CommandHandler, Entity, EntityType, EntityName, EntityOptions, EntityDescription } from "./entity.js"; import { DeviceButtonMapping, EntityCommand, UiPage } from "./ui.js"; import log from "../loggers.js"; import assert from "node:assert"; @@ -165,6 +165,8 @@ export function createRemoteSequenceCmd( } export interface RemoteParams { + icon?: string; + description?: EntityDescription; features?: RemoteFeatures[]; attributes?: Partial>; simpleCommands?: string[]; @@ -186,13 +188,23 @@ export class Remote extends Entity { * * @param id The entity identifier. Must be unique inside the integration driver. * @param name The human-readable name of the entity. - * @param params Entity parameters. + * @param params Remote-entity parameters. * @throws AssertionError if invalid parameters are specified. */ constructor( id: string, name: EntityName, - { features, attributes, simpleCommands, buttonMapping, uiPages, area, cmdHandler }: RemoteParams = {} + { + icon, + description, + features, + attributes, + simpleCommands, + buttonMapping, + uiPages, + area, + cmdHandler + }: RemoteParams = {} ) { const options: EntityOptions = {}; if (simpleCommands) { @@ -205,7 +217,7 @@ export class Remote extends Entity { options[RemoteOptions.UserInterface] = { pages: uiPages }; } - super(id, name, EntityType.Remote, { features, attributes, options, area, cmdHandler }); + super(id, name, EntityType.Remote, { icon, description, features, attributes, options, area, cmdHandler }); log.debug(`Remote entity created with id: ${this.id}`); } diff --git a/lib/entities/sensor.ts b/lib/entities/sensor.ts index 04dc322..fb051bc 100644 --- a/lib/entities/sensor.ts +++ b/lib/entities/sensor.ts @@ -6,7 +6,7 @@ * @license Apache License 2.0, see LICENSE for more details. */ -import { Entity, EntityType, EntityName } from "./entity.js"; +import { Entity, EntityType, EntityName, EntityDescription } from "./entity.js"; import log from "../loggers.js"; /** @@ -120,6 +120,8 @@ export enum SensorOptions { } export interface SensorParams { + icon?: string; + description?: EntityDescription; attributes?: Partial>; deviceClass?: SensorDeviceClasses; options?: Partial>; @@ -138,11 +140,15 @@ export class Sensor extends Entity { * * @param id The entity identifier. Must be unique inside the integration driver. * @param name The human-readable name of the entity. - * @param params Entity parameters. + * @param params Sensor-entity parameters. * @throws AssertionError if invalid parameters are specified. */ - constructor(id: string, name: EntityName, { attributes, deviceClass, options, area }: SensorParams = {}) { - super(id, name, EntityType.Sensor, { attributes, deviceClass, options, area }); + constructor( + id: string, + name: EntityName, + { icon, description, attributes, deviceClass, options, area }: SensorParams = {} + ) { + super(id, name, EntityType.Sensor, { icon, description, attributes, deviceClass, options, area }); log.debug(`Sensor entity created with id: ${this.id}`); } diff --git a/lib/entities/switch.ts b/lib/entities/switch.ts index d804dae..1794b9d 100644 --- a/lib/entities/switch.ts +++ b/lib/entities/switch.ts @@ -6,7 +6,7 @@ * @license Apache License 2.0, see LICENSE for more details. */ -import { CommandHandler, Entity, EntityType, EntityName } from "./entity.js"; +import { CommandHandler, Entity, EntityType, EntityName, EntityDescription } from "./entity.js"; import log from "../loggers.js"; // Switch entity states @@ -87,6 +87,8 @@ export enum SwitchOptions { // Define types for the parameters in the constructor export interface SwitchParams { + icon?: string; + description?: EntityDescription; features?: SwitchFeatures[]; attributes?: Partial>; deviceClass?: SwitchDeviceClasses; @@ -108,15 +110,24 @@ export class Switch extends Entity { * @param {string} id The entity identifier. Must be unique inside the integration driver. * @param {EntityName} name The human-readable name of the entity. * Either a string, which will be mapped to English, or a Map / Object containing multiple language strings. - * @param {SwitchParams} [params] Entity parameters. + * @param {SwitchParams} [params] Switch-entity parameters. * @throws AssertionError if invalid parameters are specified. */ constructor( id: string, name: EntityName, - { features, attributes, deviceClass, options, area, cmdHandler }: SwitchParams = {} + { icon, description, features, attributes, deviceClass, options, area, cmdHandler }: SwitchParams = {} ) { - super(id, name, EntityType.Switch, { features, attributes, deviceClass, options, area, cmdHandler }); + super(id, name, EntityType.Switch, { + icon, + description, + features, + attributes, + deviceClass, + options, + area, + cmdHandler + }); log.debug(`Switch entity created with id: ${this.id}`); } diff --git a/test/button.test.ts b/test/button.test.ts index 6e79789..fd7291e 100644 --- a/test/button.test.ts +++ b/test/button.test.ts @@ -8,6 +8,8 @@ test("Button constructor without parameter object creates default Button class", t.is(entity.id, "test"); t.deepEqual(entity.name, { en: "Test Button" }); t.is(entity.entity_type, EntityType.Button); + t.is(entity.icon, undefined); + t.is(entity.description, undefined); t.is(entity.device_id, undefined); t.deepEqual(entity.features, ["press"]); t.deepEqual(entity.attributes, { state: "AVAILABLE" }); @@ -19,6 +21,8 @@ test("Button constructor without parameter object creates default Button class", test("Button constructor with parameter object", (t) => { const entity = new Button("test", "Test Button", { + icon: "uc:star", + description: "unit test", state: ButtonStates.Unavailable, area: "Test lab" }); @@ -26,6 +30,8 @@ test("Button constructor with parameter object", (t) => { t.is(entity.id, "test"); t.deepEqual(entity.name, { en: "Test Button" }); t.is(entity.entity_type, EntityType.Button); + t.is(entity.icon, "uc:star"); + t.deepEqual(entity.description, { en: "unit test" }); t.is(entity.device_id, undefined); t.deepEqual(entity.features, ["press"]); t.deepEqual(entity.attributes, { state: "UNAVAILABLE" }); @@ -34,3 +40,12 @@ test("Button constructor with parameter object", (t) => { t.is(entity.area, "Test lab"); t.is(entity.hasCmdHandler, false); }); + +test("Button constructor with language text description", (t) => { + const entity = new Button("test", "Test", { + description: { en: "unit test", de: "Unit Test" } + }); + + t.is(entity.id, "test"); + t.deepEqual(entity.description, { en: "unit test", de: "Unit Test" }); +}); diff --git a/test/climate.test.ts b/test/climate.test.ts index ade6b14..a9caf42 100644 --- a/test/climate.test.ts +++ b/test/climate.test.ts @@ -15,6 +15,8 @@ test("Climate constructor without parameter object creates default Climate class t.is(entity.id, "test"); t.deepEqual(entity.name, { en: "Test Climate" }); t.is(entity.entity_type, EntityType.Climate); + t.is(entity.icon, undefined); + t.is(entity.description, undefined); t.is(entity.device_id, undefined); t.deepEqual(entity.features, []); t.deepEqual(entity.attributes, { [ClimateAttributes.State]: ClimateStates.Unknown }); @@ -30,6 +32,8 @@ test("Climate constructor with parameter object", (t) => { }; const entity = new Climate("test", "Test Climate", { + icon: "uc:star", + description: "unit test", features: [ClimateFeatures.Cool], attributes: { [ClimateAttributes.State]: ClimateStates.Unavailable @@ -41,6 +45,8 @@ test("Climate constructor with parameter object", (t) => { t.is(entity.id, "test"); t.deepEqual(entity.name, { en: "Test Climate" }); t.is(entity.entity_type, EntityType.Climate); + t.is(entity.icon, "uc:star"); + t.deepEqual(entity.description, { en: "unit test" }); t.is(entity.device_id, undefined); t.deepEqual(entity.features, ["cool"]); t.deepEqual(entity.attributes, { state: "UNAVAILABLE" }); @@ -62,3 +68,12 @@ test("Climate constructor with Object attributes", (t) => { t.is(entity.entity_type, EntityType.Climate); t.deepEqual(entity.attributes, { state: "COOL" }); }); + +test("Climate constructor with language text description", (t) => { + const entity = new Climate("test", "Test", { + description: { en: "unit test", de: "Unit Test" } + }); + + t.is(entity.id, "test"); + t.deepEqual(entity.description, { en: "unit test", de: "Unit Test" }); +}); diff --git a/test/cover.test.ts b/test/cover.test.ts index ad7befc..ecc95fe 100644 --- a/test/cover.test.ts +++ b/test/cover.test.ts @@ -8,6 +8,8 @@ test("Cover constructor without parameter object creates default Cover class", ( t.is(entity.id, "test"); t.deepEqual(entity.name, { en: "Test Cover" }); t.is(entity.entity_type, EntityType.Cover); + t.is(entity.icon, undefined); + t.is(entity.description, undefined); t.is(entity.device_id, undefined); t.deepEqual(entity.features, []); t.deepEqual(entity.attributes, { [CoverAttributes.State]: CoverStates.Unknown }); @@ -23,6 +25,8 @@ test("Cover constructor with parameter object", (t) => { }; const entity = new Cover("test", "Test Cover", { + icon: "uc:star", + description: "unit test", features: [CoverFeatures.Tilt], attributes, options: {}, @@ -32,6 +36,8 @@ test("Cover constructor with parameter object", (t) => { t.is(entity.id, "test"); t.deepEqual(entity.name, { en: "Test Cover" }); t.is(entity.entity_type, EntityType.Cover); + t.is(entity.icon, "uc:star"); + t.deepEqual(entity.description, { en: "unit test" }); t.is(entity.device_id, undefined); t.deepEqual(entity.features, ["tilt"]); t.deepEqual(entity.attributes, { state: "UNAVAILABLE" }); @@ -51,3 +57,12 @@ test("Cover constructor with Object attributes", (t) => { t.is(entity.entity_type, EntityType.Cover); t.deepEqual(entity.attributes, { position: 50 }); }); + +test("Cover constructor with language text description", (t) => { + const entity = new Cover("test", "Test", { + description: { en: "unit test", de: "Unit Test" } + }); + + t.is(entity.id, "test"); + t.deepEqual(entity.description, { en: "unit test", de: "Unit Test" }); +}); diff --git a/test/light.test.ts b/test/light.test.ts index 35c1875..f78b931 100644 --- a/test/light.test.ts +++ b/test/light.test.ts @@ -8,6 +8,8 @@ test("Light constructor without parameter object creates default Light class", ( t.is(entity.id, "test"); t.deepEqual(entity.name, { en: "Test Light" }); t.is(entity.entity_type, EntityType.Light); + t.is(entity.icon, undefined); + t.is(entity.description, undefined); t.is(entity.device_id, undefined); t.deepEqual(entity.features, []); t.deepEqual(entity.attributes, { [LightAttributes.State]: LightStates.Unknown }); @@ -23,6 +25,8 @@ test("Light constructor with parameter object", (t) => { }; const entity = new Light("test", "Test Light", { + icon: "uc:star", + description: "unit test", features: [LightFeatures.ColorTemperature], attributes, options: {}, @@ -32,6 +36,8 @@ test("Light constructor with parameter object", (t) => { t.is(entity.id, "test"); t.deepEqual(entity.name, { en: "Test Light" }); t.is(entity.entity_type, EntityType.Light); + t.is(entity.icon, "uc:star"); + t.deepEqual(entity.description, { en: "unit test" }); t.is(entity.device_id, undefined); t.deepEqual(entity.features, ["color_temperature"]); t.deepEqual(entity.attributes, { state: "UNAVAILABLE" }); @@ -51,3 +57,12 @@ test("Light constructor with Object attributes", (t) => { t.is(entity.entity_type, EntityType.Light); t.deepEqual(entity.attributes, { brightness: 33 }); }); + +test("Light constructor with language text description", (t) => { + const entity = new Light("test", "Test", { + description: { en: "unit test", de: "Unit Test" } + }); + + t.is(entity.id, "test"); + t.deepEqual(entity.description, { en: "unit test", de: "Unit Test" }); +}); diff --git a/test/media_player.test.ts b/test/media_player.test.ts index 64e7f07..06a7451 100644 --- a/test/media_player.test.ts +++ b/test/media_player.test.ts @@ -14,6 +14,8 @@ test("MediaPlayer constructor without parameter object creates default MediaPlay t.is(entity.id, "test"); t.deepEqual(entity.name, { en: "Test MediaPlayer" }); t.is(entity.entity_type, EntityType.MediaPlayer); + t.is(entity.icon, undefined); + t.is(entity.description, undefined); t.is(entity.device_id, undefined); t.deepEqual(entity.features, []); t.deepEqual(entity.attributes, { [MediaPlayerAttributes.State]: MediaPlayerStates.Unknown }); @@ -51,6 +53,8 @@ test("MediaPlayer constructor with parameter object", (t) => { }; const entity = new MediaPlayer("test", "Test MediaPlayer", { + icon: "uc:star", + description: "unit test", features: [MediaPlayerFeatures.Menu], attributes, options, @@ -60,6 +64,8 @@ test("MediaPlayer constructor with parameter object", (t) => { t.is(entity.id, "test"); t.deepEqual(entity.name, { en: "Test MediaPlayer" }); t.is(entity.entity_type, EntityType.MediaPlayer); + t.is(entity.icon, "uc:star"); + t.deepEqual(entity.description, { en: "unit test" }); t.is(entity.device_id, undefined); t.deepEqual(entity.features, ["menu"]); t.deepEqual(entity.attributes, { state: "UNAVAILABLE", volume: 22 }); @@ -85,3 +91,12 @@ test("MediaPlayer constructor with Object attributes", (t) => { t.is(entity.entity_type, EntityType.MediaPlayer); t.deepEqual(entity.attributes, { shuffle: false, muted: false, volume: 25 }); }); + +test("MediaPlayer constructor with language text description", (t) => { + const entity = new MediaPlayer("test", "Test", { + description: { en: "unit test", de: "Unit Test" } + }); + + t.is(entity.id, "test"); + t.deepEqual(entity.description, { en: "unit test", de: "Unit Test" }); +}); diff --git a/test/remote.test.ts b/test/remote.test.ts index 9463ed8..4f4ce61 100644 --- a/test/remote.test.ts +++ b/test/remote.test.ts @@ -98,6 +98,8 @@ test("Remote constructor without parameter object creates default remote class", t.is(remote.id, "test"); t.deepEqual(remote.name, { en: "Test Remote" }); t.is(remote.entity_type, EntityType.Remote); + t.is(remote.icon, undefined); + t.is(remote.description, undefined); t.is(remote.device_id, undefined); t.deepEqual(remote.features, []); t.deepEqual(remote.attributes, { [RemoteAttributes.State]: RemoteStates.Unknown }); @@ -113,6 +115,8 @@ test("Remote constructor with parameter object", (t) => { }; const remote = new Remote("test", "Test Remote", { + icon: "uc:star", + description: "unit test", features: [RemoteFeatures.SendCmd], attributes, simpleCommands: ["foobar", "foo", "bar"], @@ -122,6 +126,8 @@ test("Remote constructor with parameter object", (t) => { t.is(remote.id, "test"); t.deepEqual(remote.name, { en: "Test Remote" }); t.is(remote.entity_type, EntityType.Remote); + t.is(remote.icon, "uc:star"); + t.deepEqual(remote.description, { en: "unit test" }); t.is(remote.device_id, undefined); t.deepEqual(remote.features, ["send_cmd"]); t.deepEqual(remote.attributes, { state: "ON" }); @@ -141,3 +147,12 @@ test("Remote constructor with Object attributes", (t) => { t.is(entity.entity_type, EntityType.Remote); t.deepEqual(entity.attributes, { state: "UNAVAILABLE" }); }); + +test("Remote constructor with language text description", (t) => { + const entity = new Remote("test", "Test", { + description: { en: "unit test", de: "Unit Test" } + }); + + t.is(entity.id, "test"); + t.deepEqual(entity.description, { en: "unit test", de: "Unit Test" }); +}); diff --git a/test/sensor.test.ts b/test/sensor.test.ts index 1d18dd9..a680288 100644 --- a/test/sensor.test.ts +++ b/test/sensor.test.ts @@ -8,6 +8,8 @@ test("Sensor constructor without parameter object creates default Sensor class", t.is(entity.id, "test"); t.deepEqual(entity.name, { en: "Test Sensor" }); t.is(entity.entity_type, EntityType.Sensor); + t.is(entity.icon, undefined); + t.is(entity.description, undefined); t.is(entity.device_id, undefined); t.deepEqual(entity.features, []); t.deepEqual(entity.attributes, { [SensorAttributes.State]: SensorStates.Unknown }); @@ -27,6 +29,8 @@ test("Sensor constructor with parameter object", (t) => { }; const entity = new Sensor("test", "Test Sensor", { + icon: "uc:star", + description: "unit test", attributes, options, deviceClass: SensorDeviceClasses.Energy, @@ -36,6 +40,8 @@ test("Sensor constructor with parameter object", (t) => { t.is(entity.id, "test"); t.deepEqual(entity.name, { en: "Test Sensor" }); t.is(entity.entity_type, EntityType.Sensor); + t.is(entity.icon, "uc:star"); + t.deepEqual(entity.description, { en: "unit test" }); t.is(entity.device_id, undefined); t.deepEqual(entity.features, []); t.deepEqual(entity.attributes, { state: "UNAVAILABLE" }); @@ -61,3 +67,12 @@ test("Sensor constructor with Object attributes", (t) => { t.is(entity.entity_type, EntityType.Sensor); t.deepEqual(entity.attributes, { state: "ON", value: 100, unit: "%" }); }); + +test("Sensor constructor with language text description", (t) => { + const entity = new Sensor("test", "Test", { + description: { en: "unit test", de: "Unit Test" } + }); + + t.is(entity.id, "test"); + t.deepEqual(entity.description, { en: "unit test", de: "Unit Test" }); +}); diff --git a/test/switch.test.ts b/test/switch.test.ts index 31f299c..fa18a3b 100644 --- a/test/switch.test.ts +++ b/test/switch.test.ts @@ -8,6 +8,8 @@ test("Switch constructor without parameter object creates default Switch class", t.is(entity.id, "test"); t.deepEqual(entity.name, { en: "Test Switch" }); t.is(entity.entity_type, EntityType.Switch); + t.is(entity.icon, undefined); + t.is(entity.description, undefined); t.is(entity.device_id, undefined); t.deepEqual(entity.features, []); t.deepEqual(entity.attributes, { [SwitchAttributes.State]: SwitchStates.Unknown }); @@ -27,6 +29,8 @@ test("Switch constructor with parameter object", (t) => { }; const entity = new Switch("test", "Test Switch", { + icon: "uc:star", + description: "unit test", features: [SwitchFeatures.Toggle], attributes, options, @@ -36,6 +40,8 @@ test("Switch constructor with parameter object", (t) => { t.is(entity.id, "test"); t.deepEqual(entity.name, { en: "Test Switch" }); t.is(entity.entity_type, EntityType.Switch); + t.is(entity.icon, "uc:star"); + t.deepEqual(entity.description, { en: "unit test" }); t.is(entity.device_id, undefined); t.deepEqual(entity.features, ["toggle"]); t.deepEqual(entity.attributes, { state: "UNAVAILABLE" }); @@ -55,3 +61,12 @@ test("Switch constructor with Object attributes", (t) => { t.is(entity.entity_type, EntityType.Switch); t.deepEqual(entity.attributes, { state: "OFF" }); }); + +test("Switch constructor with language text description", (t) => { + const entity = new Switch("test", "Test", { + description: { en: "unit test", de: "Unit Test" } + }); + + t.is(entity.id, "test"); + t.deepEqual(entity.description, { en: "unit test", de: "Unit Test" }); +});