From ab1a6b2328dff09f0dc71ac3aee7b9cc8446c5a7 Mon Sep 17 00:00:00 2001 From: reptilex Date: Mon, 4 Apr 2022 13:01:52 +0200 Subject: [PATCH] added missing files --- src/models/BubbleData.ts | 23 ++++++ test/extraAppliancesNotInHouse.test.ts | 99 ++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 src/models/BubbleData.ts create mode 100644 test/extraAppliancesNotInHouse.test.ts diff --git a/src/models/BubbleData.ts b/src/models/BubbleData.ts new file mode 100644 index 0000000..824dc9f --- /dev/null +++ b/src/models/BubbleData.ts @@ -0,0 +1,23 @@ +import { HassEntity } from 'home-assistant-js-websocket'; + +export class BubbleData { + + public mainValue: number = 0; + + public mainUnitOfMeasurement: string | undefined; + + public clickEntitySlot: string | null = null; + + public clickEntityHassState:HassEntity | null = null; + + public icon:string | undefined; + + public cssSelector: string | undefined; + + public extraValue: string | undefined; + + public extraUnitOfMeasurement: string | undefined; + + public noEntitiesWithValueFound = true; + +} \ No newline at end of file diff --git a/test/extraAppliancesNotInHouse.test.ts b/test/extraAppliancesNotInHouse.test.ts new file mode 100644 index 0000000..a26b93b --- /dev/null +++ b/test/extraAppliancesNotInHouse.test.ts @@ -0,0 +1,99 @@ +import { expect, assert } from '@open-wc/testing'; +import { LovelaceCardConfig } from 'custom-card-helpers'; +import { setViewport } from '@web/test-runner-commands'; + +import { TeslaStyleSolarPowerCard } from '../src/TeslaStyleSolarPowerCard.js'; +import '../tesla-style-solar-power-card.js'; +import { setCard } from './setters.js'; + +describe('TeslaStyleSolarPowerCard with extra appliances', () => { + let card: TeslaStyleSolarPowerCard; + let haCard: HTMLElement | null; + let teslaCard: HTMLElement | null | undefined; + let hass: any; + let config: LovelaceCardConfig; + + /** Tests are extended in energy_capable. * */ + + beforeEach(async () => { + config = { + type: 'custom:tesla-style-solar-power-card', + name: 'Powerhouse', + house_entity: 'sensor.house_consumption', + grid_to_house_entity: 'sensor.grid_to_house', + appliance1_consumption_entity: 'sensor.car_consumption', + appliance1_extra_entity: 'sensor.car_soc', + appliance2_consumption_entity: 'sensor.heating_consumption', + appliance2_extra_entity: 'sensor.heating_current_function', + house_without_appliances_values: 'sensor.heating_current_function', + }; + hass = { + states: { + 'sensor.heating_consumption': { + attributes: { + unit_of_measurement: 'W', + friendly_name: 'Heating consumption', + }, + entity_id: 'heating_consumption', + state: '1000', + }, + 'sensor.heating_current_function': { + attributes: { + unit_of_measurement: null, + friendly_name: 'Heating function', + }, + entity_id: 'heating_current_function', + state: 'Warm water', + }, + 'sensor.car_consumption': { + attributes: { + unit_of_measurement: 'W', + }, + entity_id: 'car_consumption', + state: '2000', + }, + 'sensor.car_soc': { + attributes: { + unit_of_measurement: '%', + }, + entity_id: 'car_soc', + state: '90', + }, + 'sensor.house_consumption': { + attributes: { + unit_of_measurement: 'W', + }, + entity_id: 'house_consumption', + state: '4000', + }, + 'sensor.grid_to_house': { + attributes: { + unit_of_measurement: 'W', + }, + entity_id: 'grid_to_house', + state: '4000', + }, + }, + }; + await setViewport({ width: 1200, height: 1000 }); + card = await setCard(hass, config); + if (card.shadowRoot === null) assert.fail('No Card Shadowroot'); + haCard = card.shadowRoot.querySelector('ha-card'); + if (haCard === null || haCard === undefined) assert.fail('No ha-card'); + teslaCard = ( + haCard.querySelector('#tesla-style-solar-power-card') + ); + if (teslaCard === null || teslaCard === undefined) + assert.fail('No tesla-style-card'); + }); + + it('has house_entity, text and icon', async () => { + const houseEntity = teslaCard?.querySelector('.house_entity'); + if (houseEntity === null || houseEntity === undefined) + assert.fail('No house_entity element found'); + expect(houseEntity?.querySelector('.acc_text')?.innerHTML.replace(/)]+-->/g, '')).contains('1 kW'); + expect( + houseEntity?.querySelector('.acc_icon')?.getAttribute('icon')?.toString() + ).to.equal('mdi:home'); + }); +});