Logout method

Python2:
- Added HomeSFR.logout () method to logout from service
- moved HomeSFR.get_cookies () method in the HomeSFR class

Python3:
- Added HomeSFR.logout () method to logout from service
- moved HomeSFR.get_cookies () method in the HomeSFR class
This commit is contained in:
Sasha MOREL 2016-05-23 15:11:43 +02:00
parent d90da89b47
commit 4c6063cd8c
2 changed files with 46 additions and 18 deletions

View File

@ -12,14 +12,13 @@ This is a wrap aroud website, this could stop working without prior notice
### Get image ### Get image
### Get video ### Get video
## Manage logs ## Manage logs
## Logout method
## Encoding error for sensors' names ## Encoding error for sensors' names
authors = ( authors = (
'Gilles "Almtesh" Émilien MOREL', 'Gilles "Almtesh" Émilien MOREL',
) )
name = 'homesfr for Python 2' name = 'homesfr for Python 2'
version = '0.9-20160523' version = '0.10-20160523'
# Settable modes # Settable modes
MODE_OFF = 0 MODE_OFF = 0
@ -110,6 +109,7 @@ class HomeSFR ():
self.auth_user_field = 'email' self.auth_user_field = 'email'
self.auth_pass_field = 'passwd' self.auth_pass_field = 'passwd'
self.auth_extra_fields = {'back': 'service', 'token_sso': '', 'error_sso': '', 'SubmitLogin': 'OK'} self.auth_extra_fields = {'back': 'service', 'token_sso': '', 'error_sso': '', 'SubmitLogin': 'OK'}
self.auth_logout_path = '/deconnexion'
# Path to sensors and mode # Path to sensors and mode
self.sensors_list = '/mysensors' self.sensors_list = '/mysensors'
@ -189,6 +189,27 @@ class HomeSFR ():
else: else:
return (False) return (False)
def logout (self):
'''
Logs out from HomeBySFR service
The object should be destroyed just after calling this method
'''
if self.DEBUG:
print ('Sending disconnect')
self.opener.open (self.base_url + self.auth_logout_path)
if self.DEBUG:
print ('Destroying cookies')
del self.cookies
self.cookies = None
return (None)
def get_cookies (self):
'''
Returns the CookieJar as it is now, for further use
It's strongly recommended to use this method only before a object delete
'''
return (self.cookies)
def set_mode (self, mode): def set_mode (self, mode):
''' '''
Sets the detection mode Sets the detection mode
@ -286,13 +307,6 @@ class HomeSFR ():
for i in self.list_sensors (): for i in self.list_sensors ():
r.append (self.get_sensor (i)) r.append (self.get_sensor (i))
return (tuple (r)) return (tuple (r))
def get_cookies (self):
'''
Returns the CookieJar as it is now, for further use
It's strongly recommended to use this method only before a object delete
'''
return (self.cookies)
class Sensor: class Sensor:
''' '''

View File

@ -11,13 +11,12 @@ This is a wrap aroud website, this could stop working without prior notice
### Get image ### Get image
### Get video ### Get video
## Manage logs ## Manage logs
## Logout method
authors = ( authors = (
'Gilles "Almtesh" Émilien MOREL', 'Gilles "Almtesh" Émilien MOREL',
) )
name = 'homesfr for Python 3' name = 'homesfr for Python 3'
version = '0.9-20160523' version = '0.10-20160523'
# Settable modes # Settable modes
MODE_OFF = 0 MODE_OFF = 0
@ -108,6 +107,7 @@ class HomeSFR ():
self.auth_user_field = 'email' self.auth_user_field = 'email'
self.auth_pass_field = 'passwd' self.auth_pass_field = 'passwd'
self.auth_extra_fields = {'back': 'service', 'token_sso': '', 'error_sso': '', 'SubmitLogin': 'OK'} self.auth_extra_fields = {'back': 'service', 'token_sso': '', 'error_sso': '', 'SubmitLogin': 'OK'}
self.auth_logout_path = '/deconnexion'
# Path to sensors and mode # Path to sensors and mode
self.sensors_list = '/mysensors' self.sensors_list = '/mysensors'
@ -187,6 +187,27 @@ class HomeSFR ():
else: else:
return (False) return (False)
def logout (self):
'''
Logs out from HomeBySFR service
The object should be destroyed just after calling this method
'''
if self.DEBUG:
print ('Sending disconnect')
self.opener.open (self.base_url + self.auth_logout_path)
if self.DEBUG:
print ('Destroying cookies')
del self.cookies
self.cookies = None
return (None)
def get_cookies (self):
'''
Returns the CookieJar as it is now, for further use
It's strongly recommended to use this method only before a object delete
'''
return (self.cookies)
def set_mode (self, mode): def set_mode (self, mode):
''' '''
Sets the detection mode Sets the detection mode
@ -284,13 +305,6 @@ class HomeSFR ():
for i in self.list_sensors (): for i in self.list_sensors ():
r.append (self.get_sensor (i)) r.append (self.get_sensor (i))
return (tuple (r)) return (tuple (r))
def get_cookies (self):
'''
Returns the CookieJar as it is now, for further use
It's strongly recommended to use this method only before a object delete
'''
return (self.cookies)
class Sensor: class Sensor:
''' '''