Added support for nest current weather conditions

This commit is contained in:
William Scanlon 2016-02-18 15:39:05 -05:00
parent d39e1be388
commit d7c4b50e3e

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,7 +56,14 @@ 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:
for test in WEATHER_VARIABLES:
logger.error('NEST VAR: %s', test)
logger.error('Nest sensor type: "%s" does not exist',
variable)
except socket.error:
@ -109,3 +127,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)