Skip to content

Commit

Permalink
fixed battery
Browse files Browse the repository at this point in the history
  • Loading branch information
bhuebschen committed May 21, 2024
1 parent 2ff78bf commit ba9cde8
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import localize from './localize';
import { LawnMowerCardConfig } from './types';

export default function buildConfig(
config?: Partial<LawnMowerCardConfig>
config?: Partial<LawnMowerCardConfig>,
): LawnMowerCardConfig {
if (!config) {
throw new Error(localize('error.invalid_config'));
Expand Down
27 changes: 16 additions & 11 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ type ConfigElement = HTMLInputElement & {
};

@customElement('lawn-mower-card-editor')
export class LawnMowerCardEditor extends LitElement implements LovelaceCardEditor {
export class LawnMowerCardEditor
extends LitElement
implements LovelaceCardEditor
{
@property({ attribute: false }) public hass?: HomeAssistant;

@state() private config!: Partial<LawnMowerCardConfig>;
Expand Down Expand Up @@ -68,9 +71,10 @@ export class LawnMowerCardEditor extends LitElement implements LovelaceCardEdito
validationMessage=${localize('error.missing_entity')}
>
${lawnMowerEntities.map(
(entity) => html` <mwc-list-item .value=${entity}
>${entity}</mwc-list-item
>`
(entity) =>
html` <mwc-list-item .value=${entity}
>${entity}</mwc-list-item
>`,
)}
</ha-select>
</div>
Expand All @@ -86,9 +90,10 @@ export class LawnMowerCardEditor extends LitElement implements LovelaceCardEdito
naturalMenuWidth
>
${cameraEntities.map(
(entity) => html` <mwc-list-item .value=${entity}
>${entity}</mwc-list-item
>`
(entity) =>
html` <mwc-list-item .value=${entity}
>${entity}</mwc-list-item
>`,
)}
</ha-select>
</div>
Expand All @@ -107,7 +112,7 @@ export class LawnMowerCardEditor extends LitElement implements LovelaceCardEdito
aria-label=${localize(
this.compact_view
? 'editor.compact_view_aria_label_off'
: 'editor.compact_view_aria_label_on'
: 'editor.compact_view_aria_label_on',
)}
.checked=${Boolean(this.compact_view)}
.configValue=${'compact_view'}
Expand All @@ -122,7 +127,7 @@ export class LawnMowerCardEditor extends LitElement implements LovelaceCardEdito
aria-label=${localize(
this.show_name
? 'editor.show_name_aria_label_off'
: 'editor.show_name_aria_label_on'
: 'editor.show_name_aria_label_on',
)}
.checked=${Boolean(this.show_name)}
.configValue=${'show_name'}
Expand All @@ -137,7 +142,7 @@ export class LawnMowerCardEditor extends LitElement implements LovelaceCardEdito
aria-label=${localize(
this.show_status
? 'editor.show_status_aria_label_off'
: 'editor.show_status_aria_label_on'
: 'editor.show_status_aria_label_on',
)}
.checked=${Boolean(this.show_status)}
.configValue=${'show_status'}
Expand All @@ -152,7 +157,7 @@ export class LawnMowerCardEditor extends LitElement implements LovelaceCardEdito
aria-label=${localize(
this.show_toolbar
? 'editor.show_toolbar_aria_label_off'
: 'editor.show_toolbar_aria_label_on'
: 'editor.show_toolbar_aria_label_on',
)}
.checked=${Boolean(this.show_toolbar)}
.configValue=${'show_toolbar'}
Expand Down
47 changes: 40 additions & 7 deletions src/lawn-mower-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export class LawnMowerCard extends LitElement {
}

static getStubConfig(_: unknown, entities: string[]) {
const [lawnMowerEntity] = entities.filter((eid) => eid.startsWith('lawn-mower'));
const [lawnMowerEntity] = entities.filter((eid) =>
eid.startsWith('lawn-mower'),
);

return {
entity: lawnMowerEntity ?? '',
Expand Down Expand Up @@ -155,7 +157,11 @@ export class LawnMowerCard extends LitElement {

private handleSpeed(e: PointerEvent): void {
const fan_speed = (<HTMLDivElement>e.target).getAttribute('value');
this.callLawnMowerService('set_fan_speed', { request: false }, { fan_speed });
this.callLawnMowerService(
'set_fan_speed',
{ request: false },
{ fan_speed },
);
}

private handleLawnMowerAction(
Expand All @@ -164,7 +170,10 @@ export class LawnMowerCard extends LitElement {
) {
return () => {
if (!this.config.actions[action]) {
return this.callLawnMowerService(params.defaultService || action, params);
return this.callLawnMowerService(
params.defaultService || action,
params,
);
}

this.callService(this.config.actions[action]);
Expand Down Expand Up @@ -217,7 +226,25 @@ export class LawnMowerCard extends LitElement {
}

private renderBattery(): Template {
const { battery_level, battery_icon } = this.getAttributes(this.entity);
let battery_level;
let battery_icon;

if (this.config.battery) {
battery_level = Number(this.hass.states[this.config.battery].state);

const level = Number(battery_level);

if (level > 90) {
battery_icon = 'mdi:battery';
} else if (level < 10) {
battery_icon = 'mdi:battery-outline';
} else {
const iconLevel = Math.floor(level / 10) * 10;
battery_icon = `mdi:battery-${iconLevel}`;
}
} else {
({ battery_level, battery_icon } = this.getAttributes(this.entity));
}

return html`
<div class="tip" @click="${() => this.handleMore()}">
Expand Down Expand Up @@ -358,7 +385,9 @@ export class LawnMowerCard extends LitElement {
<ha-icon icon="hass:stop"></ha-icon>
${localize('common.stop')}
</paper-button>
<paper-button @click="${this.handleLawnMowerAction('return_to_base')}">
<paper-button
@click="${this.handleLawnMowerAction('return_to_base')}"
>
<ha-icon icon="hass:home-map-marker"></ha-icon>
${localize('common.return_to_base')}
</paper-button>
Expand All @@ -378,7 +407,9 @@ export class LawnMowerCard extends LitElement {
<ha-icon icon="hass:play"></ha-icon>
${localize('common.continue')}
</paper-button>
<paper-button @click="${this.handleLawnMowerAction('return_to_base')}">
<paper-button
@click="${this.handleLawnMowerAction('return_to_base')}"
>
<ha-icon icon="hass:home-map-marker"></ha-icon>
${localize('common.return_to_base')}
</paper-button>
Expand Down Expand Up @@ -441,7 +472,9 @@ export class LawnMowerCard extends LitElement {
<ha-icon-button
label="${localize('common.locate')}"
@click="${this.handleLawnMowerAction('locate', { request: false })}"
@click="${this.handleLawnMowerAction('locate', {
request: false,
})}"
><ha-icon icon="mdi:map-marker"></ha-icon>
</ha-icon-button>
Expand Down
2 changes: 1 addition & 1 deletion src/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const DEFAULT_LANG = 'en';
export default function localize(
str: string,
search?: string,
replace?: string
replace?: string,
): string | undefined {
const [section, key] = str.toLowerCase().split('.');

Expand Down
2 changes: 1 addition & 1 deletion src/translations/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@
"show_toolbar_aria_label_off": "Eszköztár megjelenítésének kikapcsolása",
"code_only_note": "Megjegyzés: A műveletek és statisztika beállítások kizárólag a kód szerkesztő használatával érhetők el."
}
}
}
2 changes: 1 addition & 1 deletion src/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"show_name_aria_label_off": "Disattiva nome",
"show_status": "Mostra Stato",
"show_status_aria_label_on": "Attiva stato",
"show_status_aria_label_off": "Disattiva stato",
"show_status_aria_label_off": "Disattiva stato",
"show_toolbar": "Mostra barra degli strumenti",
"show_toolbar_aria_label_on": "Attiva barra degli strumenti",
"show_toolbar_aria_label_off": "Disattiva barra degli strumenti",
Expand Down
126 changes: 63 additions & 63 deletions src/translations/pt-BR.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
{
"status": {
"cleaning": "Limpando",
"auto": "Limpeza automatica",
"spot": "Limpando local",
"edge": "Limpando borda",
"single_room": "Limpando um quarto",
"paused": "Em pausa",
"idle": "Ocioso",
"stop": "Parado",
"charging": "Carregando",
"returning home": "Voltando à base",
"returning": "Voltando",
"docked": "Na base",
"unknown": "Desconhecido",
"offline": "Offline",
"error": "Erro"
},
"source": {
"gentle": "Delicado",
"silent": "Silencioso",
"standard": "Padrão",
"medium": "Médio",
"turbo": "Turbo",
"normal": "Normal",
"high": "Alto",
"strong": "Forte"
},
"common": {
"name": "Vacuum Card",
"description": "Vacuum card para controlar seu robô aspirador.",
"start": "Limpar",
"continue": "Continuar",
"pause": "Pausa",
"stop": "Parar",
"return_to_base": "Retornar à base",
"locate": "Localizar aspirador",
"not_available": "Aspirador indisponível"
},
"error": {
"missing_entity": "Entidade obrigatória"
},
"warning": {
"actions_array": "AVISO: 'actions' são reservadas para substituir as ações padrões para botões existentes. Se sua intenção era adicionar ações adicionais, use a opção 'shortcuts'."
},
"editor": {
"entity": "Entidade (Obrigatória)",
"map": "Mapa (Opcional)",
"image": "Imagem (Opcional)",
"compact_view": "Vista Compacta",
"compact_view_aria_label_on": "Ativar visualização compacta",
"compact_view_aria_label_off": "Desativar visualização compacta",
"show_name": "Mostrar nome",
"show_name_aria_label_on": "Mostrar nome",
"show_name_aria_label_off": "Ocultar nome",
"show_status": "Mostrar estado",
"show_status_aria_label_on": "Mostrar estado",
"show_status_aria_label_off": "Ocultar estado",
"show_toolbar": "Mostrar barra de ferramentas",
"show_toolbar_aria_label_on": "Mostrar barra de ferramentas",
"show_toolbar_aria_label_off": "Ocultar barra de ferramentas",
"code_only_note": "Nota: Ações e estatísticas estão disponiveis exclusivamente usando o editor de código."
}
}
"status": {
"cleaning": "Limpando",
"auto": "Limpeza automatica",
"spot": "Limpando local",
"edge": "Limpando borda",
"single_room": "Limpando um quarto",
"paused": "Em pausa",
"idle": "Ocioso",
"stop": "Parado",
"charging": "Carregando",
"returning home": "Voltando à base",
"returning": "Voltando",
"docked": "Na base",
"unknown": "Desconhecido",
"offline": "Offline",
"error": "Erro"
},
"source": {
"gentle": "Delicado",
"silent": "Silencioso",
"standard": "Padrão",
"medium": "Médio",
"turbo": "Turbo",
"normal": "Normal",
"high": "Alto",
"strong": "Forte"
},
"common": {
"name": "Vacuum Card",
"description": "Vacuum card para controlar seu robô aspirador.",
"start": "Limpar",
"continue": "Continuar",
"pause": "Pausa",
"stop": "Parar",
"return_to_base": "Retornar à base",
"locate": "Localizar aspirador",
"not_available": "Aspirador indisponível"
},
"error": {
"missing_entity": "Entidade obrigatória"
},
"warning": {
"actions_array": "AVISO: 'actions' são reservadas para substituir as ações padrões para botões existentes. Se sua intenção era adicionar ações adicionais, use a opção 'shortcuts'."
},
"editor": {
"entity": "Entidade (Obrigatória)",
"map": "Mapa (Opcional)",
"image": "Imagem (Opcional)",
"compact_view": "Vista Compacta",
"compact_view_aria_label_on": "Ativar visualização compacta",
"compact_view_aria_label_off": "Desativar visualização compacta",
"show_name": "Mostrar nome",
"show_name_aria_label_on": "Mostrar nome",
"show_name_aria_label_off": "Ocultar nome",
"show_status": "Mostrar estado",
"show_status_aria_label_on": "Mostrar estado",
"show_status_aria_label_off": "Ocultar estado",
"show_toolbar": "Mostrar barra de ferramentas",
"show_toolbar_aria_label_on": "Mostrar barra de ferramentas",
"show_toolbar_aria_label_off": "Ocultar barra de ferramentas",
"code_only_note": "Nota: Ações e estatísticas estão disponiveis exclusivamente usando o editor de código."
}
}

0 comments on commit ba9cde8

Please sign in to comment.