Skip to content

Commit 0117a17

Browse files
committedMay 13, 2024
added the ability to hide/show ICON, NAME, TEXT for indexes (fixes #43)
graphic changes in order to improve text in graphs (fixes #42) fix for wrong effect text if sensor return NaN (fixes comment in #42) added pt_BR to languages so detection when 'Brazilian' is selected would works (as in merge 41)
1 parent 1ca93f2 commit 0117a17

9 files changed

+177
-68
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "comfortable-environment-card",
3-
"version": "1.6.0",
3+
"version": "1.7.0",
44
"description": "Lovelace comfortable-environment-card",
55
"keywords": [
66
"home-assistant",

‎src/comfortable-environment-card.ts

+111-64
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class ComfortableEnvironmentCard extends LitElement {
6868
}
6969

7070
public static getStubConfig(): Record<string, unknown> {
71-
return { name: localize('configurator.room_name'), temperature_sensor: "sensor.room_temperature", humidity_sensor: "sensor.room_humidity", display_precision: 1, show_index: "ALL", show_realvalues: "ALL" };
71+
return { name: localize('configurator.room_name'), temperature_sensor: "sensor.room_temperature", humidity_sensor: "sensor.room_humidity", display_precision: 1, show_index: "ALL", show_realvalues: "ALL", index_showinfo: "ALL" };
7272
}
7373

7474
protected calcHI(tempInF: number, humValue: number): number {
@@ -102,8 +102,11 @@ class ComfortableEnvironmentCard extends LitElement {
102102
}
103103

104104
protected calcHIEffects(hiValue: number): number {
105-
let hieffects = 0
105+
let hieffects = NaN
106106
switch(true) {
107+
case hiValue<80:
108+
hieffects = 0
109+
break;
107110
case hiValue>=80 && hiValue<=90.0:
108111
hieffects = 1
109112
break;
@@ -125,8 +128,11 @@ class ComfortableEnvironmentCard extends LitElement {
125128
}
126129

127130
protected calcDIEffects(diValue: number): number {
128-
let diEffects = 0
131+
let diEffects = NaN
129132
switch(true) {
133+
case diValue <= 10.0:
134+
diEffects = 0
135+
break;
130136
case diValue>10.0 && diValue<=15.0:
131137
diEffects = 1
132138
break;
@@ -164,9 +170,10 @@ class ComfortableEnvironmentCard extends LitElement {
164170
const humSensorStatus = Number(this.hass.states[this.config.humidity_sensor]?.state);
165171
const tempSensorUnit = this.hass.states[this.config.temperature_sensor]?.attributes.unit_of_measurement
166172
const tempSensorUnitInF = this.hass.states[this.config.temperature_sensor]?.attributes.unit_of_measurement==='°F'
167-
const showIndex = this.config.show_index
168-
const showRealValues = this.config.show_realvalues
169-
const display_precision = Number(this.config.display_precision)
173+
const showIndex = this.config.show_index || 'ALL'
174+
const indexInfo = this.config.index_showinfo || 'ALL'
175+
const showRealValues = this.config.show_realvalues || 'ALL'
176+
const display_precision = Number(this.config.display_precision) || 1
170177

171178
const tempCelsiusValue = tempSensorUnitInF ? this.toCelsius(tempSensorStatus) : tempSensorStatus
172179
const tempFarenheitValue = tempSensorUnitInF ? tempSensorStatus : this.toFahrenheit(tempSensorStatus)
@@ -186,74 +193,108 @@ class ComfortableEnvironmentCard extends LitElement {
186193
${this.renderStyle()}
187194
<ha-card tabindex="0">
188195
189-
${(this.config.room_name || showRealValues != 'NONE')?html`
190-
<div class="header">
191-
<div class="name">
192-
${this.config.room_name}
193-
</div>
194-
${(showRealValues != 'NONE')?html`
195-
<div class="header_icons">
196-
${(showRealValues == 'ALL' || showRealValues == 'TEMPERATURE')?html`
197-
<div class="temp">
198-
${tempSensorStatus.toFixed(display_precision)}${tempSensorUnit}
199-
<div class="icon">
200-
<svg preserveAspectRatio="xMidYMid meet" focusable="false" role="img" aria-hidden="true" viewBox="0 0 24 24" style="fill: var(--state-icon-color); vertical-align: sub;">
201-
<g>
202-
<path class="primary-path" d="${mdiThermometer}" />
203-
</g>
204-
</svg>
205-
</div>
196+
<div class="header">
197+
198+
<div class="name">
199+
${this.config.room_name}
200+
</div>
201+
202+
${(showRealValues != 'NONE')?html`
203+
<div class="header_icons">
204+
${(showRealValues == 'ALL' || showRealValues == 'TEMPERATURE')?html`
205+
<div class="temp">
206+
${tempSensorStatus.toFixed(display_precision)}${tempSensorUnit}
207+
<div class="icon">
208+
<svg preserveAspectRatio="xMidYMid meet" focusable="false" role="img" aria-hidden="true" viewBox="0 0 24 24" style="fill: var(--state-icon-color); vertical-align: sub;">
209+
<g>
210+
<path class="primary-path" d="${mdiThermometer}" />
211+
</g>
212+
</svg>
206213
</div>
207-
`:``}
208-
${(showRealValues == 'ALL' || showRealValues == 'HUMIDITY')?html`
209-
<div class="hum">
210-
${humSensorStatus.toFixed(display_precision)}%
211-
<div class="icon">
212-
<svg preserveAspectRatio="xMidYMid meet" focusable="false" role="img" aria-hidden="true" viewBox="0 0 24 24" style="fill: var(--state-icon-color); vertical-align: sub;">
213-
<g>
214-
<path class="primary-path" d="${mdiWaterPercent}" />
215-
</g>
216-
</svg>
217-
</div>
214+
</div>
215+
`:``}
216+
217+
${(showRealValues == 'ALL' || showRealValues == 'HUMIDITY')?html`
218+
<div class="hum">
219+
${humSensorStatus.toFixed(display_precision)}%
220+
<div class="icon">
221+
<svg preserveAspectRatio="xMidYMid meet" focusable="false" role="img" aria-hidden="true" viewBox="0 0 24 24" style="fill: var(--state-icon-color); vertical-align: sub;">
222+
<g>
223+
<path class="primary-path" d="${mdiWaterPercent}" />
224+
</g>
225+
</svg>
218226
</div>
219-
`:``}
220-
</div>
227+
</div>
221228
`:``}
222-
</div>
223-
`:``}
229+
</div>
230+
`:``}
231+
232+
</div>
224233
225234
<div class="info">
226235
227236
${(showIndex == 'ALL' || showIndex == 'HI')?html`
228-
<div class="comfort-env-text">
229-
<div class="icon">
230-
<svg preserveAspectRatio="xMidYMid meet" focusable="false" role="img" aria-hidden="true" viewBox="0 0 24 24" style="fill: var(--state-icon-color); vertical-align: sub;">
231-
<g>
232-
<path class="primary-path" d="${mdiSunThermometer}" />
233-
</g>
234-
</svg>
237+
${(indexInfo != 'NONE')?html`
238+
<div class="comfort-env-text">
239+
${(indexInfo == 'ALL' || indexInfo == 'ICON' || indexInfo == 'ICON_AND_NAME' || indexInfo == 'ICON_AND_TEXT')?html`
240+
<div class="icon">
241+
<svg preserveAspectRatio="xMidYMid meet" focusable="false" role="img" aria-hidden="true" viewBox="0 0 24 24" style="fill: var(--state-icon-color); vertical-align: sub;">
242+
<g>
243+
<path class="primary-path" d="${mdiSunThermometer}" />
244+
</g>
245+
</svg>
246+
</div>
247+
`:``}
248+
${(indexInfo != 'ICON')?html`
249+
<div class="effects">
250+
${(indexInfo == 'ALL' || indexInfo == 'ICON_AND_NAME' || indexInfo == 'NAME' || indexInfo == 'NAME_AND_TEXT')?html`
251+
${localize('common.hi')}: ${HI}${tempSensorUnit}
252+
`:``}
253+
${(indexInfo == 'ALL' || indexInfo == 'NAME_AND_TEXT')?html`
254+
-
255+
`:``}
256+
${(indexInfo == 'ALL' || indexInfo == 'ICON_AND_TEXT' || indexInfo == 'TEXT' || indexInfo == 'NAME_AND_TEXT')?html`
257+
${!Number.isNaN(HIeffects)?localize('states.hi.'+[HIeffects]):'---'}
258+
`:``}
259+
</div>
260+
`:``}
235261
</div>
236-
<div class="effects">${localize('common.hi')}: ${HI}${tempSensorUnit} - ${localize('states.hi.'+[HIeffects])}</div>
237-
</div>
238-
<div class="color-range-container">
262+
`:``}
263+
<div class="color-range-container${indexInfo=='NONE'?' collapsed':''}">
239264
<div class="color-range-gradient" style="background: linear-gradient(90deg, rgb(254, 240, 217) 0%, rgb(253, 204, 138) 28%, rgb(252, 141, 89) 42%, rgb(227, 74, 51) 66%, rgb(179, 0, 0) 100%);" >
240-
<li class="value-box" style="margin-left: max(0%,calc(${this.calcRange(0,100,tempSensorUnitInF?76:23,tempSensorUnitInF?132:57,HI)}% - 46px))">${HI}</li>
265+
<div class="value-box" style="margin-left: max(0%,calc(${this.calcRange(0,100,tempSensorUnitInF?76:23,tempSensorUnitInF?132:57,HI)}% - 46px))">${HI}</div>
241266
</div>
242267
</div>
243268
`:``}
244269
245270
${(showIndex == 'ALL' || showIndex == 'DI')?html`
246-
<div class="comfort-env-text">
247-
<div class="icon">
248-
<svg preserveAspectRatio="xMidYMid meet" focusable="false" role="img" aria-hidden="true" viewBox="0 0 24 24" style="fill: var(--state-icon-color); vertical-align: sub;">
249-
<g>
250-
<path class="primary-path" d="${mdiThermometerLines}" />
251-
</g>
252-
</svg>
253-
</div>
254-
<div class="effects">${localize('common.di')}: ${DI} - ${localize('states.di.'+[DIeffects])}</div>
271+
${(indexInfo != 'NONE')?html`
272+
<div class="comfort-env-text">
273+
${(indexInfo == 'ALL' || indexInfo == 'ICON' || indexInfo == 'ICON_AND_NAME' || indexInfo == 'ICON_AND_TEXT')?html`
274+
<div class="icon">
275+
<svg preserveAspectRatio="xMidYMid meet" focusable="false" role="img" aria-hidden="true" viewBox="0 0 24 24" style="fill: var(--state-icon-color); vertical-align: sub;">
276+
<g>
277+
<path class="primary-path" d="${mdiThermometerLines}" />
278+
</g>
279+
</svg>
280+
</div>
281+
`:``}
282+
${(indexInfo != 'ICON')?html`
283+
<div class="effects">
284+
${(indexInfo == 'ALL' || indexInfo == 'ICON_AND_NAME' || indexInfo == 'NAME' || indexInfo == 'NAME_AND_TEXT')?html`
285+
${localize('common.di')}: ${DI}
286+
`:``}
287+
${(indexInfo == 'ALL' || indexInfo == 'NAME_AND_TEXT')?html`
288+
-
289+
`:``}
290+
${(indexInfo == 'ALL' || indexInfo == 'ICON_AND_TEXT' || indexInfo == 'TEXT' || indexInfo == 'NAME_AND_TEXT')?html`
291+
${!Number.isNaN(DIeffects)?localize('states.di.'+[DIeffects]):'---'}
292+
`:``}
293+
</div>
294+
`:``}
255295
</div>
256-
<div class="color-range-container">
296+
`:``}
297+
<div class="color-range-container${indexInfo=='NONE'?' collapsed':''}">
257298
<div class="color-range-gradient" style="background: linear-gradient(90deg,rgb(5, 112, 176) 0%,rgb(116, 169, 207)12%,rgb(189, 201, 225) 32%,rgb(241, 238, 246) 44%,rgb(254, 240, 217) 56%,rgb(253, 204, 138) 68%,rgb(252, 141, 89) 80%,rgb(227, 74, 51) 88%,rgb(179, 0, 0) 100%);" >
258299
<div class="value-box" style="margin-left: max(0%,calc(${this.calcRange(0,100,8,34,DI)}% - 46px))">${DI}</div>
259300
</div>
@@ -283,13 +324,16 @@ class ComfortableEnvironmentCard extends LitElement {
283324
.color-range-container {
284325
display: flex;
285326
}
327+
.collapsed {
328+
margin-top: 2%;
329+
}
286330
.color-range-gradient {
287331
width: 100%;
288332
border-radius: 5px;
289333
margin: 0 10px 10px;
290334
}
291335
.value-box {
292-
border: solid 3px #000;
336+
border: solid 2px #000;
293337
border-radius: 10px;
294338
padding: 3px;
295339
width: 32px;
@@ -303,15 +347,18 @@ class ComfortableEnvironmentCard extends LitElement {
303347
margin: 0 10px 0;
304348
padding: 5px 0 5px;
305349
text-align: left;
306-
line-height: var(--mdc-icon-size);
350+
line-height: var(--mdc-icon-size, 8px);
307351
}
308352
.info {
309353
margin-top: -4px;
310354
padding-bottom: 1%;
311355
}
356+
.effects {
357+
display: inline;
358+
}
312359
.header {
313360
display: flex;
314-
padding: 0 2% 0;
361+
padding: 1% 2% 0;
315362
justify-content: space-between;
316363
font-weight: 500;
317364
margin-bottom: 1%;
@@ -328,8 +375,8 @@ class ComfortableEnvironmentCard extends LitElement {
328375
}
329376
.icon {
330377
display: inline-block;
331-
width: var(--mdc-icon-size);
332-
height: var(--mdc-icon-size);
378+
width: var(--mdc-icon-size, 24px);
379+
height: var(--mdc-icon-size, 24px);
333380
}
334381
</style>
335382
`;

‎src/const.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const CARD_VERSION = '1.6.0'
1+
export const CARD_VERSION = '1.7.0'

‎src/editor.ts

+18
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ export class ComfortableEnvironmentCardEditor extends ScopedRegistryHost(LitElem
5858
return this._config?.display_precision ?? 1;
5959
}
6060

61+
get _index_showinfo(): string {
62+
return this._config?.index_showinfo ?? "ALL";
63+
}
64+
6165
protected render(): TemplateResult | void {
6266
if (!this.hass) {
6367
return html``;
@@ -134,6 +138,20 @@ export class ComfortableEnvironmentCardEditor extends ScopedRegistryHost(LitElem
134138
})}
135139
</mwc-select>
136140
141+
<mwc-select
142+
naturalMenuWidth
143+
fixedMenuPosition
144+
label="${localize('configurator.index_showinfo')}"
145+
.configValue=${'index_showinfo'}
146+
.value=${this._index_showinfo}
147+
@selected=${this._valueChanged}
148+
@closed=${(ev) => ev.stopPropagation()}
149+
>
150+
${['ALL','ICON','ICON_AND_NAME','ICON_AND_TEXT','NAME','NAME_AND_TEXT','TEXT','NONE'].map((entity) => {
151+
return html`<mwc-list-item .value=${entity}>${entity}</mwc-list-item>`;
152+
})}
153+
</mwc-select>
154+
137155
<mwc-select
138156
naturalMenuWidth
139157
fixedMenuPosition

‎src/localize/languages/en.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"hum_sensor": "Humidity Sensor",
1515
"show_index": "Choose which index you want to show",
1616
"display_precision": "Display N numbers after decimal",
17-
"show_realvalues": "Display real values in top right corner"
17+
"show_realvalues": "Display real values in top right corner",
18+
"index_showinfo": "Display index info"
1819
},
1920
"states": {
2021
"hi": {

‎src/localize/languages/it.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"hum_sensor": "Sensore di umidità",
1515
"show_index": "Scegli quale indice mostrare",
1616
"display_precision": "Mostra N numeri dopo la virgola",
17-
"show_realvalues": "Mostra i valori reali in alto a destra"
17+
"show_realvalues": "Mostra i valori reali in alto a destra",
18+
"index_showinfo": "Mostra informazioni per l'indice"
1819
},
1920
"states": {
2021
"hi": {

‎src/localize/languages/pt_BR.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"common": {
3+
"version": "Versão",
4+
"description": "Um cartão para mostrar informação sobre Índice de Calor e/ou Índice de Desconforto com base na temperatura e humidade de uma divisão!",
5+
"invalid_configuration": "A configuração do cartão é inválido ou não existe, por favor verifique!",
6+
"temperature": "Temperatura",
7+
"humidity": "Humidade",
8+
"hi": "Índice de Calor",
9+
"di": "Índice de Desconforto"
10+
},
11+
"configurator": {
12+
"room_name": "Nome da Divisão",
13+
"temp_sensor": "Sensor de Temperatura",
14+
"hum_sensor": "Sensor de Humidade",
15+
"show_index": "Escolha qual(ais) os índices a mostrar",
16+
"display_precision": "Exibir N casas decimais",
17+
"show_realvalues": "Exibir valores reais no canto superior-direito"
18+
},
19+
"states": {
20+
"hi": {
21+
"0": "Bom",
22+
"1": "Cautela",
23+
"2": "Extrema Cautela",
24+
"3": "Perigo",
25+
"4": "Perigo Extremo"
26+
},
27+
"di" : {
28+
"0": "Extremamente desconfortável",
29+
"1": "Moderadamente desconfortável",
30+
"2": "Relativamente confortável",
31+
"3": "Confortável",
32+
"4": "Menos de 50% da população sente desconforto",
33+
"5": "Mais de 50% da população sente desconforto",
34+
"6": "A maioria da população sente desconforto",
35+
"7": "Stress severo em toda a população",
36+
"8": "Estado de emergência médica"
37+
}
38+
}
39+
}

‎src/localize/localize.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as hu from "./languages/hu.json";
88
import * as it from "./languages/it.json";
99
import * as nl from "./languages/nl.json";
1010
import * as pt from "./languages/pt.json";
11+
import * as pt_BR from "./languages/pt_BR.json";
1112
import * as ru from "./languages/ru.json";
1213
import * as sk from "./languages/sk.json";
1314
import * as uk from "./languages/uk.json";
@@ -24,6 +25,7 @@ const languages: any = {
2425
it: it,
2526
nl: nl,
2627
pt: pt,
28+
pt_BR: pt_BR,
2729
ru: ru,
2830
sk: sk,
2931
uk: uk,

‎src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ export interface ComfortableEnvironmentCardConfig extends LovelaceCardConfig {
1414
show_index: string;
1515
display_precision: number;
1616
show_realvalues: string;
17+
index_showinfo: string;
1718
}

0 commit comments

Comments
 (0)
Please sign in to comment.