From b3b4e4105174e65fae70c195a1a19f619dd63209 Mon Sep 17 00:00:00 2001 From: Gilles MOREL Date: Wed, 21 Oct 2020 09:20:17 +0200 Subject: [PATCH] =?UTF-8?q?Action=20sur=20les=20prises=20connect=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- homesfr.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/homesfr.py b/homesfr.py index 33f3e5d..2657637 100644 --- a/homesfr.py +++ b/homesfr.py @@ -113,6 +113,11 @@ sensors_hum_text = 'Humidity' sensors_oop_stateroot = 'automation' sensors_oop_state = 'on_off' sensors_oop_power = 'power_level' +sensors_oop_control = '/plugcontrol' +sensors_oop_control_sensors_id_field = 'uid' +sensors_oop_control_action_field = 'action' +sensors_oop_control_action_value_on = 'on' +sensors_oop_control_action_value_off = 'off' # Fil d'événements logs_path = '/getlog?page=1&nbparpage=10000' # je pense qu'on récupère tous les événements avec cette valeur @@ -389,8 +394,6 @@ class HomeSFR (): print ('Vous devriez utiliser les constantes MODE_OFF, MODE_ON et MODE_CUSTOM.') raise ValueError r = base_url + mode_set_path + '?' + mode_set_field + '=' + m - if self.DEBUG: - print ('Demande ' + r) self.get_or_autologin (r) return (True) @@ -590,6 +593,13 @@ class Sensor (): a = self.get_attributes (self.get_raw (), sensors_oop_stateroot) return (True if a [sensors_oop_state] == '1' else False) + def set_on_off_state (self, state): + ''' + Défini l'état d'une prise connectée, True pour fermer la prise + ''' + r = base_url + sensors_oop_control + '?' + sensors_oop_control_sensors_id_field + '=' + self.id + '&' + sensors_oop_control_action_field + '=' + (sensors_oop_control_action_value_on if state else sensors_oop_control_action_value_off) + self.get_or_autologin (r) + def get_on_off_power (self): ''' Retourne la puissance active qui traverse la prise, en watts