Repository: jabesq/netatmo-api-python

Issue:
Thermostat disconnected - error not catch
Hi guys, 

I have an issue when my thermostat is disconnected (wifi connection lost...).

I analyse the json received from netatmo, the error tag is include in body, not at root level:
```
{ 
   'status':'ok',
   'body':{ 
      'errors':[ 
         { 
            'code':6,
            'id':'xx:xx:xx:xx:xx:xx'
         }
      ],
      'home':{ 
         'id':'xx'
      }
   },
   'time_server':xxx
}
```

In the thermostat.py, the error is checked in `resp` and not in `resp["body"]` ([after post_request](https://github.com/jabesq/netatmo-api-python/blob/master/src/pyatmo/thermostat.py#L168)):
`if "errors" in resp or "body" not in resp or "home" not in resp["body"]:`

I don't know if the case of error in root level exists...

Thanks.

Discussion:

Patch:
diff --git a/fixtures/home_status_error_disconnected.json b/fixtures/home_status_error_disconnected.json
new file mode 100644
index 0000000..0059e9b
--- /dev/null
+++ b/fixtures/home_status_error_disconnected.json
@@ -0,0 +1,15 @@
+{ 
+   "status":"ok",
+   "body":{ 
+      "errors":[ 
+         { 
+            "code":6,
+            "id":"12:34:56:00:fa:d0"
+         }
+      ],
+      "home":{ 
+         "id":"12:34:56:00:f1:62"
+      }
+   },
+   "time_server":1559292039
+}
\ No newline at end of file
diff --git a/src/pyatmo/thermostat.py b/src/pyatmo/thermostat.py
index 5f2ac9b..0491aca 100644
--- a/src/pyatmo/thermostat.py
+++ b/src/pyatmo/thermostat.py
@@ -165,7 +165,12 @@ class HomeStatus:
         postParams = {"access_token": self.getAuthToken, "home_id": self.home_id}
 
         resp = postRequest(_GETHOMESTATUS_REQ, postParams)
-        if "errors" in resp or "body" not in resp or "home" not in resp["body"]:
+        if (
+            "errors" in resp
+            or "body" not in resp
+            or "home" not in resp["body"]
+            or ("errors" in resp["body"] and "modules" not in resp["body"]["home"])
+        ):
             raise NoDevice("No device found, errors in response")
         self.rawData = resp["body"]["home"]
         self.rooms = {}


Test patch:
diff --git a/tests/test_pyatmo_thermostat.py b/tests/test_pyatmo_thermostat.py
index de930a2..4f85098 100644
--- a/tests/test_pyatmo_thermostat.py
+++ b/tests/test_pyatmo_thermostat.py
@@ -463,3 +463,22 @@ def test_HomeData_setroomThermpoint_error(
         )["error"]["message"]
         == expected
     )
+
+
+def test_HomeStatus_error_disconnected(auth, requests_mock):
+    with open("fixtures/home_status_error_disconnected.json") as f:
+        json_fixture = json.load(f)
+    requests_mock.post(
+        pyatmo.thermostat._GETHOMESTATUS_REQ,
+        json=json_fixture,
+        headers={"content-type": "application/json"},
+    )
+    with open("fixtures/home_data_simple.json") as f:
+        json_fixture = json.load(f)
+    requests_mock.post(
+        pyatmo.thermostat._GETHOMESDATA_REQ,
+        json=json_fixture,
+        headers={"content-type": "application/json"},
+    )
+    with pytest.raises(pyatmo.NoDevice):
+        pyatmo.HomeStatus(auth)