mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
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:
parent
8f690ff077
commit
0a7db98b0e
@ -20,6 +20,12 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
STATE_ON = 'on'
|
STATE_ON = 'on'
|
||||||
STATE_OFF = 'off'
|
STATE_OFF = 'off'
|
||||||
|
DIGITS = {
|
||||||
|
'volts': 1,
|
||||||
|
'amps': 1,
|
||||||
|
'active_power': 0,
|
||||||
|
'temperature': 1,
|
||||||
|
}
|
||||||
SENSOR_MODELS = [
|
SENSOR_MODELS = [
|
||||||
'Ubiquiti mFi-THS',
|
'Ubiquiti mFi-THS',
|
||||||
'Ubiquiti mFi-CS',
|
'Ubiquiti mFi-CS',
|
||||||
@ -76,7 +82,8 @@ class MfiSensor(Entity):
|
|||||||
if self._port.model == 'Input Digital':
|
if self._port.model == 'Input Digital':
|
||||||
return self._port.value > 0 and STATE_ON or STATE_OFF
|
return self._port.value > 0 and STATE_ON or STATE_OFF
|
||||||
else:
|
else:
|
||||||
return self._port.value
|
digits = DIGITS.get(self._port.tag, 0)
|
||||||
|
return round(self._port.value, digits)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
|
@ -98,6 +98,6 @@ class MfiSwitch(SwitchDevice):
|
|||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
attr = {}
|
attr = {}
|
||||||
attr['volts'] = self._port.data.get('v_rms', 0)
|
attr['volts'] = round(self._port.data.get('v_rms', 0), 1)
|
||||||
attr['amps'] = self._port.data.get('i_rms', 0)
|
attr['amps'] = round(self._port.data.get('i_rms', 0), 1)
|
||||||
return attr
|
return attr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user