Round mFi sensor values to reasonable levels of precision

Most of the mFi sensors are able to reasonably provide accurate
readings to a tenth of a unit or so. This patch rounds them for
better display in the UI. Normally, I would expect this to be a view
action instead of altering the actual data emitted, but since these
values are reasonable for sensor precision, we're not really losing
anything. I followed the model from the openweathermap component, which
rounds for readability in the backend.
This commit is contained in:
Dan Smith committed 2016-02-07 20:51:00 +00:00
1 parent 8f690ff077
commit 0a7db98b0e
2 files changed
+10 -3

No files matched your search

+2 -2
View File
@@ -98,6 +98,6 @@ class MfiSwitch(SwitchDevice):
@property
def device_state_attributes(self):
attr = {}
attr['volts'] = self._port.data.get('v_rms', 0)
attr['amps'] = self._port.data.get('i_rms', 0)
attr['volts'] = round(self._port.data.get('v_rms', 0), 1)
attr['amps'] = round(self._port.data.get('i_rms', 0), 1)
return attr