class NestThermostat(HAInterface): VERSION = '1.0.0' def __init__(self, *args, **kwargs): super(NestThermostat, self).__init__(None, *args, **kwargs) def _init(self, *args, **kwargs): super(NestThermostat, self)._init(*args, **kwargs) self._last_temp = None self._mode = None self._hold = None self._fan = None self._set_point = None self._away = None self._user_name = kwargs.get('username', None) self._password = kwargs.get('password', None) self._iteration = 0 self._poll_secs = kwargs.get('poll', 60) self.interface = Nest(self._user_name, self._password) try: self.interface.login() except Exception, ex: self._logger.debug('Could not login: ' + str(ex))
def POST(self): form_input = get_input() username, password = get_credentials() nest = Nest(username, password) try: nest.login() except HTTPError: raise web.seeother(get_path('/logout')) for button_name, button_value in form_input.items(): button_parts = button_name.split(':') action = button_parts[0] structure_id = button_parts[1] device_id = button_parts[2] if len(button_parts) > 2 else None if action == 'homeaway': nest.toggle_away(structure_id=structure_id) elif action == 'fan_toggle': nest.toggle_fan(structure_id=structure_id, device_id=device_id) elif 'target' in action: delta = 0.5 if button_value == '-': delta *= -1 nest.change_temperature(structure_id, device_id, delta=delta, target_type=action) raise web.seeother(get_path('/'))
def GET(self): if not is_https() and not is_localhost(): return render.insecure() username, password = get_credentials() if username is None or password is None: return render.loggedout(message=None) else: nest = Nest(username, password) try: nest.login() except HTTPError: raise web.seeother(get_path('/logout')) logging.info(nest.simple_status) print nest.simple_status return render.loggedin(name=username, nest_state=nest.simple_status, message=None)