Fix unit of measurement
* Add version check in unit_of_measurement, to avoid error. * Remove not needed metric check in unit_of_measurement. * Add more value types to unit_of_measurement. * Fix unit prefix * Remove unused SCAN_INTERVAL variable.
This commit is contained in:
parent
6796219f37
commit
2e175b88bc
2 changed files with 25 additions and 14 deletions
|
@ -58,7 +58,6 @@ ATTR_CHILD_ID = 'child_id'
|
||||||
ATTR_PORT = 'port'
|
ATTR_PORT = 'port'
|
||||||
|
|
||||||
GATEWAYS = None
|
GATEWAYS = None
|
||||||
SCAN_INTERVAL = 30
|
|
||||||
|
|
||||||
DISCOVER_SENSORS = "mysensors.sensors"
|
DISCOVER_SENSORS = "mysensors.sensors"
|
||||||
DISCOVER_SWITCHES = "mysensors.switches"
|
DISCOVER_SWITCHES = "mysensors.switches"
|
||||||
|
|
|
@ -12,7 +12,7 @@ from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_BATTERY_LEVEL,
|
ATTR_BATTERY_LEVEL,
|
||||||
TEMP_CELCIUS, TEMP_FAHRENHEIT,
|
TEMP_CELCIUS,
|
||||||
STATE_ON, STATE_OFF)
|
STATE_ON, STATE_OFF)
|
||||||
|
|
||||||
import homeassistant.components.mysensors as mysensors
|
import homeassistant.components.mysensors as mysensors
|
||||||
|
@ -56,6 +56,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
gateway.const.SetReq.V_ARMED,
|
gateway.const.SetReq.V_ARMED,
|
||||||
gateway.const.SetReq.V_LIGHT,
|
gateway.const.SetReq.V_LIGHT,
|
||||||
gateway.const.SetReq.V_LOCK_STATUS,
|
gateway.const.SetReq.V_LOCK_STATUS,
|
||||||
|
gateway.const.SetReq.V_UNIT_PREFIX,
|
||||||
]
|
]
|
||||||
if float(gateway.version) >= 1.5:
|
if float(gateway.version) >= 1.5:
|
||||||
s_types.extend([
|
s_types.extend([
|
||||||
|
@ -129,25 +130,36 @@ class MySensorsSensor(Entity):
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Unit of measurement of this entity."""
|
"""Unit of measurement of this entity."""
|
||||||
# pylint:disable=too-many-return-statements
|
# pylint:disable=too-many-return-statements
|
||||||
|
prefix = ''
|
||||||
|
if float(self.gateway.version) >= 1.5 and \
|
||||||
|
self.gateway.const.SetReq.V_UNIT_PREFIX in self._values:
|
||||||
|
prefix = self._values[self.gateway.const.SetReq.V_UNIT_PREFIX]
|
||||||
if self.value_type == self.gateway.const.SetReq.V_TEMP:
|
if self.value_type == self.gateway.const.SetReq.V_TEMP:
|
||||||
return TEMP_CELCIUS if self.gateway.metric else TEMP_FAHRENHEIT
|
return TEMP_CELCIUS # HA will convert to degrees F if needed
|
||||||
elif self.value_type == self.gateway.const.SetReq.V_HUM or \
|
elif self.value_type == self.gateway.const.SetReq.V_HUM or \
|
||||||
self.value_type == self.gateway.const.SetReq.V_DIMMER or \
|
self.value_type == self.gateway.const.SetReq.V_DIMMER or \
|
||||||
|
float(self.gateway.version) >= 1.5 and \
|
||||||
self.value_type == self.gateway.const.SetReq.V_PERCENTAGE or \
|
self.value_type == self.gateway.const.SetReq.V_PERCENTAGE or \
|
||||||
self.value_type == self.gateway.const.SetReq.V_LIGHT_LEVEL:
|
self.value_type == self.gateway.const.SetReq.V_LIGHT_LEVEL:
|
||||||
return '%'
|
return '%'
|
||||||
elif self.value_type == self.gateway.const.SetReq.V_WATT:
|
elif self.value_type == self.gateway.const.SetReq.V_WEIGHT:
|
||||||
return 'W'
|
return '{}g'.format(prefix)
|
||||||
elif self.value_type == self.gateway.const.SetReq.V_KWH:
|
elif self.value_type == self.gateway.const.SetReq.V_DISTANCE:
|
||||||
return 'kWh'
|
return '{}m'.format(prefix)
|
||||||
elif self.value_type == self.gateway.const.SetReq.V_VOLTAGE:
|
|
||||||
return 'V'
|
|
||||||
elif self.value_type == self.gateway.const.SetReq.V_CURRENT:
|
|
||||||
return 'A'
|
|
||||||
elif self.value_type == self.gateway.const.SetReq.V_IMPEDANCE:
|
elif self.value_type == self.gateway.const.SetReq.V_IMPEDANCE:
|
||||||
return 'ohm'
|
return '{}ohm'.format(prefix)
|
||||||
elif self.gateway.const.SetReq.V_UNIT_PREFIX in self._values:
|
elif self.value_type == self.gateway.const.SetReq.V_WATT:
|
||||||
return self._values[self.gateway.const.SetReq.V_UNIT_PREFIX]
|
return '{}W'.format(prefix)
|
||||||
|
elif self.value_type == self.gateway.const.SetReq.V_KWH:
|
||||||
|
return '{}kWh'.format(prefix)
|
||||||
|
elif self.value_type == self.gateway.const.SetReq.V_FLOW:
|
||||||
|
return '{}m'.format(prefix)
|
||||||
|
elif self.value_type == self.gateway.const.SetReq.V_VOLUME:
|
||||||
|
return '{}m3'.format(prefix)
|
||||||
|
elif self.value_type == self.gateway.const.SetReq.V_VOLTAGE:
|
||||||
|
return '{}V'.format(prefix)
|
||||||
|
elif self.value_type == self.gateway.const.SetReq.V_CURRENT:
|
||||||
|
return '{}A'.format(prefix)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue