From 399536a0122bc21ecb7c216112923b7af32bb510 Mon Sep 17 00:00:00 2001 From: Christos Baltatzidis <68458228+Chreece@users.noreply.github.com> Date: Mon, 11 Nov 2024 11:45:12 +0100 Subject: [PATCH 1/7] AQI as dominant pollutant for WAQI --- dist/air-visual-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/air-visual-card.js b/dist/air-visual-card.js index 470384f..d7fb43e 100644 --- a/dist/air-visual-card.js +++ b/dist/air-visual-card.js @@ -404,7 +404,7 @@ class AirVisualCard extends HTMLElement { mainPollutant = mainAirVisualPollutantValue[hass.states[mainPollutantSensor.config].attributes['pollutant_symbol']]; } else if (validPollutants.includes(mpParse)) { mainPollutant = mainPollutantValue[mpParse]; - pollutantUnit = mainPollutantUnit[mpParse]; + pollutantUnit = 'AQI'; } else { pollutantUnit = 'pollutant unit'; mainPollutant = 'main pollutant'; From 9aafca02a8ca829befaad8e4a5b72d212d326655 Mon Sep 17 00:00:00 2001 From: Chris Chreece <68458228+Chreece@users.noreply.github.com> Date: Tue, 12 Nov 2024 09:50:05 +0100 Subject: [PATCH 2/7] No default weather entity --- dist/air-visual-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/air-visual-card.js b/dist/air-visual-card.js index d7fb43e..8183e68 100644 --- a/dist/air-visual-card.js +++ b/dist/air-visual-card.js @@ -38,7 +38,7 @@ class AirVisualCard extends HTMLElement { return { air_pollution_level: "sensor.u_s_air_pollution_level", air_quality_index: "sensor.u_s_air_quality_index", main_pollutant: "sensor.u_s_main_pollutant", - weather: "weather.home", + weather: "", hide_weather: 1, hide_title: 1, unit_of_measurement: "AQI", From b69eb5804f6720260c222c00b9b0d94bfb96d43f Mon Sep 17 00:00:00 2001 From: Christos Baltatzidis <68458228+Chreece@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:29:18 +0100 Subject: [PATCH 3/7] try to fix AirVisual Classsification --- dist/air-visual-card.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/dist/air-visual-card.js b/dist/air-visual-card.js index d7fb43e..9f839f9 100644 --- a/dist/air-visual-card.js +++ b/dist/air-visual-card.js @@ -258,7 +258,6 @@ class AirVisualCard extends HTMLElement { const aqiSensor = { name: 'aqiSensor', config: config.air_quality_index || null, value: 0 }; const aplSensor = { name: 'aplSensor', config: config.air_pollution_level || null, value: 0 }; const mainPollutantSensor = { name: 'mainPollutantSensor', config: config.main_pollutant || null, value: '' }; - const sensorList = [aqiSensor, aplSensor, mainPollutantSensor]; const validPollutants = ['co', 'no2', 'o3', 'so2', 'pm10', 'pm25', 'neph']; const unitOfMeasurement = config.unit_of_measurement || 'AQI'; @@ -374,19 +373,19 @@ class AirVisualCard extends HTMLElement { let apl = ''; let mainPollutant = ''; let speed_unit = speedUnit; - let getAQI = function () { - switch (true) { - case (aqiSensor.value <= 50): + let getAQI = function (value) { + switch (value) { + case (value <= 50): return '1'; // return string '1' to pull appropriate AQI icon filename ('ic-face-1.svg') in HTML - case (aqiSensor.value <= 100): + case (value <= 100): return '2'; - case (aqiSensor.value <= 150): + case (value <= 150): return '3'; - case (aqiSensor.value <= 200): + case (value <= 200): return '4'; - case (aqiSensor.value <= 300): + case (value <= 300): return '5'; - case (aqiSensor.value <= 9999): + case (value <= 9999): return '6'; default: return '1'; @@ -410,20 +409,19 @@ class AirVisualCard extends HTMLElement { mainPollutant = 'main pollutant'; } } - if (typeof hass.states[aqiSensor.config] != "undefined") { - aqiSensor.value = hass.states[aqiSensor.config].state; - } + // Check if APL is an WAQI sensor (because the state is an integer). Returns 'NaN' if it is not a number if (typeof hass.states[aplSensor.config] != "undefined") { let aplParse = parseInt(hass.states[aplSensor.config].state); if (!isNaN(aplParse)) { - apl = APLdescription[getAQI()]; + apl = APLdescription[getAQI(aplParse)]; } else { let aplState = hass.states[aplSensor.config].state; apl = hass.localize("component.sensor.state.airvisual__pollutant_level." + aplState) } - } else if (aqiSensor.value != 0) { - apl = APLdescription[getAQI()]; + } else if (typeof hass.states[aqiSensor.config] != "undefined") { + let aplParse = parseInt(hass.states[aqiSensor.config].state); + apl = APLdescription[getAQI(aplParse)]; } From 1fc9a4afe75cbee151b903fce233d641aa9b4c44 Mon Sep 17 00:00:00 2001 From: Christos Baltatzidis <68458228+Chreece@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:33:59 +0100 Subject: [PATCH 4/7] modified: dist/air-visual-card.js --- dist/air-visual-card.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/dist/air-visual-card.js b/dist/air-visual-card.js index c198def..d7fb43e 100644 --- a/dist/air-visual-card.js +++ b/dist/air-visual-card.js @@ -38,7 +38,7 @@ class AirVisualCard extends HTMLElement { return { air_pollution_level: "sensor.u_s_air_pollution_level", air_quality_index: "sensor.u_s_air_quality_index", main_pollutant: "sensor.u_s_main_pollutant", - weather: "", + weather: "weather.home", hide_weather: 1, hide_title: 1, unit_of_measurement: "AQI", @@ -258,6 +258,7 @@ class AirVisualCard extends HTMLElement { const aqiSensor = { name: 'aqiSensor', config: config.air_quality_index || null, value: 0 }; const aplSensor = { name: 'aplSensor', config: config.air_pollution_level || null, value: 0 }; const mainPollutantSensor = { name: 'mainPollutantSensor', config: config.main_pollutant || null, value: '' }; + const sensorList = [aqiSensor, aplSensor, mainPollutantSensor]; const validPollutants = ['co', 'no2', 'o3', 'so2', 'pm10', 'pm25', 'neph']; const unitOfMeasurement = config.unit_of_measurement || 'AQI'; @@ -373,19 +374,19 @@ class AirVisualCard extends HTMLElement { let apl = ''; let mainPollutant = ''; let speed_unit = speedUnit; - let getAQI = function (value) { - switch (value) { - case (value <= 50): + let getAQI = function () { + switch (true) { + case (aqiSensor.value <= 50): return '1'; // return string '1' to pull appropriate AQI icon filename ('ic-face-1.svg') in HTML - case (value <= 100): + case (aqiSensor.value <= 100): return '2'; - case (value <= 150): + case (aqiSensor.value <= 150): return '3'; - case (value <= 200): + case (aqiSensor.value <= 200): return '4'; - case (value <= 300): + case (aqiSensor.value <= 300): return '5'; - case (value <= 9999): + case (aqiSensor.value <= 9999): return '6'; default: return '1'; @@ -409,19 +410,20 @@ class AirVisualCard extends HTMLElement { mainPollutant = 'main pollutant'; } } - + if (typeof hass.states[aqiSensor.config] != "undefined") { + aqiSensor.value = hass.states[aqiSensor.config].state; + } // Check if APL is an WAQI sensor (because the state is an integer). Returns 'NaN' if it is not a number if (typeof hass.states[aplSensor.config] != "undefined") { let aplParse = parseInt(hass.states[aplSensor.config].state); if (!isNaN(aplParse)) { - apl = APLdescription[getAQI(aplParse)]; + apl = APLdescription[getAQI()]; } else { let aplState = hass.states[aplSensor.config].state; apl = hass.localize("component.sensor.state.airvisual__pollutant_level." + aplState) } - } else if (typeof hass.states[aqiSensor.config] != "undefined") { - let aplParse = parseInt(hass.states[aqiSensor.config].state); - apl = APLdescription[getAQI(aplParse)]; + } else if (aqiSensor.value != 0) { + apl = APLdescription[getAQI()]; } From 8760faba702c1edc9d15c050b687f109c3f5df2c Mon Sep 17 00:00:00 2001 From: Christos Baltatzidis <68458228+Chreece@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:34:43 +0100 Subject: [PATCH 5/7] modified: dist/air-visual-card.js --- dist/air-visual-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/air-visual-card.js b/dist/air-visual-card.js index d7fb43e..8183e68 100644 --- a/dist/air-visual-card.js +++ b/dist/air-visual-card.js @@ -38,7 +38,7 @@ class AirVisualCard extends HTMLElement { return { air_pollution_level: "sensor.u_s_air_pollution_level", air_quality_index: "sensor.u_s_air_quality_index", main_pollutant: "sensor.u_s_main_pollutant", - weather: "weather.home", + weather: "", hide_weather: 1, hide_title: 1, unit_of_measurement: "AQI", From 43f4ec1151124c8c5295089eafffdca172911f3c Mon Sep 17 00:00:00 2001 From: Christos Baltatzidis <68458228+Chreece@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:49:07 +0100 Subject: [PATCH 6/7] some fixes --- dist/air-visual-card.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/dist/air-visual-card.js b/dist/air-visual-card.js index 8183e68..90a9b92 100644 --- a/dist/air-visual-card.js +++ b/dist/air-visual-card.js @@ -258,7 +258,6 @@ class AirVisualCard extends HTMLElement { const aqiSensor = { name: 'aqiSensor', config: config.air_quality_index || null, value: 0 }; const aplSensor = { name: 'aplSensor', config: config.air_pollution_level || null, value: 0 }; const mainPollutantSensor = { name: 'mainPollutantSensor', config: config.main_pollutant || null, value: '' }; - const sensorList = [aqiSensor, aplSensor, mainPollutantSensor]; const validPollutants = ['co', 'no2', 'o3', 'so2', 'pm10', 'pm25', 'neph']; const unitOfMeasurement = config.unit_of_measurement || 'AQI'; @@ -377,7 +376,7 @@ class AirVisualCard extends HTMLElement { let getAQI = function () { switch (true) { case (aqiSensor.value <= 50): - return '1'; // return string '1' to pull appropriate AQI icon filename ('ic-face-1.svg') in HTML + return '1'; case (aqiSensor.value <= 100): return '2'; case (aqiSensor.value <= 150): @@ -386,7 +385,7 @@ class AirVisualCard extends HTMLElement { return '4'; case (aqiSensor.value <= 300): return '5'; - case (aqiSensor.value <= 9999): + case (aqiSensor.value > 300): return '6'; default: return '1'; @@ -410,19 +409,18 @@ class AirVisualCard extends HTMLElement { mainPollutant = 'main pollutant'; } } - if (typeof hass.states[aqiSensor.config] != "undefined") { - aqiSensor.value = hass.states[aqiSensor.config].state; - } // Check if APL is an WAQI sensor (because the state is an integer). Returns 'NaN' if it is not a number if (typeof hass.states[aplSensor.config] != "undefined") { let aplParse = parseInt(hass.states[aplSensor.config].state); + aqiSensor.value = aplParse; if (!isNaN(aplParse)) { apl = APLdescription[getAQI()]; } else { let aplState = hass.states[aplSensor.config].state; apl = hass.localize("component.sensor.state.airvisual__pollutant_level." + aplState) } - } else if (aqiSensor.value != 0) { + } else if (typeof hass.states[aqiSensor.config] != "undefined") { + aqiSensor.value = hass.states[aqiSensor.config].state; apl = APLdescription[getAQI()]; } From 97941ee1191a8f6c8e4ae6ca154683da42ddb5df Mon Sep 17 00:00:00 2001 From: Christos Baltatzidis <68458228+Chreece@users.noreply.github.com> Date: Tue, 12 Nov 2024 17:37:32 +0100 Subject: [PATCH 7/7] fix AirVisual --- dist/air-visual-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/air-visual-card.js b/dist/air-visual-card.js index 90a9b92..41d25be 100644 --- a/dist/air-visual-card.js +++ b/dist/air-visual-card.js @@ -411,7 +411,7 @@ class AirVisualCard extends HTMLElement { } // Check if APL is an WAQI sensor (because the state is an integer). Returns 'NaN' if it is not a number if (typeof hass.states[aplSensor.config] != "undefined") { - let aplParse = parseInt(hass.states[aplSensor.config].state); + let aplParse = parseInt(hass.states[aqiSensor.config].state); aqiSensor.value = aplParse; if (!isNaN(aplParse)) { apl = APLdescription[getAQI()];