From 52131a3335c644c330251b0da6f49f5650d006a0 Mon Sep 17 00:00:00 2001 From: MartinHjelmare Date: Sat, 20 Feb 2016 02:11:15 +0100 Subject: [PATCH] Fix temperature unit * Specify temperature unit according to gateway setting, to avoid converting to Fahrenheit when already Fahrenheit. * Fix docstrings in wrapper class. --- homeassistant/components/mysensors.py | 3 +- homeassistant/components/sensor/mysensors.py | 37 ++++++++++---------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/mysensors.py b/homeassistant/components/mysensors.py index 53987fa1435..a05435b2e8c 100644 --- a/homeassistant/components/mysensors.py +++ b/homeassistant/components/mysensors.py @@ -158,7 +158,7 @@ def pf_callback_factory(map_sv_types, devices, add_devices, entity_class): class GatewayWrapper(object): - """Gateway wrapper class, by subclassing serial gateway.""" + """Gateway wrapper class.""" def __init__(self, gateway, version, optimistic): """Setup class attributes on instantiation. @@ -173,6 +173,7 @@ class GatewayWrapper(object): version (str): Version of mysensors API. platform_callbacks (list): Callback functions, one per platform. const (module): Mysensors API constants. + optimistic (bool): Send values to actuators without feedback state. __initialised (bool): True if GatewayWrapper is initialised. """ self._wrapped_gateway = gateway diff --git a/homeassistant/components/sensor/mysensors.py b/homeassistant/components/sensor/mysensors.py index d33be7f2903..7d70a532164 100644 --- a/homeassistant/components/sensor/mysensors.py +++ b/homeassistant/components/sensor/mysensors.py @@ -8,7 +8,7 @@ import logging import homeassistant.components.mysensors as mysensors from homeassistant.const import ( - ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON, TEMP_CELCIUS) + ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON, TEMP_CELCIUS, TEMP_FAHRENHEIT) from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) @@ -129,27 +129,28 @@ class MySensorsSensor(Entity): @property def unit_of_measurement(self): """Unit of measurement of this entity.""" - # HA will convert to degrees F if needed + set_req = self.gateway.const.SetReq unit_map = { - self.gateway.const.SetReq.V_TEMP: TEMP_CELCIUS, - self.gateway.const.SetReq.V_HUM: '%', - self.gateway.const.SetReq.V_DIMMER: '%', - self.gateway.const.SetReq.V_LIGHT_LEVEL: '%', - self.gateway.const.SetReq.V_WEIGHT: 'kg', - self.gateway.const.SetReq.V_DISTANCE: 'm', - self.gateway.const.SetReq.V_IMPEDANCE: 'ohm', - self.gateway.const.SetReq.V_WATT: 'W', - self.gateway.const.SetReq.V_KWH: 'kWh', - self.gateway.const.SetReq.V_FLOW: 'm', - self.gateway.const.SetReq.V_VOLUME: 'm3', - self.gateway.const.SetReq.V_VOLTAGE: 'V', - self.gateway.const.SetReq.V_CURRENT: 'A', + set_req.V_TEMP: (TEMP_CELCIUS + if self.gateway.metric else TEMP_FAHRENHEIT), + set_req.V_HUM: '%', + set_req.V_DIMMER: '%', + set_req.V_LIGHT_LEVEL: '%', + set_req.V_WEIGHT: 'kg', + set_req.V_DISTANCE: 'm', + set_req.V_IMPEDANCE: 'ohm', + set_req.V_WATT: 'W', + set_req.V_KWH: 'kWh', + set_req.V_FLOW: 'm', + set_req.V_VOLUME: 'm3', + set_req.V_VOLTAGE: 'V', + set_req.V_CURRENT: 'A', } if float(self.gateway.version) >= 1.5: - if self.gateway.const.SetReq.V_UNIT_PREFIX in self._values: + if set_req.V_UNIT_PREFIX in self._values: return self._values[ - self.gateway.const.SetReq.V_UNIT_PREFIX] - unit_map.update({self.gateway.const.SetReq.V_PERCENTAGE: '%'}) + set_req.V_UNIT_PREFIX] + unit_map.update({set_req.V_PERCENTAGE: '%'}) return unit_map.get(self.value_type) @property