Skip to content

Commit a241cd9

Browse files
committed
Got basics working with thermostat
1 parent dbbace7 commit a241cd9

File tree

4 files changed

+184
-1057
lines changed

4 files changed

+184
-1057
lines changed

README.rst renamed to README.md

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,49 @@
1-
=========================================================
2-
Python API and command line tool for the Nest™ Thermostat
3-
=========================================================
1+
# Python API and command line tool for the Nest™ Thermostat
42

3+
TODO: Fix build check
54
.. image:: https://travis-ci.org/jkoelker/python-nest.svg?branch=master
65
:target: https://travis-ci.org/jkoelker/python-nest
76

7+
**NOTE: This library support the new (post 2020) API provided by Google which replaced the original Nest Developers API.**
88

9-
Installation
10-
============
11-
12-
.. code-block:: bash
13-
14-
[sudo] pip install python-nest
15-
16-
17-
*NOTE* The ``4.x`` version uses the streaming endpoint. To use the older
18-
polling/caching behavior pin your requirements to ``python-nest<4.0``.
19-
20-
*NOTE* The ``3.x`` version uses the Nest official api. As such, some functionality
21-
was removed as it is not available. To keep the old version and functionality, make sure to set
22-
your requirements to ``python-nest<3.0``.
23-
24-
Nest Developer Account
25-
=======================
9+
## Installation
2610

11+
```bash
12+
[sudo] pip install python-google-nest
13+
```
2714

28-
You will need a Nest developer account, and a Product on the Nest developer portal to use this module:
15+
## Google Device Access Registration
2916

30-
1. Visit `Nest Developers <https://developers.nest.com/>`_, and sign in. Create an account if you don't have one already.
17+
This is a fairly onerous process, so make sure to read the details before you begin.
3118

32-
2. Fill in the account details:
19+
The biggest roadblock is that access to this API requires registering with Google for Device Access <https://developers.google.com/nest/device-access/registration>. This has a one time $5 fee.
3320

34-
- The "Company Information" can be anything.
21+
The documentation <https://developers.google.com/nest/device-access/get-started> walks you through the rest of the process.
3522

36-
3. Submit changes.
23+
At a high level it involves:
3724

38-
4. Click "`Products <https://developers.nest.com/products>`_" at top of page.
25+
1. Making sure your Nest devices are linked to your Google account
26+
2. Set up GCP (Google Cloud Platform) account <https://console.cloud.google.com/>
27+
3. Set up a new GCP project
28+
1. Create a Oauth landing page and add your email as a test user
29+
2. Enable the Smart device management API
30+
3. Create an Oauth credential with the settings called from web server and https://www.google.com as the authorized redirect URI. Note the client ID and secret from this step.
31+
4. In https://console.nest.google.com/device-access create a new project and add oauth client ID from step 3.3
32+
5. Follow the series of queries in https://developers.google.com/nest/device-access/authorize to authorize devices
3933

40-
5. Click "`Create New Product <https://developers.nest.com/products/new>`_"
34+
You should end up with the following pieces of information:
35+
* project-id - ID of the project you created in https://console.nest.google.com/device-access
36+
* oauth_client_id - value from setting up OAuth in https://console.cloud.google.com/ project
37+
* client_secret - value from setting up OAuth in https://console.cloud.google.com/ project
38+
* authorization_code - You get this value when you authorize your https://console.nest.google.com/device-access project to access your devices
39+
* access-token - Token used to make requests to https://smartdevicemanagement.googleapis.com
40+
* refresh-token - Used to get a new access-token when the old one expires
4141

42-
6. Fill in details:
42+
Be careful as you follow along the guide in <https://developers.google.com/nest/device-access/get-started>, since you're dealing with so many similar accounts and keys it can be easy to mix something up and you won't get particularly useful errors.
4343

44-
- Product name must be unique.
44+
## Usage
4545

46-
- The description, users, urls can all be anything you want.
4746

48-
7. For permissions, check every box and if it's an option select the read/write option.
49-
50-
- The description requires a specific format to be accepted.
51-
52-
8. Click "Create Product".
53-
54-
9. Once the new product page opens the "Product ID" and "Product Secret" are located on the right side. These will be used as client_id and client_secret below.
55-
56-
57-
Usage
58-
=====
59-
60-
Migrate to 4.x
61-
--------------
62-
The version 4.x uses `Nest Stream API <https://developers.nest.com/documentation/cloud/rest-streaming-guide>`_, so that you can get nearly real time status update of your Nest devices.
6347

6448
If you use python-nest as a command line tool:
6549
You don't need to change, but there is a new command line option ``--keep-alive`` you can give a try.
@@ -303,6 +287,6 @@ The ``[NEST]`` section may also be named ``[nest]`` for convenience. Do not use
303287

304288
History
305289
=======
306-
307-
This module was originally a fork of `nest_thermostat <https://github.com/FiloSottile/nest_thermostat>`_
290+
This module was originally a fork of `python-nest <https://github.com/jkoelker/python-nest>`_
291+
which was a fork of `nest_thermostat <https://github.com/FiloSottile/nest_thermostat>`_
308292
which was a fork of `pynest <https://github.com/smbaker/pynest>`_

nest/command_line.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ def handle_show_commands(napi, device, display_temp, print_prompt,
299299
print('Press Ctrl+C to EXIT')
300300

301301

302+
def reautherize_callback(authorization_url):
303+
print('Please go to %s and authorize access.' % authorization_url)
304+
return input('Enter the full callback URL: ')
305+
302306
def main():
303307
parser = get_parser()
304308
args = parser.parse_args()
@@ -351,12 +355,8 @@ def _identity(x):
351355
with nest.Nest(project_id=args.project_id, client_id=args.client_id,
352356
client_secret=args.client_secret,
353357
access_token=args.token,
354-
access_token_cache_file=token_cache) as napi:
355-
if napi.authorization_required:
356-
print('Go to ' + napi.authorize_url +
357-
' to authorize, then enter PIN below')
358-
authorization_code = input("Authorization Code: ")
359-
napi.request_token(authorization_code)
358+
access_token_cache_file=token_cache,
359+
reautherize_callback=reautherize_callback) as napi:
360360

361361
if cmd.startswith("camera"):
362362
return handle_camera_commands(napi, args)
@@ -420,21 +420,13 @@ def _identity(x):
420420
else:
421421
device = napi.thermostats[args.index]
422422

423-
if args.celsius and device.temperature_scale == 'F':
424-
display_temp = utils.f_to_c
425-
elif not args.celsius and device.temperature_scale == 'C':
423+
424+
if not args.celsius:
426425
display_temp = utils.c_to_f
427426

428427
if cmd == 'temp':
429428
if args.temperature:
430-
if len(args.temperature) > 1:
431-
if device.mode != 'range':
432-
device.mode = 'range'
433-
434-
device.temperature = args.temperature
435-
436-
else:
437-
device.temperature = args.temperature[0]
429+
device.heat_setpoint = args.temperature[0]
438430

439431
print('%0.1f' % display_temp(device.temperature))
440432

0 commit comments

Comments
 (0)