Skip to content

Commit

Permalink
Use two digits precision in senso
Browse files Browse the repository at this point in the history
  • Loading branch information
postlund authored and rospogrigio committed Sep 26, 2020
1 parent d22d081 commit 208b0ad
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions custom_components/localtuya/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
_LOGGER = logging.getLogger(__name__)

DEFAULT_SCALING = 1.0
DEFAULT_PRECISION = 2


def flow_schema(dps):
Expand Down Expand Up @@ -68,9 +69,6 @@ def __init__(
@property
def state(self):
"""Return sensor state."""
scale_factor = self._config.get(CONF_SCALING)
if scale_factor is not None:
return self._state * scale_factor
return self._state

@property
Expand All @@ -85,4 +83,8 @@ def unit_of_measurement(self):

def status_updated(self):
"""Device status was updated."""
self._state = self.dps(self._dps_id)
state = self.dps(self._dps_id)
scale_factor = self._config.get(CONF_SCALING)
if scale_factor is not None:
state = round(state * scale_factor, DEFAULT_PRECISION)
self._state = state

0 comments on commit 208b0ad

Please sign in to comment.