Skip to content

Commit

Permalink
Fix issue with sensor unit. Also fix some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ankohanse committed Mar 2, 2024
1 parent aace0ba commit 4510425
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion custom_components/dabpumps/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Base component constants
DOMAIN = "dabpumps"
NAME = "DAB Pumps"
VERSION="2024.03.2"
VERSION="2024.03.3"
ISSUE_URL = "https://github.com/ankoh/dabpumps/issues"

HUB = "Hub"
Expand Down
16 changes: 14 additions & 2 deletions custom_components/dabpumps/entity_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def _convert_to_unit(self):
case 'ms': return 'ms'
case 's': return 's'
case 'secondi': return 's'
case 'min': return 'min'
case 'h': return 'h'
case 'rpm': return 'rpm'
case 'B': return 'B'
Expand Down Expand Up @@ -392,15 +393,26 @@ def get_sensor_state_class(self):
# Return StateClass=None for Enum or Label
if self._params.type != 'measure':
return None

# Return StateClass=None for params that are a setting, unlikely to change often
if self._params.change:
return None

# Return StateClass=None for diagnostics kind of parameters
groups_none = ['Modbus', 'Extra Comfort']
if self._params.group in groups_none:
return None

# Return StateClass=None for some specific fields
keys_none = [
'Last_Period_Flow_Counter',
'Last_Period_flow_Flow_Counter_Gall',
'Last_Period_Energy_Counter',
'PartialEnergy',
'TotalEnergy',
]
if self._params.key in keys_none:
return None

keys_t = []
keys_ti = [
Expand Down
2 changes: 1 addition & 1 deletion custom_components/dabpumps/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"issue_tracker": "https://github.com/ankohanse/hass-dab-pumps/issues",
"loggers": ["custom_components.dabpumps"],
"requirements": [],
"version": "2024.03.2"
"version": "2024.03.3"
}
6 changes: 5 additions & 1 deletion custom_components/dabpumps/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,18 @@ def _update_attributes(self, status, is_create):
# Convert to float
attr_precision = int(math.floor(math.log10(1.0 / self._params.weight)))
attr_val = round(float(status.val) * self._params.weight, attr_precision)
attr_unit = self.get_unit()
else:
# Convert to int
attr_precision = 0
attr_val = int(status.val)
attr_unit = self.get_unit()

case 'enum':
# Lookup the dict string for the value and otherwise return the value itself
attr_precision = None
attr_val = self._get_string(self._params.values.get(status.val, status.val))
attr_unit = None

case 'label' | _:
if self._params.type != 'label':
Expand All @@ -142,6 +145,7 @@ def _update_attributes(self, status, is_create):
# Convert to string
attr_precision = None
attr_val = self._get_string(str(status.val))
attr_unit = None

# Process any changes
changed = False
Expand Down Expand Up @@ -173,7 +177,7 @@ def _update_attributes(self, status, is_create):
# update value if it has changed
if is_create or self._attr_native_value != attr_val:
self._attr_native_value = attr_val
self._attr_native_unit_of_measurement = self.get_unit()
self._attr_native_unit_of_measurement = attr_unit
self._attr_suggested_display_precision = attr_precision

self._attr_icon = self.get_icon()
Expand Down

0 comments on commit 4510425

Please sign in to comment.