Merge pull request #2731 from home-assistant/teagan-unit-system

Teagan unit system
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2016-08-04 22:53:44 -07:00
commit d1107a9cf3
40 files changed
+604 -294

No files matched your search

+11 -10
View File
@@ -6,13 +6,14 @@ https://home-assistant.io/components/hvac/
"""
import logging
import os
from numbers import Number
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.config import load_yaml_config_file
import homeassistant.util as util
from homeassistant.util.temperature import convert as convert_temperature
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.temperature import convert
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
from homeassistant.const import (
ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_ON, STATE_OFF, STATE_UNKNOWN,
@@ -204,8 +205,8 @@ def setup(hass, config):
return
for hvac in target_hvacs:
hvac.set_temperature(convert(
temperature, hass.config.temperature_unit,
hvac.set_temperature(convert_temperature(
temperature, hass.config.units.temperature_unit,
hvac.unit_of_measurement))
if hvac.should_poll:
@@ -462,12 +463,12 @@ class HvacDevice(Entity):
@property
def min_temp(self):
"""Return the minimum temperature."""
return convert(19, TEMP_CELSIUS, self.unit_of_measurement)
return convert_temperature(19, TEMP_CELSIUS, self.unit_of_measurement)
@property
def max_temp(self):
"""Return the maximum temperature."""
return convert(30, TEMP_CELSIUS, self.unit_of_measurement)
return convert_temperature(30, TEMP_CELSIUS, self.unit_of_measurement)
@property
def min_humidity(self):
@@ -481,13 +482,13 @@ class HvacDevice(Entity):
def _convert_for_display(self, temp):
"""Convert temperature into preferred units for display purposes."""
if temp is None:
return None
if temp is None or not isinstance(temp, Number):
return temp
value = convert(temp, self.unit_of_measurement,
self.hass.config.temperature_unit)
value = convert_temperature(temp, self.unit_of_measurement,
self.hass.config.units.temperature_unit)
if self.hass.config.temperature_unit is TEMP_CELSIUS:
if self.hass.config.units.temperature_unit is TEMP_CELSIUS:
decimal_count = 1
else:
# Users of fahrenheit generally expect integer units.
+2 -2
View File
@@ -10,7 +10,7 @@ import socket
from homeassistant.const import (ATTR_BATTERY_LEVEL, CONF_OPTIMISTIC,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
STATE_OFF, STATE_ON, TEMP_CELSIUS)
STATE_OFF, STATE_ON)
from homeassistant.helpers import validate_config, discovery
CONF_GATEWAYS = 'gateways'
@@ -53,7 +53,7 @@ def setup(hass, config): # pylint: disable=too-many-locals
import mysensors.mysensors as mysensors
version = str(config[DOMAIN].get(CONF_VERSION, DEFAULT_VERSION))
is_metric = (hass.config.temperature_unit == TEMP_CELSIUS)
is_metric = hass.config.units.is_metric
persistence = config[DOMAIN].get(CONF_PERSISTENCE, True)
def setup_gateway(device, persistence_file, baud_rate, tcp_port):
+4 -7
View File
@@ -27,9 +27,6 @@ DEFAULT_TOLERANCE = 1
# Default zone
DEFAULT_PROXIMITY_ZONE = 'home'
# Default unit of measure
DEFAULT_UNIT_OF_MEASUREMENT = 'km'
# Default distance to zone
DEFAULT_DIST_TO_ZONE = NOT_SET
@@ -71,7 +68,7 @@ def setup_proximity_component(hass, config):
# Get the unit of measurement from configuration.yaml.
unit_of_measure = config.get(ATTR_UNIT_OF_MEASUREMENT,
DEFAULT_UNIT_OF_MEASUREMENT)
hass.config.units.length_unit)
zone_id = 'zone.{}'.format(proximity_zone)
state = hass.states.get(zone_id)
@@ -216,11 +213,11 @@ class Proximity(Entity): # pylint: disable=too-many-instance-attributes
# Loop through each of the distances collected and work out the
# closest.
closest_device = ''
dist_to_zone = 1000000
closest_device = None # type: str
dist_to_zone = None # type: float
for device in distances_to_zone:
if distances_to_zone[device] < dist_to_zone:
if not dist_to_zone or distances_to_zone[device] < dist_to_zone:
closest_device = device
dist_to_zone = distances_to_zone[device]
+6 -4
View File
@@ -10,6 +10,7 @@ from datetime import timedelta
from homeassistant.const import TEMP_FAHRENHEIT
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle
from homeassistant.util.temperature import celsius_to_fahrenheit
# Update this requirement to upstream as soon as it supports Python 3.
REQUIREMENTS = ['http://github.com/mala-zaba/Adafruit_Python_DHT/archive/'
@@ -32,8 +33,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=import-error
import Adafruit_DHT
SENSOR_TYPES['temperature'][1] = hass.config.temperature_unit
unit = hass.config.temperature_unit
SENSOR_TYPES['temperature'][1] = hass.config.units.temperature_unit
available_sensors = {
"DHT11": Adafruit_DHT.DHT11,
"DHT22": Adafruit_DHT.DHT22,
@@ -58,7 +58,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
if variable not in SENSOR_TYPES:
_LOGGER.error('Sensor type: "%s" does not exist', variable)
else:
dev.append(DHTSensor(data, variable, unit, name))
dev.append(
DHTSensor(data, variable, SENSOR_TYPES[variable][1], name))
except KeyError:
pass
@@ -103,7 +104,8 @@ class DHTSensor(Entity):
if self.type == 'temperature':
self._state = round(data['temperature'], 1)
if self.temp_unit == TEMP_FAHRENHEIT:
self._state = round(data['temperature'] * 1.8 + 32, 1)
self._state = round(celsius_to_fahrenheit(data['temperature']),
1)
elif self.type == 'humidity':
self._state = round(data['humidity'], 1)
+1 -3
View File
@@ -10,7 +10,6 @@ import logging
import datetime
import time
from homeassistant.const import TEMP_CELSIUS
from homeassistant.util import Throttle
from homeassistant.helpers.entity import Entity
from homeassistant.loader import get_component
@@ -238,8 +237,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
for resource in config.get("monitored_resources",
FITBIT_DEFAULT_RESOURCE_LIST):
dev.append(FitbitSensor(authd_client, config_path, resource,
hass.config.temperature_unit ==
TEMP_CELSIUS))
hass.config.units.is_metric))
add_devices(dev)
else:
+2 -2
View File
@@ -10,7 +10,7 @@ from requests.exceptions import ConnectionError as ConnectError, \
HTTPError, Timeout
from homeassistant.components.sensor import DOMAIN
from homeassistant.const import CONF_API_KEY, TEMP_CELSIUS
from homeassistant.const import CONF_API_KEY
from homeassistant.helpers import validate_config
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle
@@ -62,7 +62,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
if 'units' in config:
units = config['units']
elif hass.config.temperature_unit == TEMP_CELSIUS:
elif hass.config.units.is_metric:
units = 'si'
else:
units = 'us'
@@ -11,8 +11,7 @@ import voluptuous as vol
from homeassistant.helpers.entity import Entity
from homeassistant.const import (
CONF_API_KEY, TEMP_CELSIUS, TEMP_FAHRENHEIT,
EVENT_HOMEASSISTANT_START, ATTR_LATITUDE, ATTR_LONGITUDE)
CONF_API_KEY, EVENT_HOMEASSISTANT_START, ATTR_LATITUDE, ATTR_LONGITUDE)
from homeassistant.util import Throttle
import homeassistant.helpers.config_validation as cv
@@ -92,10 +91,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
options = config.get(CONF_OPTIONS)
if options.get('units') is None:
if hass.config.temperature_unit is TEMP_CELSIUS:
options['units'] = 'metric'
elif hass.config.temperature_unit is TEMP_FAHRENHEIT:
options['units'] = 'imperial'
options['units'] = hass.config.units.name
travel_mode = config.get(CONF_TRAVEL_MODE)
mode = options.get(CONF_MODE)
@@ -65,7 +65,7 @@ class MoldIndicator(Entity):
self._indoor_humidity_sensor = indoor_humidity_sensor
self._outdoor_temp_sensor = outdoor_temp_sensor
self._calib_factor = calib_factor
self._is_metric = (hass.config.temperature_unit == TEMP_CELSIUS)
self._is_metric = hass.config.units.is_metric
self._dewpoint = None
self._indoor_temp = None
@@ -48,8 +48,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
from pyowm import OWM
SENSOR_TYPES['temperature'][1] = hass.config.temperature_unit
unit = hass.config.temperature_unit
SENSOR_TYPES['temperature'][1] = hass.config.units.temperature_unit
forecast = config.get('forecast')
owm = OWM(config.get(CONF_API_KEY, None))
@@ -67,13 +66,15 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
if variable not in SENSOR_TYPES:
_LOGGER.error('Sensor type: "%s" does not exist', variable)
else:
dev.append(OpenWeatherMapSensor(data, variable, unit))
dev.append(OpenWeatherMapSensor(data, variable,
SENSOR_TYPES[variable][1]))
except KeyError:
pass
if forecast:
SENSOR_TYPES['forecast'] = ['Forecast', None]
dev.append(OpenWeatherMapSensor(data, 'forecast', unit))
dev.append(OpenWeatherMapSensor(data, 'forecast',
SENSOR_TYPES['temperature'][1]))
add_devices(dev)
+1 -1
View File
@@ -21,7 +21,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Setup the Temper sensors."""
from temperusb.temper import TemperHandler
temp_unit = hass.config.temperature_unit
temp_unit = hass.config.units.temperature_unit
name = config.get(CONF_NAME, DEVICE_DEFAULT_NAME)
temper_devices = TemperHandler().get_devices()
add_devices_callback([TemperSensor(dev, temp_unit, name + '_' + str(idx))
+2 -9
View File
@@ -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.temperature(
current_temp,
self._temperature_units)
current_temp, self._temperature_units = 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":
+1 -1
View File
@@ -45,7 +45,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Yahoo! weather sensor."""
from yahooweather import get_woeid, UNIT_C, UNIT_F
unit = hass.config.temperature_unit
unit = hass.config.units.temperature_unit
woeid = config.get("woeid", None)
forecast = config.get("forecast", 0)
@@ -6,6 +6,7 @@ https://home-assistant.io/components/thermostat/
"""
import logging
import os
from numbers import Number
import voluptuous as vol
@@ -13,9 +14,9 @@ from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.config import load_yaml_config_file
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.temperature import convert
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
import homeassistant.helpers.config_validation as cv
from homeassistant.util.temperature import convert
from homeassistant.const import (
ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_ON, STATE_OFF, STATE_UNKNOWN,
TEMP_CELSIUS)
@@ -146,10 +147,11 @@ def setup(hass, config):
temperature = service.data[ATTR_TEMPERATURE]
for thermostat in target_thermostats:
thermostat.set_temperature(convert(
temperature, hass.config.temperature_unit,
thermostat.unit_of_measurement))
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(
@@ -310,13 +312,13 @@ class ThermostatDevice(Entity):
def _convert_for_display(self, temp):
"""Convert temperature into preferred units for display purposes."""
if temp is None:
return None
if temp is None or not isinstance(temp, Number):
return temp
value = convert(temp, self.unit_of_measurement,
self.hass.config.temperature_unit)
value = self.hass.config.units.temperature(temp,
self.unit_of_measurement)
if self.hass.config.temperature_unit is TEMP_CELSIUS:
if self.hass.config.units.is_metric:
decimal_count = 1
else:
# Users of fahrenheit generally expect integer units.
@@ -8,7 +8,7 @@ import logging
from homeassistant.components.thermostat import ThermostatDevice
from homeassistant.const import TEMP_CELSIUS
from homeassistant.helpers.temperature import convert
from homeassistant.util.temperature import convert
REQUIREMENTS = ['bluepy_devices==0.2.0']
@@ -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']
@@ -75,7 +73,7 @@ class HeatControl(ThermostatDevice):
self._min_temp = min_temp
self._max_temp = max_temp
self._target_temp = target_temp
self._unit = None
self._unit = hass.config.units.temperature_unit
track_state_change(hass, sensor_entity_id, self._sensor_changed)
@@ -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."""
@@ -7,7 +7,7 @@ https://home-assistant.io/components/thermostat.homematic/
import logging
import homeassistant.components.homematic as homematic
from homeassistant.components.thermostat import ThermostatDevice
from homeassistant.helpers.temperature import convert
from homeassistant.util.temperature import convert
from homeassistant.const import TEMP_CELSIUS, STATE_UNKNOWN
DEPENDENCIES = ['homematic']