From 8e4e6a50d8de8cfda1e444a683a8b2157a7df7bd Mon Sep 17 00:00:00 2001 From: Jasper van der Neut - Stulen Date: Wed, 17 Apr 2019 19:27:59 +0200 Subject: [PATCH] Only create sensors if the station actually has values for them. (#20643) Because Luftdaten assigns separate ids for particle and weather measurements, most if not all stations added with config flow will have non-functional sensors, as mentioned in #19591. This change prevents the creation of sensors without data. --- homeassistant/components/luftdaten/config_flow.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/luftdaten/config_flow.py b/homeassistant/components/luftdaten/config_flow.py index b4ebc93da9c..d4baccd006f 100644 --- a/homeassistant/components/luftdaten/config_flow.py +++ b/homeassistant/components/luftdaten/config_flow.py @@ -4,7 +4,9 @@ from collections import OrderedDict import voluptuous as vol from homeassistant import config_entries -from homeassistant.const import CONF_SCAN_INTERVAL, CONF_SHOW_ON_MAP +from homeassistant.const import ( + CONF_MONITORED_CONDITIONS, CONF_SCAN_INTERVAL, + CONF_SENSORS, CONF_SHOW_ON_MAP) from homeassistant.core import callback from homeassistant.helpers import aiohttp_client import homeassistant.helpers.config_validation as cv @@ -77,6 +79,13 @@ class LuftDatenFlowHandler(config_entries.ConfigFlow): if not valid: return self._show_form({CONF_SENSOR_ID: 'invalid_sensor'}) + available_sensors = [x for x in luftdaten.values + if luftdaten.values[x] is not None] + + if available_sensors: + user_input.update({ + CONF_SENSORS: {CONF_MONITORED_CONDITIONS: available_sensors}}) + scan_interval = user_input.get( CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL) user_input.update({CONF_SCAN_INTERVAL: scan_interval.seconds})