Skip to content
This repository was archived by the owner on Dec 4, 2020. It is now read-only.

Commit ded2b63

Browse files
committed
Merge branch 'release/v4.1.0'
2 parents b3cc680 + ded4315 commit ded2b63

11 files changed

Lines changed: 350 additions & 206 deletions

Pipfile.lock

Lines changed: 191 additions & 174 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/weatherstation_data_simple.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,52 @@
459459
}
460460
}
461461
]
462+
},
463+
{
464+
"_id": "12:34:56:1d:68:2e",
465+
"date_setup": 1470935500,
466+
"last_setup": 1470935500,
467+
"type": "NAMain",
468+
"last_status_store": 1588481399,
469+
"module_name": "Basisstation",
470+
"firmware": 177,
471+
"last_upgrade": 1470935401,
472+
"wifi_status": 13,
473+
"reachable": true,
474+
"co2_calibrating": false,
475+
"data_type": [
476+
"Temperature",
477+
"CO2",
478+
"Humidity",
479+
"Noise",
480+
"Pressure"
481+
],
482+
"place": {
483+
"altitude": 93,
484+
"city": "Gothenburg",
485+
"country": "SE",
486+
"timezone": "Europe/Stockholm",
487+
"location": [
488+
11.6136629,
489+
57.7006827
490+
]
491+
},
492+
"dashboard_data": {
493+
"time_utc": 1588481387,
494+
"Temperature": 20.8,
495+
"CO2": 674,
496+
"Humidity": 41,
497+
"Noise": 34,
498+
"Pressure": 1012.1,
499+
"AbsolutePressure": 1001,
500+
"min_temp": 20.8,
501+
"max_temp": 22.2,
502+
"date_max_temp": 1588456859,
503+
"date_min_temp": 1588480176,
504+
"temp_trend": "stable",
505+
"pressure_trend": "up"
506+
},
507+
"modules": []
462508
}
463509
],
464510
"user": {

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="pyatmo",
8-
version="4.0.0", # Should be updated with new versions
8+
version="4.1.0", # Should be updated with new versions
99
author="Hugo Dupras",
1010
author_email="jabesq@gmail.com",
1111
packages=find_packages(exclude=["tests"], where="src"),

src/pyatmo/auth.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ def refresh_tokens(self) -> Dict[str, Union[str, int]]:
101101
return token
102102

103103
def post_request(
104-
self, url: str, params: Optional[Dict] = None, timeout: int = 5,
104+
self,
105+
url: str,
106+
params: Optional[Dict] = None,
107+
timeout: int = 5,
105108
) -> Any:
106109
"""Wrapper for post requests."""
107110
resp = None
@@ -171,12 +174,12 @@ def query(url: str, params: Dict, timeout: int, retries: int) -> Any:
171174
f"when accessing '{url}'"
172175
)
173176

174-
except JSONDecodeError:
177+
except JSONDecodeError as exc:
175178
raise ApiError(
176179
f"{resp.status_code} - "
177180
f"{ERRORS.get(resp.status_code, '')} - "
178181
f"when accessing '{url}'"
179-
)
182+
) from exc
180183

181184
try:
182185
if "application/json" in resp.headers.get("content-type", []):
@@ -252,16 +255,16 @@ def __init__(
252255
password: str,
253256
scope="read_station",
254257
):
255-
# pylint: disable=super-init-not-called
256-
self._client_id = client_id
257-
self._client_secret = client_secret
258+
super().__init__(client_id=client_id, client_secret=client_secret, scope=scope)
258259

259-
self._oauth = OAuth2Session(client=LegacyApplicationClient(client_id=client_id))
260+
self._oauth = OAuth2Session(
261+
client=LegacyApplicationClient(client_id=self.client_id)
262+
)
260263
self._oauth.fetch_token(
261264
token_url=AUTH_REQ,
262265
username=username,
263266
password=password,
264-
client_id=client_id,
265-
client_secret=client_secret,
266-
scope=scope,
267+
client_id=self.client_id,
268+
client_secret=self.client_secret,
269+
scope=self.scope,
267270
)

