Skip to content

Commit efb2db3

Browse files
committed
make 'unit_of_measurement' a configurable field
unit_of_measurement attribute is no longer provided to AirVisual sensors, so I updated attribute to be configurable. The card editor is broken, so you will need to configure the card via YAML. use the following YAML in your card to configure: unit_of_measurement: 'AQI'
1 parent afd7a87 commit efb2db3

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This is a Home Assistant Lovelace card that uses the [AirVisual component](https
2121
| `weather` | string | optional | `weather.dark_sky` | Name of the weather entity if you wish to display temperature, humidity and wind information on the card. |
2222
| `country` | string | `US` | `mdi:air-conditioner` | Name of the country that Airvisual is collecting AQI data from. |
2323
| `city` | string | optional | `San Francisco` | Name of the city that AirVisual is collecting AQI data from. |
24+
| `unit_of_measurement` | string | optional | `AQI` | Unit of measurement |
2425
| `icons` | string | `/hacsfiles/air-visual-card` | `/hacsfiles/air-visual-card` | The local directory where the .svg files are located. For example, 'icons: "/hacsfiles/air-visual-card"' is appropriate if this plugin is installed using HACS. If left blank, icons will be loaded from default location. |
2526
| `hide_title` | boolean | `true` | `true` | `false` | Set to `true` if you want to hide the title that includes the city name. Useful for minimalists or those using dark themes. |
2627
| `hide_face` | boolean | `false` | `true` | `false` | Set to `true` if you want to hide the face icon. |

dist/air-visual-card-editor.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// Used weather-card-editor.js from Weather Card as template
1+
// I Used weather-card-editor.js from Weather Card as template
22
// https://github.com/bramkragten/weather-card
3+
// 2023-02-25 card editor is likely broken as it doesn't show entities,
34

45
const fireEvent = (node, type, detail, options) => {
56
options = options || {};
@@ -67,6 +68,9 @@ export class AirVisualCardEditor extends LitElement {
6768
get _speed_unit() {
6869
return this._config.speed_unit || "mp/h";
6970
}
71+
get _unit_of_measurement() {
72+
return this._config.unit_of_measurement || "AQI";
73+
}
7074
get _hide_title() {
7175
return this._config.hide_title !== false;
7276
}
@@ -163,6 +167,14 @@ export class AirVisualCardEditor extends LitElement {
163167
.configValue="${"speed_unit"}"
164168
@value-changed="${this._valueChanged}"
165169
></paper-input>
170+
171+
<paper-input
172+
label="Unit of Measurement (Optional)"
173+
.value="${this._unit_of_measurement}"
174+
.configValue="${"unit_of_measurement"}"
175+
@value-changed="${this._valueChanged}"
176+
></paper-input>
177+
166178
<paper-input
167179
label="Icons location (Optional)"
168180
.value="${this._icons}"

dist/air-visual-card.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// To study:
22
// Plant Picture Card: https://github.com/badguy99/PlantPictureCard/blob/master/dist/PlantPictureCard.js
3-
4-
53
// UPDATE FOR EACH RELEASE!!! From aftership-card. Version # is hard-coded for now.
64
console.info(
7-
`%c AIR-VISUAL-CARD \n%c Version 2.0.0 `,
5+
`%c AIR-VISUAL-CARD \n%c Version 2.0.2 `,
86
'color: orange; font-weight: bold; background: black',
97
'color: white; font-weight: bold; background: dimgray',
108
);
@@ -43,6 +41,7 @@ class AirVisualCard extends HTMLElement {
4341
weather: "weather.home",
4442
hide_weather: 1,
4543
hide_title: 1,
44+
unit_of_measurement: "AQI",
4645
hide_face: 0
4746
}
4847
}
@@ -260,7 +259,7 @@ class AirVisualCard extends HTMLElement {
260259
const mainPollutantSensor = { name: 'mainPollutantSensor', config: config.main_pollutant || null, value: 0 };
261260
const sensorList = [aqiSensor, aplSensor, mainPollutantSensor];
262261

263-
const unitOfMeasurement = hass.states[aqiSensor.config] ? hass.states[aqiSensor.config].attributes['unit_of_measurement'] : 'AQI';
262+
const unitOfMeasurement = config.unit_of_measurement || 'AQI';
264263

265264
const AQIbgColor = {
266265

0 commit comments

Comments
 (0)