Skip to content

Commit

Permalink
Merge pull request #227 from basbruss/226-interpolation-not-configura…
Browse files Browse the repository at this point in the history
…ble-due-to-missing-new_range

fix interpolation not configurable due to missing new range
  • Loading branch information
basbruss authored Jun 17, 2024
2 parents 37f5cc5 + f8ae014 commit cf870e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
14 changes: 10 additions & 4 deletions custom_components/adaptive_cover/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,16 +606,15 @@ async def async_step_update(self, user_input: dict[str, Any] | None = None):
CONF_MIN_ELEVATION: self.config.get(CONF_MIN_ELEVATION, None),
CONF_MAX_ELEVATION: self.config.get(CONF_MAX_ELEVATION, None),
CONF_TRANSPARENT_BLIND: self.config.get(CONF_TRANSPARENT_BLIND, False),
CONF_INTERP: self.config.get(CONF_INTERP),
CONF_INTERP_START: self.config.get(CONF_INTERP_START, None),
CONF_INTERP_END: self.config.get(CONF_INTERP_END, None),
CONF_INTERP_LIST: self.config.get(CONF_INTERP_LIST, []),
CONF_INTERP_LIST_NEW: self.config.get(CONF_INTERP_LIST_NEW, []),
CONF_INTERP: self.config.get(CONF_INTERP),
CONF_LUX_ENTITY: self.config.get(CONF_LUX_ENTITY),
CONF_LUX_THRESHOLD: self.config.get(CONF_LUX_THRESHOLD),
CONF_IRRADIANCE_ENTITY: self.config.get(CONF_IRRADIANCE_ENTITY),
CONF_IRRADIANCE_THRESHOLD: self.config.get(CONF_IRRADIANCE_THRESHOLD),

},
)

Expand Down Expand Up @@ -696,6 +695,10 @@ async def async_step_vertical(self, user_input: dict[str, Any] | None = None):
},
)
self.options.update(user_input)
if self.options.get(CONF_INTERP, False):
return await self.async_step_interp()
if self.options[CONF_ENABLE_BLIND_SPOT]:
return await self.async_step_blind_spot()
if self.options[CONF_CLIMATE_MODE]:
return await self.async_step_climate()
return await self._update_options()
Expand Down Expand Up @@ -791,8 +794,11 @@ async def async_step_interp(self, user_input: dict[str, Any] | None = None):
)
self.options.update(user_input)
return await self._update_options()
return self.add_suggested_values_to_schema(
INTERPOLATION_OPTIONS, user_input or self.options
return self.async_show_form(
step_id="interp",
data_schema=self.add_suggested_values_to_schema(
INTERPOLATION_OPTIONS, user_input or self.options
),
)

async def async_step_blind_spot(self, user_input: dict[str, Any] | None = None):
Expand Down
12 changes: 7 additions & 5 deletions custom_components/adaptive_cover/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf870e3

Please sign in to comment.