From 7337cd44158b1b82828e2d7229e4abc6f3e8a2f9 Mon Sep 17 00:00:00 2001 From: Anko Hanse Date: Thu, 9 May 2024 13:24:43 +1200 Subject: [PATCH] Fix entity Number behavor for min and max limit --- custom_components/dabpumps/const.py | 2 +- custom_components/dabpumps/coordinator.py | 4 ++-- custom_components/dabpumps/entity_base.py | 15 ++++++++------- custom_components/dabpumps/manifest.json | 2 +- custom_components/dabpumps/number.py | 14 ++++++++------ 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/custom_components/dabpumps/const.py b/custom_components/dabpumps/const.py index 4fe60c4..4544514 100644 --- a/custom_components/dabpumps/const.py +++ b/custom_components/dabpumps/const.py @@ -14,7 +14,7 @@ # Base component constants DOMAIN = "dabpumps" NAME = "DAB Pumps" -VERSION="2024.05.1" +VERSION="2024.05.2" ISSUE_URL = "https://github.com/ankoh/dabpumps/issues" PLATFORMS: list[Platform] = [ diff --git a/custom_components/dabpumps/coordinator.py b/custom_components/dabpumps/coordinator.py index 8bcb89e..272dadd 100644 --- a/custom_components/dabpumps/coordinator.py +++ b/custom_components/dabpumps/coordinator.py @@ -742,8 +742,8 @@ async def _async_process_device_config_data(self, device, data): param_type = meta_param.get('type') or '' param_unit = meta_param.get('unit') param_weight = meta_param.get('weight') - param_min = meta_param.get('min') - param_max = meta_param.get('max') + param_min = meta_param.get('min') or meta_param.get('warn_low') + param_max = meta_param.get('max') or meta_param.get('warn_hi') param_family = meta_param.get('family') or '' param_group = meta_param.get('group') or '' diff --git a/custom_components/dabpumps/entity_base.py b/custom_components/dabpumps/entity_base.py index 914f324..97168c7 100644 --- a/custom_components/dabpumps/entity_base.py +++ b/custom_components/dabpumps/entity_base.py @@ -578,13 +578,14 @@ def get_number_step(self): candidates = [1000, 100, 10, 1] # find first candidate where min, max and diff are all dividable by (without remainder) - min = int(self._params.min) - max = int(self._params.max) - diff = max - min - - for c in candidates: - if (min % c == 0) and (max % c == 0) and (diff % c == 0): - return c + if self._params.min is not None and self._params.max is not None: + min = int(self._params.min) + max = int(self._params.max) + diff = max - min + + for c in candidates: + if (min % c == 0) and (max % c == 0) and (diff % c == 0): + return c return None diff --git a/custom_components/dabpumps/manifest.json b/custom_components/dabpumps/manifest.json index ed3b776..1e36b2b 100644 --- a/custom_components/dabpumps/manifest.json +++ b/custom_components/dabpumps/manifest.json @@ -10,5 +10,5 @@ "issue_tracker": "https://github.com/ankohanse/hass-dab-pumps/issues", "loggers": ["custom_components.dabpumps"], "requirements": [], - "version": "2024.05.1" + "version": "2024.05.2" } \ No newline at end of file diff --git a/custom_components/dabpumps/number.py b/custom_components/dabpumps/number.py index def3e24..11564df 100644 --- a/custom_components/dabpumps/number.py +++ b/custom_components/dabpumps/number.py @@ -125,8 +125,8 @@ def _update_attributes(self, status, is_create): if self._params.weight and self._params.weight != 1 and self._params.weight != 0: # Convert to float attr_precision = int(math.floor(math.log10(1.0 / self._params.weight))) - attr_min = round(float(self._params.min) * self._params.weight, attr_precision) if self._params.min is not None else None - attr_max = round(float(self._params.max) * self._params.weight, attr_precision) if self._params.max is not None else None + attr_min = float(self._params.min) if self._params.min is not None else None + attr_max = float(self._params.max) if self._params.max is not None else None attr_val = round(float(status.val) * self._params.weight, attr_precision) if status.val is not None else None attr_step = self._params.weight else: @@ -150,8 +150,10 @@ def _update_attributes(self, status, is_create): self._attr_mode = NumberMode.BOX self._attr_device_class = self.get_number_device_class() self._attr_entity_category = self.get_entity_category() - self._attr_native_min_value = attr_min - self._attr_native_max_value = attr_max + if attr_min: + self._attr_native_min_value = attr_min + if attr_max: + self._attr_native_max_value = attr_max self._attr_native_step = attr_step self._attr_device_info = DeviceInfo( @@ -179,8 +181,8 @@ async def async_set_native_value(self, value: float) -> None: """Change the selected option""" if self._params.weight and self._params.weight != 1 and self._params.weight != 0: - # Convert to float - data_val = float(round(value / self._params.weight)) + # Convert from float to int + data_val = int(round(value / self._params.weight)) else: # Convert to int data_val = int(value)