From dd3e82185797f0b3e461b7fce01f88bb289161e1 Mon Sep 17 00:00:00 2001 From: Andrej Komelj Date: Thu, 15 Oct 2020 15:14:07 +0200 Subject: [PATCH] fix mqtt config check in OnlyWith configuration helper (#1304) * fix config check in OnlyWith configuration helper OnlyWith configuration helper check now verifies whether a component is configured in any of the packages not only in raw configuration * fix C0301(line-too-long) pylint in imports * fix flake8 (E127) over-indented line --- esphome/config_validation.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/esphome/config_validation.py b/esphome/config_validation.py index 1e54c04fe5..51f908c113 100644 --- a/esphome/config_validation.py +++ b/esphome/config_validation.py @@ -11,10 +11,11 @@ from string import ascii_letters, digits import voluptuous as vol from esphome import core -from esphome.const import CONF_AVAILABILITY, CONF_COMMAND_TOPIC, CONF_DISCOVERY, CONF_ID, \ - CONF_INTERNAL, CONF_NAME, CONF_PAYLOAD_AVAILABLE, CONF_PAYLOAD_NOT_AVAILABLE, \ - CONF_RETAIN, CONF_SETUP_PRIORITY, CONF_STATE_TOPIC, CONF_TOPIC, \ - CONF_HOUR, CONF_MINUTE, CONF_SECOND, CONF_VALUE, CONF_UPDATE_INTERVAL, CONF_TYPE_ID, CONF_TYPE +from esphome.const import CONF_AVAILABILITY, CONF_COMMAND_TOPIC, \ + CONF_DISCOVERY, CONF_ID, CONF_INTERNAL, CONF_NAME, CONF_PAYLOAD_AVAILABLE, \ + CONF_PAYLOAD_NOT_AVAILABLE, CONF_RETAIN, CONF_SETUP_PRIORITY, CONF_STATE_TOPIC, CONF_TOPIC, \ + CONF_HOUR, CONF_MINUTE, CONF_SECOND, CONF_VALUE, CONF_UPDATE_INTERVAL, CONF_TYPE_ID, \ + CONF_TYPE, CONF_PACKAGES from esphome.core import CORE, HexInt, IPAddress, Lambda, TimePeriod, TimePeriodMicroseconds, \ TimePeriodMilliseconds, TimePeriodSeconds, TimePeriodMinutes from esphome.helpers import list_starts_with, add_class_to_obj @@ -1167,9 +1168,12 @@ class OnlyWith(Optional): @property def default(self): # pylint: disable=unsupported-membership-test - if self._component not in CORE.raw_config: - return vol.UNDEFINED - return self._default + if (self._component in CORE.raw_config or + (CONF_PACKAGES in CORE.raw_config and + self._component in + {list(x.keys())[0] for x in CORE.raw_config[CONF_PACKAGES].values()})): + return self._default + return vol.UNDEFINED @default.setter def default(self, value):