Skip to content

Commit

Permalink
Merge pull request #132 from Snuffy2/Fix-add_sensor_input-Error
Browse files Browse the repository at this point in the history
Fix add_sensor_input options Error
  • Loading branch information
enkama authored Aug 21, 2024
2 parents f133117 + db4b634 commit d2e9195
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions custom_components/variable/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ async def async_step_sensor_options_page_2(self, user_input=None):
if (
user_input.get(CONF_VALUE) is not None
and isinstance(user_input.get(CONF_VALUE), str)
and self.add_sensor_input.get(CONF_VALUE_TYPE) == "datetime"
and self.sensor_options_page_1.get(CONF_VALUE_TYPE) == "datetime"
):
if (
user_input.get(CONF_TZOFFSET) is not None
Expand Down Expand Up @@ -1236,6 +1236,11 @@ async def async_step_sensor_options_page_2(self, user_input=None):
)

def check_value_default(self, new_device_class):
_LOGGER.debug(
f"[check_value_default] value: {self.config_entry.data.get(CONF_VALUE)}, "
f"current device_class: {self.config_entry.data.get(CONF_DEVICE_CLASS)} ({type(self.config_entry.data.get(CONF_DEVICE_CLASS))}), "
f"new_device_class: {new_device_class} ({type(new_device_class)})"
)
val_default_value = None
if self.config_entry.data.get(CONF_VALUE) is None or (
isinstance(self.config_entry.data.get(CONF_VALUE), str)
Expand All @@ -1258,10 +1263,13 @@ def build_sensor_options_page_2(self):
SENSOR_UNITS_SELECT_LIST.append(
selector.SelectOptionDict(label="None", value="None")
)

val_default, val_default_value = self.check_value_default(
self.sensor_options_page_1.get(CONF_DEVICE_CLASS)
_LOGGER.debug(
f"[build_sensor_options_page_2] device_class: {self.sensor_options_page_1.get(CONF_DEVICE_CLASS)} ({type(self.sensor_options_page_1.get(CONF_DEVICE_CLASS))})"
)
device_class = self.sensor_options_page_1.get(CONF_DEVICE_CLASS)
if isinstance(device_class, str) and device_class.lower() == "none":
device_class = None
val_default, val_default_value = self.check_value_default(device_class)

SENSOR_OPTIONS_PAGE_2_SCHEMA = vol.Schema({})
if (
Expand Down

0 comments on commit d2e9195

Please sign in to comment.