Skip to content

Commit

Permalink
make 'unit_of_measurement' a configurable field
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
dnguyen800 committed Feb 6, 2023
1 parent afd7a87 commit efb2db3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This is a Home Assistant Lovelace card that uses the [AirVisual component](https
| `weather` | string | optional | `weather.dark_sky` | Name of the weather entity if you wish to display temperature, humidity and wind information on the card. |
| `country` | string | `US` | `mdi:air-conditioner` | Name of the country that Airvisual is collecting AQI data from. |
| `city` | string | optional | `San Francisco` | Name of the city that AirVisual is collecting AQI data from. |
| `unit_of_measurement` | string | optional | `AQI` | Unit of measurement |
| `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. |
| `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. |
| `hide_face` | boolean | `false` | `true` | `false` | Set to `true` if you want to hide the face icon. |
Expand Down
14 changes: 13 additions & 1 deletion dist/air-visual-card-editor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Used weather-card-editor.js from Weather Card as template
// I Used weather-card-editor.js from Weather Card as template
// https://github.com/bramkragten/weather-card
// 2023-02-25 card editor is likely broken as it doesn't show entities,

const fireEvent = (node, type, detail, options) => {
options = options || {};
Expand Down Expand Up @@ -67,6 +68,9 @@ export class AirVisualCardEditor extends LitElement {
get _speed_unit() {
return this._config.speed_unit || "mp/h";
}
get _unit_of_measurement() {
return this._config.unit_of_measurement || "AQI";
}
get _hide_title() {
return this._config.hide_title !== false;
}
Expand Down Expand Up @@ -163,6 +167,14 @@ export class AirVisualCardEditor extends LitElement {
.configValue="${"speed_unit"}"
@value-changed="${this._valueChanged}"
></paper-input>
<paper-input
label="Unit of Measurement (Optional)"
.value="${this._unit_of_measurement}"
.configValue="${"unit_of_measurement"}"
@value-changed="${this._valueChanged}"
></paper-input>
<paper-input
label="Icons location (Optional)"
.value="${this._icons}"
Expand Down
7 changes: 3 additions & 4 deletions dist/air-visual-card.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// To study:
// Plant Picture Card: https://github.com/badguy99/PlantPictureCard/blob/master/dist/PlantPictureCard.js


// UPDATE FOR EACH RELEASE!!! From aftership-card. Version # is hard-coded for now.
console.info(
`%c AIR-VISUAL-CARD \n%c Version 2.0.0 `,
`%c AIR-VISUAL-CARD \n%c Version 2.0.2 `,
'color: orange; font-weight: bold; background: black',
'color: white; font-weight: bold; background: dimgray',
);
Expand Down Expand Up @@ -43,6 +41,7 @@ class AirVisualCard extends HTMLElement {
weather: "weather.home",
hide_weather: 1,
hide_title: 1,
unit_of_measurement: "AQI",
hide_face: 0
}
}
Expand Down Expand Up @@ -260,7 +259,7 @@ class AirVisualCard extends HTMLElement {
const mainPollutantSensor = { name: 'mainPollutantSensor', config: config.main_pollutant || null, value: 0 };
const sensorList = [aqiSensor, aplSensor, mainPollutantSensor];

const unitOfMeasurement = hass.states[aqiSensor.config] ? hass.states[aqiSensor.config].attributes['unit_of_measurement'] : 'AQI';
const unitOfMeasurement = config.unit_of_measurement || 'AQI';

const AQIbgColor = {

Expand Down

0 comments on commit efb2db3

Please sign in to comment.