From f8ae0145f51592f7802bb9fda73e4687aaa068a3 Mon Sep 17 00:00:00 2001 From: basbruss <68892092+basbruss@users.noreply.github.com> Date: Mon, 17 Jun 2024 16:02:01 +0200 Subject: [PATCH] Fix local variable --- custom_components/adaptive_cover/coordinator.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/custom_components/adaptive_cover/coordinator.py b/custom_components/adaptive_cover/coordinator.py index a430938..6a70d24 100644 --- a/custom_components/adaptive_cover/coordinator.py +++ b/custom_components/adaptive_cover/coordinator.py @@ -607,16 +607,18 @@ def state(self) -> int: def interpolate_states(self, state): """Interpolate states.""" normal_range = [0, 100] + new_range = [] if self.start_value and self.end_value: new_range = [self.start_value, self.end_value] if self.normal_list and self.new_list: normal_range = list(map(int, self.normal_list)) new_range = list(map(int, self.new_list)) - state = np.interp(state, normal_range, new_range) - if state == new_range[0]: - state = 0 - if state == new_range[-1]: - state = 100 + if new_range: + state = np.interp(state, normal_range, new_range) + if state == new_range[0]: + state = 0 + if state == new_range[-1]: + state = 100 return state @property