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

Wind unit (km/h) #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ custom_updater:

#### Configuration variables:

| Name | Optional | Description |
| ------- | -------- | -------------------------------------------------------------------------------------------------- |
| type | **No** | Should be `'custom:weather-card-chart'` |
| title | **No** | Card title |
| weather | **No** | An entity_id with the `weather` domain |
| temp | Yes | Entity_id of the temperature sensor. Show temperature value from sensor instead |
| mode | Yes | Default value: `daily`. Set mode to `hourly` to display hours instead weekdays on the chart |
| Name | Optional | Description |
| --------- | -------- | -------------------------------------------------------------------------------------------------- |
| type | **No** | Should be `'custom:weather-card-chart'` |
| title | **No** | Card title |
| weather | **No** | An entity_id with the `weather` domain |
| temp | Yes | Entity_id of the temperature sensor. Show temperature value from sensor instead |
| mode | Yes | Default value: `daily`. Set mode to `hourly` to display hours instead weekdays on the chart |
| wind_unit | Yes | Default value: `ms`. Set mode to `kmh` to use km/h units for wind speed |
46 changes: 36 additions & 10 deletions custom-weather-card-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const locale = {
tempLo: "Temperatur nat",
precip: "Nedbør",
uPress: "hPa",
uSpeed: "m/s",
uSpeed: {
"ms": "m/s",
"kmh": "km/h"
},
uPrecip: "mm",
cardinalDirections: [
'N', 'N-NØ', 'NØ', 'Ø-NØ', 'Ø', 'Ø-SØ', 'SØ', 'S-SØ',
Expand All @@ -16,7 +19,10 @@ const locale = {
tempLo: "Temperature night",
precip: "Precipitations",
uPress: "hPa",
uSpeed: "m/s",
uSpeed: {
"ms": "m/s",
"kmh": "km/h"
},
uPrecip: "mm",
cardinalDirections: [
'N', 'N-NE', 'NE', 'E-NE', 'E', 'E-SE', 'SE', 'S-SE',
Expand All @@ -28,7 +34,10 @@ const locale = {
tempLo: "Température nuit",
precip: "Précipitations",
uPress: "hPa",
uSpeed: "m/s",
uSpeed: {
"ms": "m/s",
"kmh": "km/h"
},
uPrecip: "mm",
cardinalDirections: [
'N', 'N-NE', 'NE', 'E-NE', 'E', 'E-SE', 'SE', 'S-SE',
Expand All @@ -40,7 +49,10 @@ const locale = {
tempLo: "Minimum temperatuur",
precip: "Neerslag",
uPress: "hPa",
uSpeed: "m/s",
uSpeed: {
"ms": "m/s",
"kmh": "km/h"
},
uPrecip: "mm",
cardinalDirections: [
'N', 'N-NO', 'NO', 'O-NO', 'O', 'O-ZO', 'ZO', 'Z-ZO',
Expand All @@ -51,8 +63,11 @@ const locale = {
tempHi: "Температура",
tempLo: "Температура ночью",
precip: "Осадки",
uPress: "гПа",
uSpeed: "м/с",
uPress: "",
uSpeed: {
"ms": "гПа",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error in lines 66-68. Correct version:

    uPress: "гПа",
    uSpeed: {
      "ms": "м/с",

"kmh": "км/ч"
},
uPrecip: "мм",
cardinalDirections: [
'С', 'С-СВ', 'СВ', 'В-СВ', 'В', 'В-ЮВ', 'ЮВ', 'Ю-ЮВ',
Expand All @@ -64,7 +79,10 @@ const locale = {
tempLo: "Temperatur natt",
precip: "Nederbörd",
uPress: "hPa",
uSpeed: "m/s",
uSpeed: {
"ms": "m/s",
"kmh": "km/h"
},
uPrecip: "mm",
cardinalDirections: [
'N', 'N-NO', 'NO', 'O-NO', 'O', 'O-SO', 'SO', 'S-SO',
Expand Down Expand Up @@ -144,7 +162,7 @@ class WeatherCardChart extends Polymer.Element {
</div>
<div>
<ha-icon icon="hass:[[getWindDirIcon(windBearing)]]"></ha-icon> [[getWindDir(windBearing)]]<br>
<ha-icon icon="hass:weather-windy"></ha-icon> [[computeWind(weatherObj.attributes.wind_speed)]] [[ll('uSpeed')]]
<ha-icon icon="hass:weather-windy"></ha-icon> [[computeWind(weatherObj.attributes.wind_speed)]] [[getWindUnit()]]
</div>
</div>
<ha-chart-base data="[[ChartData]]"></ha-chart-base>
Expand Down Expand Up @@ -176,6 +194,7 @@ class WeatherCardChart extends Polymer.Element {
constructor() {
super();
this.mode = 'daily';
this.windUnit = 'ms';
this.weatherIcons = {
'clear-night': 'hass:weather-night',
'cloudy': 'hass:weather-cloudy',
Expand Down Expand Up @@ -205,6 +224,7 @@ class WeatherCardChart extends Polymer.Element {
this.weatherObj = config.weather;
this.tempObj = config.temp;
this.mode = config.mode;
this.windUnit = config.wind_unit || 'ms';
if (!config.weather) {
throw new Error('Please define "weather" entity in the card config');
}
Expand Down Expand Up @@ -243,8 +263,10 @@ class WeatherCardChart extends Polymer.Element {
}

computeWind(speed) {
var calcSpeed = Math.round(speed * 1000 / 3600);
return calcSpeed;
if (this.windUnit === 'ms')
return Math.round(speed * 1000 / 3600);
else
return speed;
}

getCardSize() {
Expand All @@ -259,6 +281,10 @@ class WeatherCardChart extends Polymer.Element {
return this.weatherIcons[condition];
}

getWindUnit() {
return this.ll('uSpeed')[this.windUnit];
}

getWindDirIcon(degree) {
return this.cardinalDirectionsIcon[parseInt((degree + 22.5) / 45.0)];
}
Expand Down