Skip to content

Commit cf870e3

Browse files
authored
Merge pull request #227 from basbruss/226-interpolation-not-configurable-due-to-missing-new_range
fix interpolation not configurable due to missing new range
2 parents 37f5cc5 + f8ae014 commit cf870e3

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

custom_components/adaptive_cover/config_flow.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,16 +606,15 @@ async def async_step_update(self, user_input: dict[str, Any] | None = None):
606606
CONF_MIN_ELEVATION: self.config.get(CONF_MIN_ELEVATION, None),
607607
CONF_MAX_ELEVATION: self.config.get(CONF_MAX_ELEVATION, None),
608608
CONF_TRANSPARENT_BLIND: self.config.get(CONF_TRANSPARENT_BLIND, False),
609+
CONF_INTERP: self.config.get(CONF_INTERP),
609610
CONF_INTERP_START: self.config.get(CONF_INTERP_START, None),
610611
CONF_INTERP_END: self.config.get(CONF_INTERP_END, None),
611612
CONF_INTERP_LIST: self.config.get(CONF_INTERP_LIST, []),
612613
CONF_INTERP_LIST_NEW: self.config.get(CONF_INTERP_LIST_NEW, []),
613-
CONF_INTERP: self.config.get(CONF_INTERP),
614614
CONF_LUX_ENTITY: self.config.get(CONF_LUX_ENTITY),
615615
CONF_LUX_THRESHOLD: self.config.get(CONF_LUX_THRESHOLD),
616616
CONF_IRRADIANCE_ENTITY: self.config.get(CONF_IRRADIANCE_ENTITY),
617617
CONF_IRRADIANCE_THRESHOLD: self.config.get(CONF_IRRADIANCE_THRESHOLD),
618-
619618
},
620619
)
621620

@@ -696,6 +695,10 @@ async def async_step_vertical(self, user_input: dict[str, Any] | None = None):
696695
},
697696
)
698697
self.options.update(user_input)
698+
if self.options.get(CONF_INTERP, False):
699+
return await self.async_step_interp()
700+
if self.options[CONF_ENABLE_BLIND_SPOT]:
701+
return await self.async_step_blind_spot()
699702
if self.options[CONF_CLIMATE_MODE]:
700703
return await self.async_step_climate()
701704
return await self._update_options()
@@ -791,8 +794,11 @@ async def async_step_interp(self, user_input: dict[str, Any] | None = None):
791794
)
792795
self.options.update(user_input)
793796
return await self._update_options()
794-
return self.add_suggested_values_to_schema(
795-
INTERPOLATION_OPTIONS, user_input or self.options
797+
return self.async_show_form(
798+
step_id="interp",
799+
data_schema=self.add_suggested_values_to_schema(
800+
INTERPOLATION_OPTIONS, user_input or self.options
801+
),
796802
)
797803

798804
async def async_step_blind_spot(self, user_input: dict[str, Any] | None = None):

custom_components/adaptive_cover/coordinator.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,16 +607,18 @@ def state(self) -> int:
607607
def interpolate_states(self, state):
608608
"""Interpolate states."""
609609
normal_range = [0, 100]
610+
new_range = []
610611
if self.start_value and self.end_value:
611612
new_range = [self.start_value, self.end_value]
612613
if self.normal_list and self.new_list:
613614
normal_range = list(map(int, self.normal_list))
614615
new_range = list(map(int, self.new_list))
615-
state = np.interp(state, normal_range, new_range)
616-
if state == new_range[0]:
617-
state = 0
618-
if state == new_range[-1]:
619-
state = 100
616+
if new_range:
617+
state = np.interp(state, normal_range, new_range)
618+
if state == new_range[0]:
619+
state = 0
620+
if state == new_range[-1]:
621+
state = 100
620622
return state
621623

622624
@property

0 commit comments

Comments
 (0)