johnray / Indigo-Nest-Thermostat-Plugin

Nest Thermostat plugin for Indigo 5.x Pro
GNU General Public License v2.0
17 stars 8 forks source link

Nest plugin failing when trying to add a device #2

Open edrabbit opened 10 years ago

edrabbit commented 10 years ago

THe Nest Plugin is failing to add a device. I debugged and it appears that Nest may have changed the data they are sending back when attempting to _refresh_status. My manual troubleshooting:

>>> from plugin import NestThermostat
>>> NT = NestThermostat('EMAIL@ADDRESS.COM','PASSWORD', 'Upstairs', 'Home')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "plugin.py", line 87, in __init__
    self._refresh_status()
  File "plugin.py", line 137, in _refresh_status
    self._nest_structures[structures[key][NEST_STRUCTURE_NAME].lower()]=key
KeyError: 'name'

Looks like Nest's structure data is missing "name". Here's what status_url is returning in self._status_data (personal info redacted):

{
    "[REDACTED_STRUCTURE_GUID]": {
        "$timestamp": 1390444297312, 
        "$version": 417110165, 
        "away": false, 
        "away_setter": 1, 
        "away_timestamp": 1386876720, 
        "country_code": "US", 
        "devices": [
            "device.[REDACTED_DEVICE_SERIAL]", 
            "device.[REDACTED_DEVICE_SERIAL]"
        ], 
        "dr_reminder_enabled": true, 
        "fabric_ids": [], 
        "house_type": "family", 
        "hvac_safety_shutoff_enabled": true, 
        "measurement_scale": "imperial", 
        "num_thermostats": "unknown", 
        "postal_code": "[REDACTED]", 
        "renovation_date": "unknown", 
        "structure_area": 139.355, 
        "swarm": [
            "device.[REDACTED_DEVICE_SERIAL]", 
            "device.[REDACTED_DEVICE_SERIAL]"
        ], 
        "topaz_enhanced_auto_away_enabled": false, 
        "touched_by": {
            "touched_by": 1
        }, 
        "user": "user.[REDACTED]"
    }
}

I've made my attempt at switching the code to just assume the first structure is what the user wants, but still running into problems inside Indigo with it. See change at https://github.com/edrabbit/Indigo-Nest-Thermostat-Plugin/commit/62700882adeee64bfd3ca4ba23630bbf8604bda9

edrabbit commented 10 years ago

Scratch that, had the right approach with assuming the first structure but misread some code. Got it working (or at east pass the auth/getting status point) now. Forked here rather than pull request since in theory it reduces functionality by making it function for me: https://github.com/edrabbit/Indigo-Nest-Thermostat-Plugin