Skip to content

Commit

Permalink
Update sensor.py
Browse files Browse the repository at this point in the history
Correct rounding so money remains 2 decimal places
  • Loading branch information
hif2k1 authored Aug 17, 2022
1 parent 1e6b411 commit 01f62cf
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions custom_components/battery_sim/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ def device_info(self):

@property
def native_value(self):
"""Return the state of the sensor."""
return round(float(self._handle._sensors[self._sensor_type]),3)
"""Return the state of the sensor."""
if (self._sensor_type == ATTR_MONEY_SAVED):
return round(float(self._handle._sensors[self._sensor_type]),2)
else:
return round(float(self._handle._sensors[self._sensor_type]),3)

@property
def device_class(self):
Expand Down Expand Up @@ -203,7 +206,10 @@ def icon(self):
@property
def state(self):
"""Return the state of the sensor."""
return round(float(self._handle._sensors[self._sensor_type]),3)
if (self._sensor_type == ATTR_MONEY_SAVED):
return round(float(self._handle._sensors[self._sensor_type]),2)
else:
return round(float(self._handle._sensors[self._sensor_type]),3)

def update(self):
"""Not used"""
Expand Down

0 comments on commit 01f62cf

Please sign in to comment.