Merge pull request #1322 from w1ll1am23/nest_weather_component
Added support for nest current weather conditions
This commit is contained in:
commit
f20ea41538
1 changed files with 34 additions and 1 deletions
|
@ -21,7 +21,18 @@ SENSOR_TYPES = ['humidity',
|
||||||
'last_connection',
|
'last_connection',
|
||||||
'battery_level']
|
'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',
|
SENSOR_TEMP_TYPES = ['temperature',
|
||||||
'target',
|
'target',
|
||||||
|
@ -45,6 +56,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
add_devices([NestTempSensor(structure,
|
add_devices([NestTempSensor(structure,
|
||||||
device,
|
device,
|
||||||
variable)])
|
variable)])
|
||||||
|
elif variable in WEATHER_VARIABLES:
|
||||||
|
json_variable = JSON_VARIABLE_NAMES.get(variable, None)
|
||||||
|
add_devices([NestWeatherSensor(structure,
|
||||||
|
device,
|
||||||
|
json_variable)])
|
||||||
else:
|
else:
|
||||||
logger.error('Nest sensor type: "%s" does not exist',
|
logger.error('Nest sensor type: "%s" does not exist',
|
||||||
variable)
|
variable)
|
||||||
|
@ -109,3 +125,20 @@ class NestTempSensor(NestSensor):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return round(temp, 1)
|
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue