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.pull/1167/head
parent
8f690ff077
commit
0a7db98b0e
|
@ -20,6 +20,12 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
STATE_ON = 'on'
|
||||
STATE_OFF = 'off'
|
||||
DIGITS = {
|
||||
'volts': 1,
|
||||
'amps': 1,
|
||||
'active_power': 0,
|
||||
'temperature': 1,
|
||||
}
|
||||
SENSOR_MODELS = [
|
||||
'Ubiquiti mFi-THS',
|
||||
'Ubiquiti mFi-CS',
|
||||
|
@ -76,7 +82,8 @@ class MfiSensor(Entity):
|
|||
if self._port.model == 'Input Digital':
|
||||
return self._port.value > 0 and STATE_ON or STATE_OFF
|
||||
else:
|
||||
return self._port.value
|
||||
digits = DIGITS.get(self._port.tag, 0)
|
||||
return round(self._port.value, digits)
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue