Package: pyrituals
PyRituals packageAn async Python wrapper for the Rituals Perfume Genie API.
It allows you to control the diffuser and retrieve its state.
The package supports the first and second version.InstallationpipinstallpyritualsUsageImportfrompyritualsimportAccount,Diffuser,AuthenticationExceptionCreate aaiohttp.ClientSessionto make requestsfromaiohttpimportClientSessionsession=ClientSession()EndpointsDefault endpoints:AUTH_URL="https://rituals.sense-company.com/ocapi/login"# Account.authenticate()ACCOUNT_URL="https://rituals.sense-company.com/api/account/hubs"# Account.get_devices()HUB_URL="https://rituals.sense-company.com/api/account/hub"# Diffuser.update_data()UPDATE_URL="https://rituals.sense-company.com/api/hub/update/attr"# Diffuser.turn_*(), Diffuser.set_*()To change the used API endpoints add anurlparameter to the function. Example:LOGIN_URL="https://rituals.sense-company.com/ocapi/login"account=Account("name@example.com","passw0rd",session)awaitaccount.authenticate(url=LOGIN_URL)AccountCreate an instanceemail="name@example.com"password="passw0rd"account=Account(email,password,session)Authenticatetry:awaitaccount.authenticate()exceptAuthenticationExceptionase:print("Could not authenticate:",e)Account dataThe account data is only available after authentication.account.dataGet linked devicesget_devices()returns a list ofDiffusers.devices=awaitaccount.get_devices()DiffuserDiffuser dataThe initial data and format is different from the data after executingupdate_data().
Some properties require data that is only available after executingupdate_data().
Therefore, it's required to executeupdate_data()before using the diffuser properties.diffuser.datadiffuser.battery_percentagediffuser.chargingdiffuser.has_batterydiffuser.has_cartridgediffuser.hashdiffuser.hub_datadiffuser.hublotdiffuser.filldiffuser.perfumediffuser.perfume_amountdiffuser.room_sizediffuser.is_ondiffuser.is_onlinediffuser.namediffuser.versiondiffuser.wifi_percentagediffuser.room_size_square_meterGet updated dataawaitdiffuser.update_data()Turn the diffuser onawaitdiffuser.turn_on()Turn the diffuser offawaitdiffuser.turn_off()Set the diffuser perfume amountAmount must be an integer between 1 and 3, inclusive.amount=1awaitdiffuser.set_perfume_amount(amount)Set the diffuser room sizeSize must be an integer between 1 and 4, inclusive.size=2awaitdiffuser.set_room_size(size)Set the diffuser room size in square metersSize must be the integer 15, 30, 60 or 100.size=60awaitdiffuser.set_room_size_square_meter(size)ExamplefromaiohttpimportClientSessionfromasyncioimportrunimportpyritualsasyncdefmain():asyncwithClientSession()assession:account=pyrituals.Account("name@example.com","passw0rd",session)try:awaitaccount.authenticate()exceptpyrituals.AuthenticationExceptionasex:print("Could not authenticate:",ex)returnprint("Account data:",account.data)devices=awaitaccount.get_devices()fordiffuserindevices:print("Diffuser data:",diffuser.data)awaitdiffuser.turn_on()awaitdiffuser.set_perfume_amount(1)awaitdiffuser.set_room_size(4)awaitdiffuser.update_data()print("Diffuser updated data:",diffuser.data)ifdiffuser.has_battery:print(f"Battery percentage:{diffuser.battery_percentage}%")run(main())