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

Commit

Permalink
Raise exception on WeatherStationData or WelcomeData if no device
Browse files Browse the repository at this point in the history
  • Loading branch information
philippelt committed Aug 3, 2016
1 parent 217b7f5 commit a8178cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lnetatmo.py
Expand Up @@ -47,6 +47,10 @@
_GETEVENTSUNTIL_REQ = _BASE_URL + "api/geteventsuntil"


class NoDevice( Exception ):
pass


class ClientAuth:
"""
Request authentication and keep access token available through token method. Renew it automatically if necessary
Expand Down Expand Up @@ -131,6 +135,7 @@ def __init__(self, authData):
}
resp = postRequest(_GETSTATIONDATA_REQ, postParams)
self.rawData = resp['body']['devices']
if not self.rawData : raise NoDevice("No weather station available")
self.stations = { d['_id'] : d for d in self.rawData }
self.modules = dict()
for i in range(len(self.rawData)):
Expand Down Expand Up @@ -283,6 +288,7 @@ def __init__(self, authData):
resp = postRequest(_GETHOMEDATA_REQ, postParams)
self.rawData = resp['body']
self.homes = { d['id'] : d for d in self.rawData['homes'] }
if not self.homes : raise NoDevice("No camera available")
self.persons = dict()
self.events = dict()
self.cameras = dict()
Expand Down Expand Up @@ -552,11 +558,22 @@ def getStationMinMaxTH(station=None, module=None):
stderr.write("Library source missing identification arguments to check lnetatmo.py (user/password/etc...)")
exit(1)

authorization = ClientAuth(scope="read_station read_camera access_camera") # Test authentication method
devList = DeviceList(authorization) # Test DEVICELIST
devList.MinMaxTH() # Test GETMEASUR
authorization = ClientAuth(scope="read_station read_camera access_camera") # Test authentication method

try:
devList = DeviceList(authorization) # Test DEVICELIST
except NoDevice:
if stdout.isatty():
print("lnetatmo.py : warning, no weather station available for testing")
else:
devList.MinMaxTH() # Test GETMEASUR


Camera = WelcomeData(authorization)
try:
Camera = WelcomeData(authorization)
except NoDevice :
if stdout.isatty():
print("lnetatmo.py : warning, no camera available for testing")

# If we reach this line, all is OK

Expand Down
2 changes: 2 additions & 0 deletions usage.md
Expand Up @@ -222,6 +222,7 @@ Requires : an authorization object (ClientAuth instance)

Return : a WeatherStationData object. This object contains most administration properties of stations and modules accessible to the user and the last data pushed by the station to the Netatmo servers.

Raise a lnetatmo.NoDevice exception if no weather station is available for the given account.

Properties, all properties are read-only unless specified:

Expand Down Expand Up @@ -331,6 +332,7 @@ Requires : an authorization object (ClientAuth instance)

Return : a WelcomeData object. This object contains most administration properties of Welcome cameras accessible to the user and the last data pushed by the cameras to the Netatmo servers.

Raise a lnetatmo.NoDevice exception if no camera is available for the given account.

Properties, all properties are read-only unless specified:

Expand Down

0 comments on commit a8178cc

Please sign in to comment.