2016-05-19 15:15:55 +02:00
|
|
|
'''
|
|
|
|
Home by SFR wrapping class
|
2016-05-22 22:57:39 +02:00
|
|
|
Plain use of your Home by SFR device from a Python 3 library
|
2016-05-19 15:15:55 +02:00
|
|
|
|
|
|
|
Warning:
|
|
|
|
This is a wrap aroud website, this could stop working without prior notice
|
|
|
|
'''
|
|
|
|
|
2016-05-21 16:59:51 +02:00
|
|
|
# TODO:
|
|
|
|
## Manage cameras
|
|
|
|
### Get video
|
|
|
|
|
2018-02-22 21:29:53 +01:00
|
|
|
from urllib import request
|
|
|
|
from http.cookiejar import CookieJar
|
|
|
|
from urllib.parse import urlencode
|
|
|
|
from xml.etree import ElementTree as ET
|
|
|
|
from urllib.error import HTTPError
|
|
|
|
from datetime import datetime
|
|
|
|
|
2016-05-19 15:15:55 +02:00
|
|
|
authors = (
|
|
|
|
'Gilles "Almtesh" Émilien MOREL',
|
2018-02-22 21:29:53 +01:00
|
|
|
)
|
2016-05-23 12:03:27 +02:00
|
|
|
name = 'homesfr for Python 3'
|
2020-09-20 12:00:45 +02:00
|
|
|
version = '1.2'
|
2016-05-19 15:15:55 +02:00
|
|
|
|
|
|
|
# Settable modes
|
|
|
|
MODE_OFF = 0
|
|
|
|
MODE_CUSTOM = 1
|
|
|
|
MODE_ON = 2
|
|
|
|
|
2016-05-22 22:57:39 +02:00
|
|
|
# Sensors names
|
|
|
|
PRESENCE_DETECTOR = 'PIR_DETECTOR'
|
|
|
|
MAGNETIC_OPENNING_DETECTOR = 'MAGNETIC'
|
|
|
|
SMOKE_DETECTOR = 'SMOKE'
|
|
|
|
SIREN = 'SIREN'
|
|
|
|
REMOTE_CONTROLER = 'REMOTE'
|
|
|
|
KEYPAD_CONTROLER = 'KEYPAD'
|
|
|
|
PRESENCE_CAMERA_DETECTOR = 'PIR_CAMERA'
|
|
|
|
|
2019-01-15 23:02:35 +01:00
|
|
|
|
2016-05-25 17:19:16 +02:00
|
|
|
class Common ():
|
2016-05-21 16:59:51 +02:00
|
|
|
'''
|
2016-05-25 17:19:16 +02:00
|
|
|
Common ressources to the library's classes
|
2016-05-21 16:59:51 +02:00
|
|
|
'''
|
2016-05-25 17:19:16 +02:00
|
|
|
|
|
|
|
def __init__ (self):
|
2016-05-19 15:15:55 +02:00
|
|
|
|
|
|
|
# Specific configuration
|
2016-05-25 17:19:16 +02:00
|
|
|
|
2016-05-19 15:15:55 +02:00
|
|
|
self.base_url = 'https://home.sfr.fr'
|
|
|
|
|
|
|
|
# path to login test
|
|
|
|
self.auth_path = '/mysensors'
|
2020-09-26 07:55:57 +02:00
|
|
|
self.auth_ok_url = 'https://home.sfr.fr/logged' # if logged
|
2020-09-20 12:00:45 +02:00
|
|
|
self.auth_post_url = 'https://boutique.home.sfr.fr/authentification'
|
|
|
|
self.auth_referer = 'https://boutique.home.sfr.fr/authentification?back=service'
|
|
|
|
self.auth_user_field = 'email'
|
|
|
|
self.auth_pass_field = 'passwd'
|
|
|
|
self.auth_extra_fields = {'back': 'service', 'token_sso': '', 'error_sso': '', 'SubmitLogin': 'OK'}
|
2016-05-23 15:11:43 +02:00
|
|
|
self.auth_logout_path = '/deconnexion'
|
2016-05-19 15:15:55 +02:00
|
|
|
|
|
|
|
# Path to sensors and mode
|
|
|
|
self.sensors_list = '/mysensors'
|
|
|
|
|
|
|
|
# Path to list of alerts
|
|
|
|
self.alerts_path = '/listalert'
|
|
|
|
|
|
|
|
# Path to get and set modes
|
|
|
|
self.mode_get_path = '/mysensors'
|
|
|
|
self.mode_get_label = 'alarm_mode'
|
|
|
|
self.mode_set_path = '/alarmmode'
|
2018-02-22 21:29:53 +01:00
|
|
|
self.mode_set_field = 'action' # Name for GET field
|
|
|
|
self.mode_off = 'OFF' # Value for off
|
|
|
|
self.mode_custom = 'CUSTOM' # Value for custom
|
|
|
|
self.mode_on = 'ON' # Value for on
|
2016-05-19 15:15:55 +02:00
|
|
|
|
|
|
|
# Cameras
|
|
|
|
self.cameras_list = '/homescope/mycams'
|
|
|
|
self.camera_snapshot = '/homescope/snapshot'
|
2016-05-25 17:19:16 +02:00
|
|
|
self.camera_snapshot_mac = 'mac'
|
2016-05-19 15:15:55 +02:00
|
|
|
self.camera_video = '/homescope/flv'
|
2016-05-25 17:19:16 +02:00
|
|
|
self.camera_vide_mac = 'mac'
|
|
|
|
self.camera_recordings_list = '/listenr'
|
|
|
|
self.camera_recordings_delete = '/delenr'
|
|
|
|
self.camera_recordings_start = '/homescope/record'
|
|
|
|
self.camera_recordings_stop = '/homescope/stoprecord'
|
|
|
|
self.camera_recordings_mac = 'mac'
|
2016-05-19 15:15:55 +02:00
|
|
|
self.camera_get_config_path = '/homescope/camsettings'
|
2016-05-25 17:19:16 +02:00
|
|
|
self.camera_get_config_mac = 'mac'
|
|
|
|
self.camera_get_config_flip = 'FLIP'
|
2018-02-22 21:29:53 +01:00
|
|
|
self.camera_get_config_leds = 'LEDMODE' # set to 0 to turn the leds on
|
2020-09-26 07:51:52 +02:00
|
|
|
self.camera_get_config_petmode = 'pet_mode'
|
|
|
|
self.camera_get_config_recording = 'rec24'
|
|
|
|
self.camera_get_config_privacy = 'privacy'
|
2016-05-25 17:19:16 +02:00
|
|
|
self.camera_get_config_name = 'NAME'
|
2016-05-19 15:15:55 +02:00
|
|
|
self.camera_set_config_path = '/homescope/camsettings'
|
|
|
|
self.camera_set_config_mac = 'mac'
|
|
|
|
self.camera_set_config_flip = 'flip'
|
2018-02-22 21:29:53 +01:00
|
|
|
self.camera_set_config_leds = 'led_mode' # set to 0 to turn the leds on
|
2020-09-26 07:51:52 +02:00
|
|
|
self.camera_set_config_petmode = 'pet_mode'
|
2016-05-25 17:19:16 +02:00
|
|
|
self.camera_set_config_recording = 'rec24'
|
|
|
|
self.camera_set_config_name = 'name'
|
|
|
|
|
|
|
|
# Sensors
|
|
|
|
self.sensors_list = '/mysensors'
|
|
|
|
self.sensors_label = 'Sensor'
|
|
|
|
self.sensors_label_id = 'id'
|
|
|
|
self.sensors_mac_field = 'deviceMac'
|
|
|
|
self.sensors_type_field = 'deviceType'
|
|
|
|
self.sensors_model_field = 'deviceModel'
|
|
|
|
self.sensors_version_field = 'deviceVersion'
|
|
|
|
self.sensors_name_field = 'name'
|
|
|
|
self.sensors_longname_field = 'long_name'
|
2018-02-22 21:29:53 +01:00
|
|
|
self.sensors_namegender_field = 'name_gender' # Only usefull for French for the moment
|
2016-05-25 17:19:16 +02:00
|
|
|
self.sensors_batterylevel_field = 'batteryLevel'
|
|
|
|
self.sensors_signal_field = 'signalLevel'
|
|
|
|
self.sensors_lasttrigger_field = 'lastTriggerTime'
|
|
|
|
self.sensors_lasttrigger_dateformat = '%Y-%m-%d %H:%M:%S'
|
|
|
|
self.sensors_status_field = 'status'
|
|
|
|
self.sensors_status_value_ok = 'OK'
|
|
|
|
# I don't have any other value for the moment
|
2016-05-26 16:57:48 +02:00
|
|
|
|
|
|
|
# Logs
|
2018-02-22 21:29:53 +01:00
|
|
|
self.logs_path = '/getlog?page=1&nbparpage=10000' # should retrieve all available logs
|
2016-05-26 16:57:48 +02:00
|
|
|
self.logs_labels = 'LOG'
|
2016-05-25 17:19:16 +02:00
|
|
|
|
|
|
|
def bytes2file (self, b):
|
|
|
|
'''
|
|
|
|
Gives a file-like class from a Bytes
|
|
|
|
'''
|
|
|
|
from io import BytesIO
|
|
|
|
r = BytesIO ()
|
|
|
|
r.write (b)
|
|
|
|
r.seek (0)
|
|
|
|
return (r)
|
|
|
|
|
|
|
|
def bytes2image (self, b):
|
|
|
|
'''
|
|
|
|
Gives a Image object from bytes
|
|
|
|
Uses the bytes2file function
|
|
|
|
'''
|
|
|
|
from PIL import Image
|
|
|
|
f = self.bytes2file (b)
|
|
|
|
r = Image.open (f)
|
|
|
|
return (r)
|
2016-05-26 16:57:48 +02:00
|
|
|
|
2019-01-15 23:02:35 +01:00
|
|
|
def get_xml_elements (self, url, label, id_label = None):
|
2016-05-26 16:57:48 +02:00
|
|
|
def build_tree (element):
|
|
|
|
r = {}
|
|
|
|
for i in element.getchildren ():
|
|
|
|
if i.getchildren () == []:
|
|
|
|
r.update ({i.tag: i.text})
|
|
|
|
else:
|
|
|
|
r.update ({i.tag: build_tree (i)})
|
|
|
|
return (r)
|
|
|
|
a = self.bytes2file (self.opener.open (url).read ())
|
|
|
|
a.seek (0)
|
|
|
|
b = ET.parse (a)
|
2018-02-22 21:29:53 +01:00
|
|
|
if id_label is None:
|
2016-05-26 16:57:48 +02:00
|
|
|
r = []
|
|
|
|
for i in b.findall (label):
|
|
|
|
r.append (build_tree (i))
|
|
|
|
return (tuple (r))
|
|
|
|
else:
|
|
|
|
r = {}
|
|
|
|
for i in b.findall (label):
|
|
|
|
r.update ({i.get (id_label): build_tree (i)})
|
|
|
|
return (r)
|
2016-05-25 17:19:16 +02:00
|
|
|
|
2019-01-15 23:02:35 +01:00
|
|
|
|
2016-05-25 17:19:16 +02:00
|
|
|
class HomeSFR (Common):
|
|
|
|
def __init__ (self, username = None, password = None, cookies = None, debug = False, autologin = True):
|
|
|
|
'''
|
|
|
|
Sets the class with username and password couple, or cookies
|
|
|
|
Both user/password and cookies can be set, the cookies will be used first
|
|
|
|
The debug parameter defines if the class will write debug messages to stdout, if False, the stdout will never be writen by the class
|
|
|
|
The autologin parameter defines if the class will manage the login by itself, if False, the user must call login () to login and test_login () to check the login
|
|
|
|
The autologin paramater will always be False if no username and password are defined, and the login () method will always return False
|
|
|
|
'''
|
|
|
|
Common.__init__ (self)
|
|
|
|
self.DEBUG = debug
|
|
|
|
if self.DEBUG:
|
|
|
|
print (name + ' ' + version)
|
|
|
|
print ('Authors:')
|
|
|
|
for i in authors:
|
|
|
|
print (' - ' + i)
|
2018-02-22 21:29:53 +01:00
|
|
|
if username is not None:
|
2016-05-25 17:19:16 +02:00
|
|
|
print ('init with username ' + username)
|
2018-02-22 21:29:53 +01:00
|
|
|
if cookies is not None:
|
2016-05-25 17:19:16 +02:00
|
|
|
print ('init with cookies')
|
|
|
|
print ('debug = ' + str (debug))
|
|
|
|
print ('autologin = ' + str (autologin))
|
|
|
|
|
2018-02-22 21:29:53 +01:00
|
|
|
if (username is None or password is None) and cookies is None:
|
2016-05-25 17:19:16 +02:00
|
|
|
raise TypeError ('You must define either username AND password or cookies')
|
|
|
|
self.username = username
|
|
|
|
self.password = password
|
2018-02-22 21:29:53 +01:00
|
|
|
if self.username is not None and self.password is not None:
|
2016-05-25 17:19:16 +02:00
|
|
|
self.autologin = autologin
|
|
|
|
else:
|
|
|
|
self.autologin = False
|
2018-02-22 21:29:53 +01:00
|
|
|
if cookies is None:
|
2016-05-25 17:19:16 +02:00
|
|
|
self.cookies = CookieJar ()
|
2016-12-01 11:27:01 +01:00
|
|
|
elif type (cookies) == CookieJar:
|
2016-05-25 17:19:16 +02:00
|
|
|
self.cookies = cookies
|
2016-12-01 11:27:01 +01:00
|
|
|
else:
|
|
|
|
raise TypeError ('Cookies must be CookieJar type.')
|
2016-05-25 17:19:16 +02:00
|
|
|
self.opener = request.build_opener (request.HTTPCookieProcessor (self.cookies))
|
2016-05-19 15:15:55 +02:00
|
|
|
|
|
|
|
def __str__ (self):
|
|
|
|
'''
|
|
|
|
Shows name, version, defined user and debug state
|
|
|
|
'''
|
2018-02-22 21:29:53 +01:00
|
|
|
if self.username is not None:
|
2016-05-23 09:23:26 +02:00
|
|
|
return (name + ' ' + version + '\nUser: ' + self.username + '\nDebug: ' + str (self.DEBUG))
|
|
|
|
else:
|
|
|
|
return (name + ' ' + version + '\nUser: Unknown (auth from cookie class)\nDebug: ' + str (self.DEBUG))
|
2016-05-19 15:15:55 +02:00
|
|
|
|
|
|
|
def test_login (self):
|
|
|
|
'''
|
|
|
|
Tests if the client is logged
|
|
|
|
Return True if it's logged, returns False either
|
|
|
|
'''
|
|
|
|
try:
|
|
|
|
if self.DEBUG:
|
|
|
|
print ('Testing login')
|
|
|
|
self.opener.open (self.base_url + self.auth_path)
|
|
|
|
except HTTPError:
|
|
|
|
if self.DEBUG:
|
|
|
|
print ('Not connected')
|
|
|
|
return (False)
|
|
|
|
if self.DEBUG:
|
|
|
|
print ('Connected')
|
|
|
|
return (True)
|
|
|
|
|
|
|
|
def login (self):
|
|
|
|
'''
|
|
|
|
Logs in the HomeBySFR service
|
|
|
|
Call this function first or exception will be raised
|
2016-05-23 09:23:26 +02:00
|
|
|
Returns True if the login was a success, False either
|
|
|
|
This method will always return False if no username and password are defined
|
2016-05-19 15:15:55 +02:00
|
|
|
'''
|
2018-02-22 21:29:53 +01:00
|
|
|
if self.username is not None and self.password is not None:
|
2016-05-23 09:23:26 +02:00
|
|
|
self.opener.open (self.auth_referer)
|
|
|
|
data = self.auth_extra_fields
|
|
|
|
data [self.auth_user_field] = self.username
|
|
|
|
data [self.auth_pass_field] = self.password
|
2018-01-27 16:22:13 +01:00
|
|
|
data = bytes (urlencode (data), 'UTF8')
|
2016-05-23 09:23:26 +02:00
|
|
|
if self.DEBUG:
|
2018-02-22 21:29:53 +01:00
|
|
|
print ('Cookies ' + str (len (self.cookies)))
|
2016-05-23 09:23:26 +02:00
|
|
|
print ('Sending data ' + str (data))
|
|
|
|
a = self.opener.open (self.auth_post_url, data = data)
|
|
|
|
if self.DEBUG:
|
|
|
|
print ('Auth redirected to ' + a.geturl ())
|
2020-09-20 12:00:45 +02:00
|
|
|
return (a.geturl () == self.auth_ok_url)
|
2016-05-23 09:23:26 +02:00
|
|
|
else:
|
|
|
|
return (False)
|
2016-05-19 15:15:55 +02:00
|
|
|
|
2016-05-26 16:57:48 +02:00
|
|
|
def do_autologin (self):
|
|
|
|
'''
|
|
|
|
Trigger the autologin
|
|
|
|
'''
|
2020-09-20 12:00:45 +02:00
|
|
|
while (self.autologin and not self.test_login ()):
|
2016-05-26 16:57:48 +02:00
|
|
|
self.login ()
|
|
|
|
|
2016-05-23 15:11:43 +02:00
|
|
|
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)
|
|
|
|
|
2016-05-19 15:15:55 +02:00
|
|
|
def set_mode (self, mode):
|
|
|
|
'''
|
|
|
|
Sets the detection mode
|
|
|
|
For the current version, use the MODE_OFF, MODE_ON and MODE_CUSTOM constants and always returns True, but raises an exception if a problem happens
|
|
|
|
'''
|
2016-05-26 16:57:48 +02:00
|
|
|
self.do_autologin ()
|
2016-05-19 15:15:55 +02:00
|
|
|
if mode == MODE_OFF:
|
|
|
|
m = self.mode_off
|
|
|
|
elif mode == MODE_CUSTOM:
|
|
|
|
m = self.mode_custom
|
|
|
|
elif mode == MODE_ON:
|
|
|
|
m = self.mode_on
|
|
|
|
else:
|
|
|
|
if self.DEBUG:
|
|
|
|
print ('You should use the MODE_OFF, MODE_ON and MODE_CUSTOM constants to set this.')
|
|
|
|
raise ValueError
|
|
|
|
r = self.base_url + self.mode_set_path + '?' + self.mode_set_field + '=' + m
|
|
|
|
if self.DEBUG:
|
|
|
|
print ('Will get ' + r)
|
|
|
|
self.opener.open (r)
|
|
|
|
return (True)
|
|
|
|
|
|
|
|
def get_mode (self):
|
|
|
|
'''
|
|
|
|
Gets the detection mode
|
|
|
|
Returns one of MODE_OFF, MODE_ON and MODE_CUSTOM constants, or None if something went wrong
|
|
|
|
'''
|
2016-05-26 16:57:48 +02:00
|
|
|
self.do_autologin ()
|
2016-05-19 15:15:55 +02:00
|
|
|
r = self.base_url + self.mode_get_path
|
|
|
|
if self.DEBUG:
|
|
|
|
print ('Getting ' + r)
|
2016-05-25 17:19:16 +02:00
|
|
|
a = self.bytes2file (self.opener.open (r).read ())
|
2016-05-19 15:15:55 +02:00
|
|
|
b = ET.parse (a).getroot ()
|
|
|
|
c = b.get (self.mode_get_label)
|
|
|
|
if self.DEBUG:
|
|
|
|
print ('Got mode ' + c)
|
|
|
|
if (c == self.mode_off):
|
|
|
|
return (MODE_OFF)
|
|
|
|
if (c == self.mode_custom):
|
|
|
|
return (MODE_CUSTOM)
|
|
|
|
if (c == self.mode_on):
|
|
|
|
return (MODE_ON)
|
|
|
|
return (None)
|
|
|
|
|
|
|
|
def list_sensors (self):
|
|
|
|
'''
|
|
|
|
Returns a list of sensors' ids.
|
|
|
|
'''
|
2016-05-26 16:57:48 +02:00
|
|
|
self.do_autologin ()
|
2016-05-19 15:15:55 +02:00
|
|
|
r = self.base_url + self.sensors_list
|
2016-05-25 17:19:16 +02:00
|
|
|
a = self.bytes2file (self.opener.open (r).read ())
|
2016-05-19 15:15:55 +02:00
|
|
|
b = ET.parse (a)
|
|
|
|
r = []
|
|
|
|
for i in b.findall (self.sensors_label):
|
|
|
|
r.append (i.get (self.sensors_label_id))
|
|
|
|
return (list (r))
|
|
|
|
|
|
|
|
def get_sensor (self, id):
|
|
|
|
'''
|
2016-05-23 08:41:07 +02:00
|
|
|
Returns a Sensor object for the sensor id or None if sensor is not found
|
2016-05-19 15:15:55 +02:00
|
|
|
The available ids can be got from the list_sensors method
|
|
|
|
'''
|
2016-05-26 16:57:48 +02:00
|
|
|
self.do_autologin ()
|
2016-05-25 17:19:16 +02:00
|
|
|
r = Sensor (id, self.opener)
|
|
|
|
r.refresh ()
|
|
|
|
return (r)
|
2016-05-19 15:15:55 +02:00
|
|
|
|
|
|
|
def get_all_sensors (self):
|
|
|
|
'''
|
2016-05-23 08:41:07 +02:00
|
|
|
Returns a tuple of sensors as described in the get_sensor method
|
2016-05-19 15:15:55 +02:00
|
|
|
'''
|
|
|
|
r = []
|
|
|
|
for i in self.list_sensors ():
|
|
|
|
r.append (self.get_sensor (i))
|
2016-05-23 08:41:07 +02:00
|
|
|
return (tuple (r))
|
2016-05-25 17:19:16 +02:00
|
|
|
|
|
|
|
def get_camera (self, id):
|
|
|
|
'''
|
|
|
|
Get a Camera object from the sensor's id
|
|
|
|
'''
|
2016-05-26 16:57:48 +02:00
|
|
|
self.do_autologin ()
|
2016-05-25 17:19:16 +02:00
|
|
|
r = Camera (id, self.opener)
|
|
|
|
r.refresh ()
|
|
|
|
return (r)
|
2016-05-26 16:57:48 +02:00
|
|
|
|
|
|
|
def get_logs (self):
|
|
|
|
'''
|
2018-01-27 16:22:13 +01:00
|
|
|
Return the whole logs in a form of tuple of dicts, as returned by the site
|
2016-05-26 16:57:48 +02:00
|
|
|
'''
|
|
|
|
self.do_autologin ()
|
|
|
|
a = self.base_url + self.logs_path
|
|
|
|
return (self.get_xml_elements (a, self.logs_labels))
|
2016-05-22 22:57:39 +02:00
|
|
|
|
2019-01-15 23:02:35 +01:00
|
|
|
|
2016-05-25 17:19:16 +02:00
|
|
|
class Sensor (Common):
|
2016-05-22 22:57:39 +02:00
|
|
|
'''
|
|
|
|
Class used to read easily the sensors
|
|
|
|
'''
|
2016-05-25 17:19:16 +02:00
|
|
|
def __init__ (self, id, opener):
|
2016-05-22 22:57:39 +02:00
|
|
|
'''
|
|
|
|
Initialize the class with the dict producted by HomeSFR.get_sensors ()
|
|
|
|
'''
|
2016-05-25 17:19:16 +02:00
|
|
|
Common.__init__ (self)
|
2016-05-22 22:57:39 +02:00
|
|
|
|
2016-05-25 17:19:16 +02:00
|
|
|
self.id = id
|
|
|
|
self.sensor_dict = None
|
|
|
|
self.opener = opener
|
|
|
|
|
|
|
|
def refresh (self):
|
|
|
|
'''
|
|
|
|
Gets or refresh the data for the sensor
|
|
|
|
'''
|
2016-05-26 16:57:48 +02:00
|
|
|
|
2016-05-25 17:19:16 +02:00
|
|
|
r = self.base_url + self.sensors_list
|
|
|
|
self.sensor_dict = None
|
2016-05-26 16:57:48 +02:00
|
|
|
self.sensor_dict = self.get_xml_elements (r, self.sensors_label, self.sensors_label_id) [self.id]
|
2016-05-22 22:57:39 +02:00
|
|
|
|
|
|
|
def get_raw (self):
|
|
|
|
'''
|
|
|
|
Returns the raw dict, as presented in the original XML file
|
|
|
|
'''
|
|
|
|
return (self.sensor_dict)
|
|
|
|
|
2016-05-25 17:19:16 +02:00
|
|
|
def get_mac (self):
|
|
|
|
'''
|
|
|
|
Returns the sensor's model, if any, None either
|
|
|
|
'''
|
|
|
|
return (self.sensor_dict [self.sensors_mac_field])
|
|
|
|
|
2016-05-22 22:57:39 +02:00
|
|
|
def get_type (self):
|
|
|
|
'''
|
|
|
|
Returns the sensor's type
|
|
|
|
'''
|
2016-05-25 17:19:16 +02:00
|
|
|
return (self.sensor_dict [self.sensors_type_field])
|
2016-05-22 22:57:39 +02:00
|
|
|
|
|
|
|
def get_model (self):
|
|
|
|
'''
|
|
|
|
Returns the sensor's model, if any, None either
|
|
|
|
'''
|
2016-05-25 17:19:16 +02:00
|
|
|
return (self.sensor_dict [self.sensors_model_field])
|
2016-05-22 22:57:39 +02:00
|
|
|
|
|
|
|
def get_version (self):
|
|
|
|
'''
|
|
|
|
Returns the sensor's version
|
|
|
|
'''
|
2016-05-25 17:19:16 +02:00
|
|
|
return (self.sensor_dict [self.sensors_version_field])
|
2016-05-22 22:57:39 +02:00
|
|
|
|
|
|
|
def get_name (self):
|
|
|
|
'''
|
|
|
|
Returns the sensor's name
|
|
|
|
'''
|
2016-05-25 17:19:16 +02:00
|
|
|
return (self.sensor_dict [self.sensors_name_field])
|
2016-05-22 22:57:39 +02:00
|
|
|
|
|
|
|
def get_longname (self):
|
|
|
|
'''
|
|
|
|
Returns the sensor's type name in system's language and the sensor's name
|
|
|
|
'''
|
2016-05-25 17:19:16 +02:00
|
|
|
return (self.sensor_dict [self.sensors_longname_field])
|
2016-05-22 22:57:39 +02:00
|
|
|
|
|
|
|
def get_namegender (self):
|
|
|
|
'''
|
|
|
|
Return M for male and F for female.
|
|
|
|
Only usefull for languages with gender on nouns
|
|
|
|
'''
|
2016-05-25 17:19:16 +02:00
|
|
|
return (self.sensor_dict [self.sensors_namegender_field])
|
2016-05-22 22:57:39 +02:00
|
|
|
|
|
|
|
def get_batterylevel (self):
|
|
|
|
'''
|
|
|
|
Returns the sensor's battery level, out of 10
|
|
|
|
It seems that batteryless sensors return 255
|
|
|
|
'''
|
2016-05-25 17:19:16 +02:00
|
|
|
return (int (self.sensor_dict [self.sensors_batterylevel_field]))
|
2016-05-22 22:57:39 +02:00
|
|
|
|
|
|
|
def get_signal (self):
|
|
|
|
'''
|
|
|
|
Returns the sensor's signal quality, out of 10
|
|
|
|
'''
|
2016-05-25 17:19:16 +02:00
|
|
|
return (int (self.sensor_dict [self.sensors_signal_field]))
|
2016-05-22 22:57:39 +02:00
|
|
|
|
|
|
|
def get_lasttrigger (self):
|
|
|
|
'''
|
|
|
|
Return the timestamp of the sensor's last triger
|
|
|
|
The sensors always trigger, even when the alarm's mode is off
|
|
|
|
'''
|
2016-05-25 17:19:16 +02:00
|
|
|
a = self.sensor_dict [self.sensors_lasttrigger_field]
|
2016-05-23 12:03:27 +02:00
|
|
|
# Try because camera return the date '0000-00-00 00:00:00' that is ununderstandable
|
|
|
|
try:
|
2016-05-25 17:19:16 +02:00
|
|
|
b = datetime.strptime (a, self.sensors_lasttrigger_dateformat)
|
2016-05-23 12:03:27 +02:00
|
|
|
except ValueError:
|
|
|
|
return (0)
|
2016-05-22 22:57:39 +02:00
|
|
|
r = int (b.timestamp ())
|
|
|
|
return (r)
|
|
|
|
|
|
|
|
def get_status (self):
|
|
|
|
'''
|
|
|
|
Returns True is the sensor is OK, False either
|
|
|
|
'''
|
2016-05-25 17:19:16 +02:00
|
|
|
return (self.sensor_dict [self.sensors_status_field] == self.sensors_status_value_ok)
|
|
|
|
|
2020-09-26 07:51:52 +02:00
|
|
|
def get_camera_snapshot (self):
|
2016-05-25 17:19:16 +02:00
|
|
|
'''
|
|
|
|
Get a snapshot from the camera
|
|
|
|
Return a PIL.Image object
|
|
|
|
'''
|
|
|
|
r = self.base_url + self.camera_snapshot + '?' + self.camera_snapshot_mac + '=' + self.get_mac ()
|
|
|
|
a = self.bytes2image (self.opener.open (r).read ())
|
2020-09-26 07:51:52 +02:00
|
|
|
return (a)
|
|
|
|
|
|
|
|
def get_camera_petmode (self):
|
|
|
|
'''
|
|
|
|
Gets the pet mode value
|
|
|
|
Pet mode is a setting on movement sensibility, to avoid trigger on pet movements
|
|
|
|
'''
|
|
|
|
return (self.sensor_dict [self.camera_get_config_petmode] == '1')
|
|
|
|
|
|
|
|
def get_camera_recording (self):
|
|
|
|
'''
|
|
|
|
Gets if the camera records or not
|
|
|
|
'''
|
|
|
|
return (self.sensor_dict [self.camera_get_config_recording] == '1')
|
|
|
|
|
|
|
|
def get_camera_privacy (self):
|
|
|
|
'''
|
|
|
|
Gets if the camera records or not
|
|
|
|
'''
|
|
|
|
return (self.sensor_dict [self.camera_get_config_privacy] == '1')
|