/ device.py
device.py
1 """A controller for the Argo Ulisse 13 DCI Eco Wifi.""" 2 3 import requests 4 5 6 class Argo(object): 7 cookies = None 8 base_url = "http://31.14.128.210/UI" 9 webapp_url = f"{base_url}/WEBAPP/webapp.php" 10 ui_url = f"{base_url}/UI.php" 11 12 def login(self, username: str, password: str) -> bool: 13 """Log in to the WebUI interface. 14 15 This should be run prior to any other command, as it retrieves 16 cookies that are necessary for the other command to work. 17 18 Returns: 19 True if the login was successful. 20 """ 21 params = { 22 "username": username, 23 "password": password, 24 "rememberme": "on", 25 } 26 resp = requests.get(self.webapp_url, params=params) 27 if "password_JS" not in resp.cookies: 28 return False 29 self.cookies = resp.cookies 30 return True 31 32 def turn_on(self) -> None: 33 """Turns on the Argo.""" 34 self._toggle(True) 35 36 def turn_off(self) -> None: 37 """Turns off the Argo.""" 38 self._toggle(False) 39 40 def _hmi(self, enable: bool) -> str: 41 val = 1 if enable else 0 42 return f"N,N,{val},N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N" 43 44 def _toggle(self, enable: bool) -> None: 45 params = { 46 "CM": "UI_TC", 47 "USN": self.cookies["username_JS"], 48 "PSW": self.cookies["password_JS"], 49 "UPD": 1, # Update? 50 "HMI": self._hmi(enable), 51 } 52 requests.get(self.ui_url, params)