shauntarves/wyze-sdk

maybe fixed

Closed this issue · 3 comments

using auth app and two way maybe im not catching thing right

woke up to this error

Traceback (most recent call last):
  File "main.py", line 124, in <module>
    onoffH(wyzeclient,"Heat")
  File "main.py", line 80, in onoffH
    toggleh(false,wyzeclient,type)
  File "main.py", line 36, in toggleh
    plug = client.plugs.info(device_mac='7C78B272C3F0-0002')
  File "/home/josh/.local/lib/python3.8/site-packages/wyze_sdk/api/devices/plugs.py", line 31, in info
    plugs = [_plug for _plug in self._list_plugs() if _plug['mac']
  File "/home/josh/.local/lib/python3.8/site-packages/wyze_sdk/api/devices/plugs.py", line 14, in _list_plugs
    return [device for device in super()._list_devices(
  File "/home/josh/.local/lib/python3.8/site-packages/wyze_sdk/api/base.py", line 73, in _list_devices
    return self._api_client().get_object_list()["data"]["device_list"]
TypeError: 'NoneType' object is not subscriptable

had this error yesterday
Traceback (most recent call last): File "main.py", line 124, in <module> onoffH(wyzeclient,"Heat") File "main.py", line 77, in onoffH toggleh(true,wyzeclient,type) File "main.py", line 36, in toggleh plug = client.plugs.info(device_mac='7C78B272C3F0-0002') File "/home/josh/.local/lib/python3.8/site-packages/wyze_sdk/api/devices/plugs.py", line 45, in info if "data" in switch_state_timer.data and switch_state_timer.data['data'] is not None: AttributeError: 'NoneType' object has no attribute 'data'

`from ctypes.wintypes import HMODULE
from datetime import datetime, timedelta
from time import sleep, time
from datetime import datetime

from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS

import os
from sympy import false, round_two, true

from wyze_sdk import Client
from wyze_sdk.errors import WyzeApiError

=======

on = 1
token = "-=="
org = ""
bucket = ""
rh = ""
wyzeclient = Client(email='', password='')

initDate = datetime.now().day

You can generate an API token from the "API Tokens Tab" in the UI

def toggleh(T,wyzeclient,type):
client = wyzeclient

if(type == "Heat"):
    try:
        plug = client.plugs.info(device_mac='')
        s = plug.is_on

        plug2 = client.plugs.info(device_mac='')
        s2 = plug2.is_on
        print("testttt" + str(s2))
        if (T == False) and ( s == True):
            client.plugs.turn_off(device_mac=plug.mac, device_model=plug.product.model, after=timedelta(milliseconds=0))
            print("heater off")
        elif(T == True) and ( s == False):               
            client.plugs.turn_on(device_mac=plug.mac, device_model=plug.product.model)
            plug = client.plugs.info(device_mac=plug.mac)
            print("heater on")   
    
    except WyzeApiError as e:
    # You will get a WyzeApiError if the request failed
            print(f"Got an error: {e}")  
elif(type == "Rh"):            
    try:
        plug = client.plugs.info(device_mac='')
        s = plug.is_on

        plug2 = client.plugs.info(device_mac='')
        s2 = plug2.is_on
        print("testttt" + str(s2))
        if (T == False) and ( s == True):
            client.plugs.turn_off(device_mac=plug.mac, device_model=plug.product.model, after=timedelta(milliseconds=0))
            print("Rh off")
        elif(T == True) and ( s == False):               
            client.plugs.turn_on(device_mac=plug.mac, device_model=plug.product.model)
            plug = client.plugs.info(device_mac=plug.mac)
            print("Rh on")   
    
    except WyzeApiError as e:
    # You will get a WyzeApiError if the request failed
            print(f"Got an error: {e}")  
## print("All Set")

def onoffH(wyzeclient,type):
print(rh)
if(type =="Heat" and rh <= 76.5):
toggleh(true,wyzeclient,type)

elif(type =="Heat" and rh >= 77.0):
    toggleh(false,wyzeclient,type)
      
elif(type =="Rh" and rh <= 73.5):
    toggleh(true,wyzeclient,type)
    
elif(type =="Rh" and rh >= 74.0):
    toggleh(false,wyzeclient,type)

def checkWyze():
client = Client(email='', password='')
try:
response = client.devices_list()
for device in client.devices_list():
print(f"mac: {device.mac}")
print(f"nickname: {device.nickname}")
print(f"is_online: {device.is_online}")
print(f"product model: {device.product.model}")
except WyzeApiError as e:
# You will get a WyzeApiError if the request failed
print(f"Got an error: {e}")

while on !=0:
with InfluxDBClient(url="http://127.0.0.1:", token=token, org=org) as infclient:
query_api = infclient.query_api()
query = ''
result = query_api.query(org=org, query=query)
results = []
for table in result:
for record in table.records:
results.append((record.get_field(), record.get_value()))
rh = record.get_value()

rh = float(rh)
# rh = rh*100
rh = round(rh,1)
print("Temp is....  " + str(rh))
onoffH(wyzeclient,"Heat")
infclient.close()

with InfluxDBClient(url="http://127.0.0.1:", token=token, org=org) as infclient:
    query_api = infclient.query_api()
    query = ''

result = query_api.query(org=org, query=query)
results = []
for table in result:
    for record in table.records:
     results.append((record.get_field(), record.get_value()))
     rh = record.get_value()

rh = float(rh)
rh = rh*100
rh = round(rh,1)
print("humidy is....  " + str(rh))
onoffH(wyzeclient,"Rh")

test = datetime.now().day
if(initDate < datetime.now().day):
    wyzeclient.refresh_token()
    initDate = datetime.now().day
    print("Refreshed")
else:
    print("Refresh Not Needed")



sleep(30)
`

remove any sensitive info

I updated my code. I was plugging 2 plug status and think that errored it out. It ran just fine last night. Will keep posted.

But maybe need to add non type error checking 🤷‍♂️ idk