diff --git a/homeassistant/components/frontend/www_static/home-assistant-polymer b/homeassistant/components/frontend/www_static/home-assistant-polymer index cbafbda5fdd..a343d3d098e 160000 --- a/homeassistant/components/frontend/www_static/home-assistant-polymer +++ b/homeassistant/components/frontend/www_static/home-assistant-polymer @@ -1 +1 @@ -Subproject commit cbafbda5fdd2216ab4b6ebd962cbd1164fa8abec +Subproject commit a343d3d098e78976fc66f8ed66ce0ae5d7bc3861 diff --git a/homeassistant/components/sensor/vera.py b/homeassistant/components/sensor/vera.py index d7b642fb2fc..927c1863cce 100644 --- a/homeassistant/components/sensor/vera.py +++ b/homeassistant/components/sensor/vera.py @@ -51,7 +51,8 @@ class VeraSensor(VeraDevice, Entity): def update(self): """Update the state.""" if self.vera_device.category == "Temperature Sensor": - current_temp = self.vera_device.temperature + self.current_value = self.vera_device.temperature + vera_temp_units = ( self.vera_device.vera_controller.temperature_units) @@ -60,14 +61,6 @@ class VeraSensor(VeraDevice, Entity): else: self._temperature_units = TEMP_CELSIUS - if self.hass: - temp = self.hass.config.units.temperature( - current_temp, - self._temperature_units) - - current_temp = temp - - self.current_value = current_temp elif self.vera_device.category == "Light Sensor": self.current_value = self.vera_device.light elif self.vera_device.category == "Humidity Sensor": diff --git a/homeassistant/components/thermostat/__init__.py b/homeassistant/components/thermostat/__init__.py index b8a3b113671..09a18b91402 100644 --- a/homeassistant/components/thermostat/__init__.py +++ b/homeassistant/components/thermostat/__init__.py @@ -147,14 +147,11 @@ def setup(hass, config): temperature = service.data[ATTR_TEMPERATURE] for thermostat in target_thermostats: - if thermostat.unit_of_measurement is not None: - converted_temperature = convert( - temperature, hass.config.units.temperature_unit, - thermostat.unit_of_measurement) - else: - converted_temperature = temperature - thermostat.set_temperature(converted_temperature) + converted_temperature = convert( + temperature, hass.config.units.temperature_unit, + thermostat.unit_of_measurement) + thermostat.set_temperature(converted_temperature) thermostat.update_ha_state(True) hass.services.register( @@ -306,20 +303,12 @@ class ThermostatDevice(Entity): @property def min_temp(self): """Return the minimum temperature.""" - try: - unit = self.unit_of_measurement - return convert(7, TEMP_CELSIUS, unit) - except ValueError: - return STATE_UNKNOWN + return convert(7, TEMP_CELSIUS, self.unit_of_measurement) @property def max_temp(self): """Return the maximum temperature.""" - try: - unit = self.unit_of_measurement - return convert(35, TEMP_CELSIUS, unit) - except ValueError: - return STATE_UNKNOWN + return convert(35, TEMP_CELSIUS, self.unit_of_measurement) def _convert_for_display(self, temp): """Convert temperature into preferred units for display purposes.""" diff --git a/homeassistant/components/thermostat/heat_control.py b/homeassistant/components/thermostat/heat_control.py index 0f2dbce6040..9f70c90ced1 100644 --- a/homeassistant/components/thermostat/heat_control.py +++ b/homeassistant/components/thermostat/heat_control.py @@ -8,12 +8,10 @@ import logging import voluptuous as vol import homeassistant.helpers.config_validation as cv -import homeassistant.util as util from homeassistant.components import switch from homeassistant.components.thermostat import ( STATE_HEAT, STATE_COOL, STATE_IDLE, ThermostatDevice) -from homeassistant.const import ( - ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS, TEMP_FAHRENHEIT) +from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT from homeassistant.helpers.event import track_state_change DEPENDENCIES = ['switch', 'sensor'] @@ -157,24 +155,11 @@ class HeatControl(ThermostatDevice): """Update thermostat with latest state from sensor.""" unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) - if unit not in (TEMP_CELSIUS, TEMP_FAHRENHEIT): - self._cur_temp = None - self._unit = None - _LOGGER.error('Sensor has unsupported unit: %s (allowed: %s, %s)', - unit, TEMP_CELSIUS, TEMP_FAHRENHEIT) - return - - temp = util.convert(state.state, float) - - if temp is None: - self._cur_temp = None - self._unit = None - _LOGGER.error('Unable to parse sensor temperature: %s', - state.state) - return - - self._cur_temp = temp - self._unit = unit + try: + self._cur_temp = self.hass.config.units.temperature( + float(state.state), unit) + except ValueError as ex: + _LOGGER.error('Unable to update from sensor: %s', ex) def _control_heating(self): """Check if we need to turn heating on or off.""" diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 61f1c53f2a2..4dac7f9f6d0 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -202,9 +202,9 @@ class Entity(object): try: unit_of_measure = attr.get(ATTR_UNIT_OF_MEASUREMENT) if unit_of_measure in (TEMP_CELSIUS, TEMP_FAHRENHEIT): - state = \ - str(self.hass.config.units.temperature(float(state), - unit_of_measure)) + units = self.hass.config.units + state = str(units.temperature(float(state), unit_of_measure)) + attr[ATTR_UNIT_OF_MEASUREMENT] = units.temperature_unit except ValueError: # Could not convert state to float pass diff --git a/homeassistant/helpers/unit_system.py b/homeassistant/helpers/unit_system.py index e5d1481d979..a83a2b9a2ba 100644 --- a/homeassistant/helpers/unit_system.py +++ b/homeassistant/helpers/unit_system.py @@ -91,8 +91,7 @@ class UnitSystem(object): """Determine if this is the metric unit system.""" return self.name == CONF_UNIT_SYSTEM_METRIC - def temperature(self: object, temperature: float, from_unit: str) -> ( - float, str): + def temperature(self: object, temperature: float, from_unit: str) -> float: """Convert the given temperature to this unit system.""" if not isinstance(temperature, Number): raise TypeError( diff --git a/tests/components/thermostat/test_heat_control.py b/tests/components/thermostat/test_heat_control.py index f7f786adbbb..7c14d2b1490 100644 --- a/tests/components/thermostat/test_heat_control.py +++ b/tests/components/thermostat/test_heat_control.py @@ -124,19 +124,29 @@ class TestThermostatHeatControl(unittest.TestCase): def test_sensor_bad_unit(self): """Test sensor that have bad unit.""" + state = self.hass.states.get(ENTITY) + temp = state.attributes.get('current_temperature') + unit = state.attributes.get('unit_of_measurement') + self._setup_sensor(22.0, unit='bad_unit') self.hass.pool.block_till_done() + state = self.hass.states.get(ENTITY) - self.assertEqual(None, state.attributes.get('unit_of_measurement')) - self.assertEqual(None, state.attributes.get('current_temperature')) + self.assertEqual(unit, state.attributes.get('unit_of_measurement')) + self.assertEqual(temp, state.attributes.get('current_temperature')) def test_sensor_bad_value(self): """Test sensor that have None as state.""" + state = self.hass.states.get(ENTITY) + temp = state.attributes.get('current_temperature') + unit = state.attributes.get('unit_of_measurement') + self._setup_sensor(None) self.hass.pool.block_till_done() + state = self.hass.states.get(ENTITY) - self.assertEqual(None, state.attributes.get('unit_of_measurement')) - self.assertEqual(None, state.attributes.get('current_temperature')) + self.assertEqual(unit, state.attributes.get('unit_of_measurement')) + self.assertEqual(temp, state.attributes.get('current_temperature')) def test_set_target_temp_heater_on(self): """Test if target temperature turn heater on."""