mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +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):
|
def update(self):
|
||||||
"""Update the state."""
|
"""Update the state."""
|
||||||
if self.vera_device.category == "Temperature Sensor":
|
if self.vera_device.category == "Temperature Sensor":
|
||||||
current_temp = self.vera_device.temperature
|
self.current_value = self.vera_device.temperature
|
||||||
|
|
||||||
vera_temp_units = (
|
vera_temp_units = (
|
||||||
self.vera_device.vera_controller.temperature_units)
|
self.vera_device.vera_controller.temperature_units)
|
||||||
|
|
||||||
@ -60,14 +61,6 @@ class VeraSensor(VeraDevice, Entity):
|
|||||||
else:
|
else:
|
||||||
self._temperature_units = TEMP_CELSIUS
|
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":
|
elif self.vera_device.category == "Light Sensor":
|
||||||
self.current_value = self.vera_device.light
|
self.current_value = self.vera_device.light
|
||||||
elif self.vera_device.category == "Humidity Sensor":
|
elif self.vera_device.category == "Humidity Sensor":
|
||||||
|
@ -147,14 +147,11 @@ def setup(hass, config):
|
|||||||
temperature = service.data[ATTR_TEMPERATURE]
|
temperature = service.data[ATTR_TEMPERATURE]
|
||||||
|
|
||||||
for thermostat in target_thermostats:
|
for thermostat in target_thermostats:
|
||||||
if thermostat.unit_of_measurement is not None:
|
converted_temperature = convert(
|
||||||
converted_temperature = convert(
|
temperature, hass.config.units.temperature_unit,
|
||||||
temperature, hass.config.units.temperature_unit,
|
thermostat.unit_of_measurement)
|
||||||
thermostat.unit_of_measurement)
|
|
||||||
else:
|
|
||||||
converted_temperature = temperature
|
|
||||||
thermostat.set_temperature(converted_temperature)
|
|
||||||
|
|
||||||
|
thermostat.set_temperature(converted_temperature)
|
||||||
thermostat.update_ha_state(True)
|
thermostat.update_ha_state(True)
|
||||||
|
|
||||||
hass.services.register(
|
hass.services.register(
|
||||||
@ -306,20 +303,12 @@ class ThermostatDevice(Entity):
|
|||||||
@property
|
@property
|
||||||
def min_temp(self):
|
def min_temp(self):
|
||||||
"""Return the minimum temperature."""
|
"""Return the minimum temperature."""
|
||||||
try:
|
return convert(7, TEMP_CELSIUS, self.unit_of_measurement)
|
||||||
unit = self.unit_of_measurement
|
|
||||||
return convert(7, TEMP_CELSIUS, unit)
|
|
||||||
except ValueError:
|
|
||||||
return STATE_UNKNOWN
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def max_temp(self):
|
def max_temp(self):
|
||||||
"""Return the maximum temperature."""
|
"""Return the maximum temperature."""
|
||||||
try:
|
return convert(35, TEMP_CELSIUS, self.unit_of_measurement)
|
||||||
unit = self.unit_of_measurement
|
|
||||||
return convert(35, TEMP_CELSIUS, unit)
|
|
||||||
except ValueError:
|
|
||||||
return STATE_UNKNOWN
|
|
||||||
|
|
||||||
def _convert_for_display(self, temp):
|
def _convert_for_display(self, temp):
|
||||||
"""Convert temperature into preferred units for display purposes."""
|
"""Convert temperature into preferred units for display purposes."""
|
||||||
|
@ -8,12 +8,10 @@ import logging
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
import homeassistant.util as util
|
|
||||||
from homeassistant.components import switch
|
from homeassistant.components import switch
|
||||||
from homeassistant.components.thermostat import (
|
from homeassistant.components.thermostat import (
|
||||||
STATE_HEAT, STATE_COOL, STATE_IDLE, ThermostatDevice)
|
STATE_HEAT, STATE_COOL, STATE_IDLE, ThermostatDevice)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT
|
||||||
ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
|
||||||
from homeassistant.helpers.event import track_state_change
|
from homeassistant.helpers.event import track_state_change
|
||||||
|
|
||||||
DEPENDENCIES = ['switch', 'sensor']
|
DEPENDENCIES = ['switch', 'sensor']
|
||||||
@ -157,24 +155,11 @@ class HeatControl(ThermostatDevice):
|
|||||||
"""Update thermostat with latest state from sensor."""
|
"""Update thermostat with latest state from sensor."""
|
||||||
unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||||
|
|
||||||
if unit not in (TEMP_CELSIUS, TEMP_FAHRENHEIT):
|
try:
|
||||||
self._cur_temp = None
|
self._cur_temp = self.hass.config.units.temperature(
|
||||||
self._unit = None
|
float(state.state), unit)
|
||||||
_LOGGER.error('Sensor has unsupported unit: %s (allowed: %s, %s)',
|
except ValueError as ex:
|
||||||
unit, TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
_LOGGER.error('Unable to update from sensor: %s', ex)
|
||||||
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
|
|
||||||
|
|
||||||
def _control_heating(self):
|
def _control_heating(self):
|
||||||
"""Check if we need to turn heating on or off."""
|
"""Check if we need to turn heating on or off."""
|
||||||
|
@ -202,9 +202,9 @@ class Entity(object):
|
|||||||
try:
|
try:
|
||||||
unit_of_measure = attr.get(ATTR_UNIT_OF_MEASUREMENT)
|
unit_of_measure = attr.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||||
if unit_of_measure in (TEMP_CELSIUS, TEMP_FAHRENHEIT):
|
if unit_of_measure in (TEMP_CELSIUS, TEMP_FAHRENHEIT):
|
||||||
state = \
|
units = self.hass.config.units
|
||||||
str(self.hass.config.units.temperature(float(state),
|
state = str(units.temperature(float(state), unit_of_measure))
|
||||||
unit_of_measure))
|
attr[ATTR_UNIT_OF_MEASUREMENT] = units.temperature_unit
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# Could not convert state to float
|
# Could not convert state to float
|
||||||
pass
|
pass
|
||||||
|
@ -91,8 +91,7 @@ class UnitSystem(object):
|
|||||||
"""Determine if this is the metric unit system."""
|
"""Determine if this is the metric unit system."""
|
||||||
return self.name == CONF_UNIT_SYSTEM_METRIC
|
return self.name == CONF_UNIT_SYSTEM_METRIC
|
||||||
|
|
||||||
def temperature(self: object, temperature: float, from_unit: str) -> (
|
def temperature(self: object, temperature: float, from_unit: str) -> float:
|
||||||
float, str):
|
|
||||||
"""Convert the given temperature to this unit system."""
|
"""Convert the given temperature to this unit system."""
|
||||||
if not isinstance(temperature, Number):
|
if not isinstance(temperature, Number):
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
|
@ -124,19 +124,29 @@ class TestThermostatHeatControl(unittest.TestCase):
|
|||||||
|
|
||||||
def test_sensor_bad_unit(self):
|
def test_sensor_bad_unit(self):
|
||||||
"""Test sensor that have bad unit."""
|
"""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._setup_sensor(22.0, unit='bad_unit')
|
||||||
self.hass.pool.block_till_done()
|
self.hass.pool.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
self.assertEqual(None, state.attributes.get('unit_of_measurement'))
|
self.assertEqual(unit, state.attributes.get('unit_of_measurement'))
|
||||||
self.assertEqual(None, state.attributes.get('current_temperature'))
|
self.assertEqual(temp, state.attributes.get('current_temperature'))
|
||||||
|
|
||||||
def test_sensor_bad_value(self):
|
def test_sensor_bad_value(self):
|
||||||
"""Test sensor that have None as state."""
|
"""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._setup_sensor(None)
|
||||||
self.hass.pool.block_till_done()
|
self.hass.pool.block_till_done()
|
||||||
|
|
||||||
state = self.hass.states.get(ENTITY)
|
state = self.hass.states.get(ENTITY)
|
||||||
self.assertEqual(None, state.attributes.get('unit_of_measurement'))
|
self.assertEqual(unit, state.attributes.get('unit_of_measurement'))
|
||||||
self.assertEqual(None, state.attributes.get('current_temperature'))
|
self.assertEqual(temp, state.attributes.get('current_temperature'))
|
||||||
|
|
||||||
def test_set_target_temp_heater_on(self):
|
def test_set_target_temp_heater_on(self):
|
||||||
"""Test if target temperature turn heater on."""
|
"""Test if target temperature turn heater on."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user