Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # DEPENDENCIES: pip3 install aiohttp pysmartthings asyncio
- import aiohttp
- import pysmartthings
- import asyncio
- import requests
- # INSTRUCTION: https://github.com/PiotrMachowski/Home-Assistant-custom-components-SmartThings-Soundbar#getting-api-key-and-device-id
- API_KEY = "API_KEY"
- DEVICE_ID = "DEVICE_ID"
- async def run():
- async with aiohttp.ClientSession() as session:
- api = pysmartthings.SmartThings(session, API_KEY)
- device = (await api.devices(device_ids=[DEVICE_ID]))[0]
- await device.status.refresh()
- print("CAPABILITIES")
- print(device.capabilities)
- print("\nATTRIBUTES")
- print(str(device.status.attributes).replace(DEVICE_ID, "DEVICE_ID"))
- f1 = open("pysmartthings.txt", "w")
- f1.write("CAPABILITIES\n")
- f1.write(str(device.capabilities))
- f1.write("\nATTRIBUTES\n")
- f1.write(str(device.status.attributes).replace(DEVICE_ID, "DEVICE_ID"))
- f1.close()
- async def waiter():
- await run()
- loop = asyncio.get_event_loop()
- loop.run_until_complete(waiter())
- API_DEVICE_STATUS = "https://api.smartthings.com/v1/devices/" + DEVICE_ID + "/states"
- REQUEST_HEADERS = {"Authorization": "Bearer " + API_KEY}
- resp = requests.get(API_DEVICE_STATUS, headers=REQUEST_HEADERS)
- print("\nSTATUS")
- print(str(resp.json()).replace(DEVICE_ID, "DEVICE_ID"))
- f2 = open("api.txt", "w")
- f2.write("STATUS\n")
- f2.write(str(resp.json()).replace(DEVICE_ID, "DEVICE_ID"))
- f2.close()
Add Comment
Please, Sign In to add comment