From 3d0a04958bfe6bba1345fad445e2f86bae5545b8 Mon Sep 17 00:00:00 2001 From: Tsvi Mostovicz Date: Mon, 11 Mar 2019 08:59:45 +0200 Subject: [PATCH] Use regular if statement Ternary statements can be tricky if you try to keep the value the same if not something --- homeassistant/components/input_datetime/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/input_datetime/__init__.py b/homeassistant/components/input_datetime/__init__.py index dc363846147..1fb2eeee1d7 100644 --- a/homeassistant/components/input_datetime/__init__.py +++ b/homeassistant/components/input_datetime/__init__.py @@ -20,6 +20,8 @@ CONF_HAS_DATE = 'has_date' CONF_HAS_TIME = 'has_time' CONF_INITIAL = 'initial' +DEFAULT_VALUE = '1970-01-01 00:00:00' + ATTR_DATE = 'date' ATTR_TIME = 'time' @@ -121,13 +123,16 @@ class InputDatetime(RestoreEntity): restore_val = old_state.state if not self.has_date: - restore_val = restore_val if not None else '00:00:00' + if not restore_val: + restore_val = DEFAULT_VALUE.split()[0] self._current_datetime = dt_util.parse_time(restore_val) elif not self.has_time: - restore_val = restore_val if not None else '1970-01-01' + if not restore_val: + restore_val = DEFAULT_VALUE.split()[1] self._current_datetime = dt_util.parse_date(restore_val) else: - restore_val = restore_val if not None else '1970-01-01 00:00:00' + if not restore_val: + restore_val = DEFAULT_VALUE self._current_datetime = dt_util.parse_datetime(restore_val) @property