Merge pull request #1322 from w1ll1am23/nest_weather_component

Added support for nest current weather conditions
This commit is contained in:
Paulus Schoutsen 2016-02-19 08:24:07 -08:00
commit f20ea41538

View file

@ -21,7 +21,18 @@ SENSOR_TYPES = ['humidity',
'last_connection',
'battery_level']
SENSOR_UNITS = {'humidity': '%', 'battery_level': 'V'}
WEATHER_VARIABLES = ['weather_condition', 'weather_temperature',
'weather_humidity',
'wind_speed', 'wind_direction']
JSON_VARIABLE_NAMES = {'weather_humidity': 'humidity',
'weather_temperature': 'temperature',
'weather_condition': 'condition',
'wind_speed': 'kph',
'wind_direction': 'direction'}
SENSOR_UNITS = {'humidity': '%', 'battery_level': 'V',
'kph': 'kph', 'temperature': '°C'}
SENSOR_TEMP_TYPES = ['temperature',
'target',
@ -45,6 +56,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
add_devices([NestTempSensor(structure,
device,
variable)])
elif variable in WEATHER_VARIABLES:
json_variable = JSON_VARIABLE_NAMES.get(variable, None)
add_devices([NestWeatherSensor(structure,
device,
json_variable)])
else:
logger.error('Nest sensor type: "%s" does not exist',
variable)
@ -109,3 +125,20 @@ class NestTempSensor(NestSensor):
return None
return round(temp, 1)
class NestWeatherSensor(NestSensor):
""" Represents a basic Nest Weather Conditions sensor. """
@property
def state(self):
""" Returns the state of the sensor. """
if self.variable == 'kph' or self.variable == 'direction':
return getattr(self.structure.weather.current.wind, self.variable)
else:
return getattr(self.structure.weather.current, self.variable)
@property
def unit_of_measurement(self):
""" Unit the value is expressed in. """
return SENSOR_UNITS.get(self.variable, None)