src/pyatmo/home_coach.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ def __init__(self, auth: NetatmoOAuth2) -> None:
1919
Raises:
2020
NoDevice: No devices found.
2121
"""
22-
super(HomeCoachData, self).__init__(auth, url_req=_GETHOMECOACHDATA_REQ)
22+
super().__init__(auth, url_req=_GETHOMECOACHDATA_REQ)

src/pyatmo/public_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def __init__(
6666
resp = self.auth.post_request(url=_GETPUBLIC_DATA, params=post_params)
6767
try:
6868
self.raw_data = resp["body"]
69-
except (KeyError, TypeError):
70-
raise NoDevice("No public weather data returned by Netatmo server")
69+
except (KeyError, TypeError) as exc:
70+
raise NoDevice("No public weather data returned by Netatmo server") from exc
7171

7272
self.status = resp["status"]
7373
self.time_exec = to_time_string(resp["time_exec"])

src/pyatmo/weather_station.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ def __init__(self, auth: NetatmoOAuth2, url_req: str = None) -> None:
3434

3535
try:
3636
self.raw_data = fix_id(resp["body"].get("devices"))
37-
except KeyError:
37+
except KeyError as exc:
3838
LOG.debug("No <body> in response %s", resp)
39-
raise NoDevice("No weather station data returned by Netatmo server")
39+
raise NoDevice(
40+
"No weather station data returned by Netatmo server"
41+
) from exc
4042

4143
if not self.raw_data:
4244
raise NoDevice("No weather station available")
@@ -84,15 +86,17 @@ def get_modules(self, station_id: str) -> Dict:
8486

8587
res = {}
8688
for station in [self.stations[station_data["_id"]]]:
89+
station_type = station.get("type")
90+
station_name = station.get("station_name", station_type)
8791
res[station["_id"]] = {
88-
"station_name": station["station_name"],
89-
"module_name": station.get("module_name", station.get("type")),
92+
"station_name": station_name,
93+
"module_name": station.get("module_name", station_type),
9094
"id": station["_id"],
9195
}
9296

9397
for module in station["modules"]:
9498
res[module["_id"]] = {
95-
"station_name": module.get("station_name", station["station_name"]),
99+
"station_name": module.get("station_name", station_name),
96100
"module_name": module.get("module_name", module.get("type")),
97101
"id": module["_id"],
98102
}
@@ -141,6 +145,12 @@ def get_monitored_conditions(self, module_id: str) -> List:
141145
if module["type"] in ["NAMain", "NAModule1", "NAModule4", "NHC"]:
142146
conditions.extend(["min_temp", "max_temp"])
143147

148+
if module["type"] in ["NAMain", "NAModule1", "NAModule4"]:
149+
conditions.extend(["temp_trend"])
150+
151+
if module["type"] == "NAMain":
152+
conditions.extend(["pressure_trend"])
153+
144154
if module["type"] in [
145155
"NAMain",
146156
"NAModule1",

tests/test_pyatmo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def test_post_request_binary(auth, requests_mock):
5858

5959

6060
@pytest.mark.parametrize(
61-
"test_input,expected", [(200, None), (404, None), (401, None)],
61+
"test_input,expected",
62+
[(200, None), (404, None), (401, None)],
6263
)
6364
def test_post_request_fail(auth, requests_mock, test_input, expected):
6465
"""Test failing requests against the Netatmo API."""

tests/test_pyatmo_camera.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ def test_camera_data_camera_urls_disconnected(auth, requests_mock):
112112

113113

114114
@pytest.mark.parametrize(
115-
"home_id, expected", [("91763b24c43d3e344f424e8b", ["Richard Doe"])],
115+
"home_id, expected",
116+
[("91763b24c43d3e344f424e8b", ["Richard Doe"])],
116117
)
117118
def test_camera_data_persons_at_home(camera_home_data, home_id, expected):
118119
assert camera_home_data.persons_at_home(home_id) == expected
@@ -321,7 +322,14 @@ def test_camera_data_get_smokedetector(camera_home_data, sid, expected):
321322
"camera_set_state_ok.json",
322323
True,
323324
),
324-
(None, "12:34:56:00:f1:62", None, "on", "camera_set_state_ok.json", True,),
325+
(
326+
None,
327+
"12:34:56:00:f1:62",
328+
None,
329+
"on",
330+
"camera_set_state_ok.json",
331+
True,
332+
),
325333
(
326334
"91763b24c43d3e344f424e8b",
327335
"12:34:56:00:f1:62",

tests/test_pyatmo_thermostat.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,13 @@ def test_home_status_boiler_status(home_status):
391391
],
392392
)
393393
def test_home_status_set_thermmode(
394-
home_status, requests_mock, mode, end_time, schedule_id, json_fixture, expected,
394+
home_status,
395+
requests_mock,
396+
mode,
397+
end_time,
398+
schedule_id,
399+
json_fixture,
400+
expected,
395401
):
396402
with open("fixtures/%s" % json_fixture) as json_file:
397403
json_fixture = json.load(json_file)
@@ -451,7 +457,14 @@ def test_home_status_set_thermmode(
451457
],
452458
)
453459
def test_home_status_set_room_thermpoint(
454-
home_status, requests_mock, room_id, mode, temp, end_time, json_fixture, expected,
460+
home_status,
461+
requests_mock,
462+
room_id,
463+
mode,
464+
temp,
465+
end_time,
466+
json_fixture,
467+
expected,
455468
):
456469
with open("fixtures/%s" % json_fixture) as json_file:
457470
json_fixture = json.load(json_file)
@@ -506,7 +519,13 @@ def test_home_status_set_room_thermpoint(
506519
],
507520
)
508521
def test_home_status_set_room_thermpoint_error(
509-
home_status, requests_mock, room_id, mode, temp, json_fixture, expected,
522+
home_status,
523+
requests_mock,
524+
room_id,
525+
mode,
526+
temp,
527+
json_fixture,
528+
expected,
510529
):
511530
with open("fixtures/%s" % json_fixture) as json_file:
512531
json_fixture = json.load(json_file)

0 commit comments

Comments
 (0)