Skip to content

Instantly share code, notes, and snippets.

@gyoza
Last active March 20, 2019 14:20
Show Gist options
  • Save gyoza/6be7c23c1719fb980d53f749978f1dce to your computer and use it in GitHub Desktop.
Save gyoza/6be7c23c1719fb980d53f749978f1dce to your computer and use it in GitHub Desktop.
set simplisafe to home
#!/usr/bin/env python3.6
import os
from selenium import webdriver
from selenium.webdriver.common.by import By as by
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as expect
CHROME_PATH = '/usr/bin/google-chrome'
CHROMEDRIVER_PATH = '/usr/bin/chromedriver'
DEFAULT_VALUE = None
USERNAME = os.getenv('SIMPLISAFEUSER', DEFAULT_VALUE)
PASSWORD = os.getenv('SIMPLISAFEPASS', DEFAULT_VALUE)
if not (USERNAME or PASSWORD):
print("NO ENV VARS SET")
quit()
USERNAME = USERNAME.rstrip()
PASSWORD = PASSWORD.rstrip()
def get_web_driver(url, options):
if not url.startswith('https'):
raise Exception('URLs need to start with "https"')
driver = webdriver.Chrome(
executable_path=CHROMEDRIVER_PATH,
chrome_options=options,
)
driver.get(url)
return driver
if __name__ == "__main__":
chrome_options = Options()
chrome_options.binary_location = CHROME_PATH
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
login_url = "https://simplisafe.com/my-account/login"
driver = get_web_driver(login_url, chrome_options)
username = driver.find_element_by_id('existing-username')
username.send_keys(USERNAME)
password = driver.find_element_by_id('existing-user-pass')
password.send_keys(PASSWORD)
loginButton = driver.find_element_by_id('user-login-submit')
loginButton.click()
wait = WebDriverWait(driver, 10)
homeButton = wait.until(expect.presence_of_element_located((by.ID, 'home-circle')))
awayButton = wait.until(expect.presence_of_element_located((by.ID, 'away-circle')))
home_is_active = homeButton.get_attribute("class")
away_is_active = awayButton.get_attribute("class")
if "active-status" in (home_is_active or away_is_active):
print("alarm already set! Not setting.")
driver.quit()
else:
homeButton.click()
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment