mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Address last comments
This commit is contained in:
parent
26526ca57a
commit
231656916c
@ -1 +1 @@
|
||||
Subproject commit cbafbda5fdd2216ab4b6ebd962cbd1164fa8abec
|
||||
Subproject commit a343d3d098e78976fc66f8ed66ce0ae5d7bc3861
|
@ -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":
|
||||
|
@ -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."""
|
||||
|
@ -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."""
|
||||
|
@ -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
|
||||
|
@ -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(
|
||||
|
@ -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."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user