Skip to content

Instantly share code, notes, and snippets.

@ViViDboarder
Created September 24, 2024 22:47
Show Gist options
  • Save ViViDboarder/6ad9da8bae86baee4f11bff5ae3f1231 to your computer and use it in GitHub Desktop.
Save ViViDboarder/6ad9da8bae86baee4f11bff5ae3f1231 to your computer and use it in GitHub Desktop.
WeMo device setup script for pywemo
from getpass import getpass
from pywemo import discovery
from pywemo.ouimeaux_device import Device
def discover() -> Device | None:
for device in discovery.discover_devices():
print(device)
if input("y/N? ").lower() == "y":
return device
return None
def main() -> int:
device = discover()
if not device:
print("No selection. Try again or pick something new.")
return 1
ssid = input("SSID: ")
password = getpass("Network passphrase: ")
if not ssid or not password:
print("Must provide SSID and passphrase")
return 1
print("Setting up...")
result = device.setup(ssid=ssid, password=password)
if result[1] != "success":
print(result)
return 1
print("Success!")
return 0
if __name__ == "__main__":
exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment