mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Remove dead code in modbus sensor and 100% test coverage (#49634)
This commit is contained in:
parent
0862212942
commit
914451d99c
@ -306,22 +306,16 @@ class ModbusRegisterSensor(RestoreEntity, SensorEntity):
|
||||
v_result.append(f"{float(v_temp):.{self._precision}f}")
|
||||
self._value = ",".join(map(str, v_result))
|
||||
else:
|
||||
val = val[0]
|
||||
|
||||
# Apply scale and precision to floats and ints
|
||||
if isinstance(val, (float, int)):
|
||||
val = self._scale * val + self._offset
|
||||
val = self._scale * val[0] + self._offset
|
||||
|
||||
# We could convert int to float, and the code would still work; however
|
||||
# we lose some precision, and unit tests will fail. Therefore, we do
|
||||
# the conversion only when it's absolutely necessary.
|
||||
if isinstance(val, int) and self._precision == 0:
|
||||
self._value = str(val)
|
||||
else:
|
||||
self._value = f"{float(val):.{self._precision}f}"
|
||||
else:
|
||||
# Don't process remaining datatypes (bytes and booleans)
|
||||
# We could convert int to float, and the code would still work; however
|
||||
# we lose some precision, and unit tests will fail. Therefore, we do
|
||||
# the conversion only when it's absolutely necessary.
|
||||
if isinstance(val, int) and self._precision == 0:
|
||||
self._value = str(val)
|
||||
else:
|
||||
self._value = f"{float(val):.{self._precision}f}"
|
||||
|
||||
self._available = True
|
||||
self.schedule_update_ha_state()
|
||||
|
Loading…
x
Reference in New Issue
Block a user