You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am experiencing issues with setting a guest access code for a Wyze Lock using the Wyze SDK. Specifically, the SDK fails to detect the keypad associated with the lock, even though the keypad is enabled and visible in the Wyze app.
Context
Device Nickname: HOME_NAME
Keypad Status: Enabled (visible in the Wyze app)
Firmware Version: 1.0.4.0
Steps to Reproduce:
Use the Wyze SDK to list devices.
Attempt to set a guest access code for the lock.
Code Snippet:
importosimporttimeimportargparseimportloggingimportrequestsfromdotenvimportload_dotenvfromwyze_sdkimportClientfromwyze_sdk.errorsimportWyzeApiErrorfromwyze_sdk.models.devices.locksimportLockKeyPermission, LockKeyPermissionType# Setup logginglogging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# Load environment variables from .env fileload_dotenv()
WYZE_ACCESS_TOKEN=os.getenv('WYZE_ACCESS_TOKEN')
WYZE_REFRESH_TOKEN=os.getenv('WYZE_REFRESH_TOKEN')
LOCK_MAC_ADDRESS=os.getenv('LOCK_MAC_ADDRESS') # Load MAC address from .envACCESS_CODE="1234"# Replace with desired access codeACCESS_CODE_NAME="Testtt"# Replace with desired access code nameSTART_TIME=int(time.time()) *1000# Current time in millisecondsEND_TIME=START_TIME+24*60*60*1000# 24 hours from now in milliseconds# Function to refresh the access tokendefrefresh_access_token(refresh_token):
url="https://api.wyzecam.com/app/user/refresh_token"payload= {
"app_ver": "wyze_developer_api",
"app_version": "wyze_developer_api",
"phone_id": "wyze_developer_api",
"refresh_token": refresh_token,
"sc": "wyze_developer_api",
"sv": "wyze_developer_api",
"ts": int(time.time() *1000)
}
headers= {
"Content-Type": "application/json"
}
try:
response=requests.post(url, json=payload, headers=headers)
response.raise_for_status()
data=response.json()
new_access_token=data['data']['access_token']
new_refresh_token=data['data']['refresh_token']
logging.info("Access token refreshed successfully")
returnnew_access_token, new_refresh_tokenexceptrequests.RequestExceptionase:
logging.error(f"Failed to refresh token: {e}")
raise# Function to get the clientdefget_client():
globalWYZE_ACCESS_TOKEN, WYZE_REFRESH_TOKENtry:
client=Client(token=WYZE_ACCESS_TOKEN)
# Test if the access token is validclient.devices_list()
logging.info("Access token is valid")
exceptWyzeApiErrorase:
if"AccessTokenError"instr(e) or"access token expired"instr(e):
logging.warning("Access token expired, refreshing...")
try:
WYZE_ACCESS_TOKEN, WYZE_REFRESH_TOKEN=refresh_access_token(WYZE_REFRESH_TOKEN)
os.environ['WYZE_ACCESS_TOKEN'] =WYZE_ACCESS_TOKENos.environ['WYZE_REFRESH_TOKEN'] =WYZE_REFRESH_TOKENclient=Client(token=WYZE_ACCESS_TOKEN)
exceptExceptionasrefresh_error:
logging.error(f"Failed to refresh access token: {refresh_error}")
raisee# Re-raise the original error if refreshing failselse:
logging.error(f"WyzeApiError: {e}")
raisee# Re-raise the original error if it's not an access token issuereturnclientdefset_guest_access_code(client, lock_mac, access_code, code_name, start_time, end_time):
try:
# Fetch the lock devicedevice=next((dfordinclient.devices_list() ifd.mac==lock_mac), None)
ifnotdevice:
logging.error(f"No device found with MAC address {lock_mac}")
returnlogging.info(f"Setting guest access code for device: {device.nickname}")
permission=LockKeyPermission(
type=LockKeyPermissionType.DURATION,
begin=start_time,
end=end_time
)
response=client.locks.create_access_code(
device_mac=lock_mac,
access_code=access_code,
name=code_name,
permission=permission
)
logging.info(f"API Response: {response}")
exceptWyzeApiErrorase:
logging.error(f"Failed to set guest access code: {e}")
exceptExceptionase:
logging.error(f"Unexpected error while setting guest access code: {e}")
defmain():
parser=argparse.ArgumentParser(description="Wyze Lock Guest Access Code Setter")
args=parser.parse_args()
try:
client=get_client()
set_guest_access_code(client, LOCK_MAC_ADDRESS, ACCESS_CODE, ACCESS_CODE_NAME, START_TIME, END_TIME)
exceptExceptionase:
logging.error(f"Script failed: {e}")
if__name__=="__main__":
main()
Observed Behavior:
The SDK fails to detect the keypad associated with the lock, despite the keypad being enabled and visible in the Wyze app.
The error message encountered: 'NoneType' object has no attribute 'is_enabled'
Expected Behavior:
The SDK should detect the keypad associated with the lock.
The guest access code should be set successfully.
Environment:
Wyze SDK version: 2.1.0
Python version: Python 3.12.4
Operating System: MacOS
Using .env with
WYZE_EMAIL=[email protected]# required the first time to obtain the access tokenWYZE_PASSWORD=your_password# required the first time to obtain the access tokenWYZE_TOTP_KEY=your_totp_key# required to login when account has MFA enabledWYZE_API_KEY=your_api_keyWYZE_KEY_ID=your_key_idWYZE_ACCESS_TOKEN=your_access_token# provided by the scriptWYZE_REFRESH_TOKEN=your_refresh_token# provided by the scriptHOME_1_NAME="Name House"HOME_1_ICAL_URL=your_home_1_airbnb_ical_urlHOME_1_LOCK_DEVICE_MAC=your_home_1_lock_device_macHOME_1_KEYPAD_SERIAL_NUMBER=your_home_1_keypad_device_macHOME_1_CHECK_IN_TIME=16:00HOME_1_CHECK_OUT_TIME=11:00
The text was updated successfully, but these errors were encountered:
I am experiencing issues with setting a guest access code for a Wyze Lock using the Wyze SDK. Specifically, the SDK fails to detect the keypad associated with the lock, even though the keypad is enabled and visible in the Wyze app.
Context
Device Nickname: HOME_NAME
Keypad Status: Enabled (visible in the Wyze app)
Firmware Version: 1.0.4.0
Steps to Reproduce:
Use the Wyze SDK to list devices.
Attempt to set a guest access code for the lock.
Code Snippet:
Observed Behavior:
The SDK fails to detect the keypad associated with the lock, despite the keypad being enabled and visible in the Wyze app.
The error message encountered: 'NoneType' object has no attribute 'is_enabled'
Expected Behavior:
The SDK should detect the keypad associated with the lock.
The guest access code should be set successfully.
Environment:
Wyze SDK version: 2.1.0
Python version: Python 3.12.4
Operating System: MacOS
Using .env with
The text was updated successfully, but these errors were encountered: