Skip to content

Commit

Permalink
Migrate nest platform to python-nest
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Jan 13, 2015
1 parent 646f22b commit b9a08bb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 387 deletions.
1 change: 1 addition & 0 deletions homeassistant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ def set(self, entity_id, new_state, attributes=None):
not be affected.
"""

new_state = str(new_state)
attributes = attributes or {}

with self._lock:
Expand Down
52 changes: 30 additions & 22 deletions homeassistant/components/thermostat/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,69 +22,77 @@ def get_devices(hass, config):
return []

try:
# pylint: disable=no-name-in-module, unused-variable
import homeassistant.external.pynest.nest as pynest # noqa
import nest
except ImportError:
logger.exception("Error while importing dependency phue.")
logger.exception(
"Error while importing dependency nest. "
"Did you maybe not install the python-nest dependency?")

return []

return [NestThermostat(username, password)]
napi = nest.Nest(username, password)

return [
NestThermostat(structure, device)
for structure in napi.structures
for device in structure.devices]


class NestThermostat(ThermostatDevice):
""" Represents a Nest thermostat within Home Assistant. """

def __init__(self, username, password):
# pylint: disable=no-name-in-module, import-error
import homeassistant.external.pynest.nest as pynest

self.nest = pynest.Nest(username, password)
self.nest.login()
self.update()
def __init__(self, structure, device):
self.structure = structure
self.device = device

@property
def name(self):
""" Returns the name of the nest, if any. """
return "Nest"
return self.device.name

@property
def unit_of_measurement(self):
""" Returns the unit of measurement. """
return TEMP_FAHRENHEIT if self.nest.units == 'F' else TEMP_CELCIUS
return TEMP_CELCIUS

@property
def device_state_attributes(self):
""" Returns device specific state attributes. """
return None
# Move these to Thermostat Device and make them global
return {
"humidity": self.device.humidity,
"target_humidity": self.device.target_humidity,
"fan": self.device.fan,
"mode": self.device.mode
}

@property
def current_temperature(self):
""" Returns the current temperature. """
return self.nest.get_curtemp()
return round(self.device.temperature, 1)

@property
def target_temperature(self):
""" Returns the temperature we try to reach. """
return self.nest.get_tartemp()
return round(self.device.target, 1)

@property
def is_away_mode_on(self):
""" Returns if away mode is on. """
return self.nest.is_away()
return self.structure.away

def set_temperature(self, temperature):
""" Set new target temperature """
self.nest.set_temperature(temperature)
self.device.target = temperature

def turn_away_mode_on(self):
""" Turns away on. """
self.nest.set_away("away")
self.structure.away = True

def turn_away_mode_off(self):
""" Turns away off. """
self.nest.set_away("here")
self.structure.away = False

def update(self):
""" Update nest. """
self.nest.get_status()
""" Python-nest has its own mechanism for staying up to date. """
pass
Loading

0 comments on commit b9a08bb

Please sign in to comment.