Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix add_sensor_input options Error #132

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading