Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Use import from 'lit' package
Browse files Browse the repository at this point in the history
  • Loading branch information
Yevgenium committed Oct 30, 2021
1 parent bc55ae8 commit 0f82413
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"author": "Yevgeniy Prokopenko",
"license": "MIT",
"dependencies": {
"lit": "^2.0.2",
"chart.js": "^3.5.1",
"chartjs-plugin-datalabels": "^2.0.0"
},
Expand Down
24 changes: 11 additions & 13 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import {
weatherIconsDay,
weatherIconsNight
} from './const.js';
import { Chart, registerables } from 'chart.js';
import {LitElement, html} from 'lit';
import {Chart, registerables} from 'chart.js';
import ChartDataLabels from 'chartjs-plugin-datalabels';
Chart.register(...registerables, ChartDataLabels);

const LitElement = Object.getPrototypeOf(customElements.get("ha-panel-lovelace"));
const html = LitElement.prototype.html;

class WeatherChartCard extends LitElement {

static getStubConfig() {
Expand Down Expand Up @@ -123,7 +121,7 @@ class WeatherChartCard extends LitElement {
this.forecastItems = Math.round(card.offsetWidth / 56);
}

drawChart({ config, language, weather, forecastItems } = this) {
drawChart({config, language, weather, forecastItems} = this) {
if (!weather || !weather.attributes || !weather.attributes.forecast) {
return [];
}
Expand Down Expand Up @@ -320,7 +318,7 @@ class WeatherChartCard extends LitElement {
});
}

updateChart({ weather, forecastItems, forecastChart } = this) {
updateChart({weather, forecastItems, forecastChart} = this) {
if (!weather || !weather.attributes || !weather.attributes.forecast) {
return [];
}
Expand Down Expand Up @@ -348,7 +346,7 @@ class WeatherChartCard extends LitElement {
}
}

render({ config, _hass, weather, forecastItems } = this) {
render({config, _hass, weather, forecastItems} = this) {
if (!config || !_hass) {
return html``;
}
Expand Down Expand Up @@ -380,7 +378,7 @@ class WeatherChartCard extends LitElement {
height: ${this.iconSize}px;
}
.card {
padding-top: ${config.title? '0px' : '16px'};
padding-top: ${config.title ? '0px' : '16px'};
padding-right: 16px;
padding-bottom: 16px;
padding-left: 16px;
Expand Down Expand Up @@ -456,7 +454,7 @@ class WeatherChartCard extends LitElement {
`;
}

renderMain({ config, sun, weather, temperature } = this) {
renderMain({config, sun, weather, temperature} = this) {
if (config.show_main == false)
return html``;
return html`
Expand All @@ -483,7 +481,7 @@ class WeatherChartCard extends LitElement {
`;
}

renderAttributes({ config, humidity, pressure, windSpeed, windDirection } = this) {
renderAttributes({config, humidity, pressure, windSpeed, windDirection} = this) {
if (this.unitSpeed === 'm/s') {
windSpeed = Math.round(windSpeed * 1000 / 3600);
}
Expand All @@ -495,8 +493,8 @@ class WeatherChartCard extends LitElement {
return html`
<div class="attributes">
<div>
<ha-icon icon="hass:water-percent"></ha-icon> ${Math.round(humidity)} %<br>
<ha-icon icon="hass:gauge"></ha-icon> ${Math.round(pressure)} ${this.ll('units')[this.unitPressure]}
<ha-icon icon="hass:water-percent"></ha-icon> ${humidity} %<br>
<ha-icon icon="hass:gauge"></ha-icon> ${pressure} ${this.ll('units')[this.unitPressure]}
</div>
<div>
${this.renderSun()}
Expand All @@ -509,7 +507,7 @@ class WeatherChartCard extends LitElement {
`;
}

renderSun({ sun, language } = this) {
renderSun({sun, language} = this) {
if ( sun == undefined)
return html``;
return html`
Expand Down

0 comments on commit 0f82413

Please sign in to comment.