Package: aiovantage
aiovantageaiovantage is a Python library for interacting with and controlling Vantage InFusion home automation controllers.Uses acontrollerpattern inspired heavily by theaiohuelibrary.This open-source, non-commercial library is not affiliated, associated, authorized, endorsed by, or in any way officially connected with Vantage, and is provided for interoperability purposes only.Table of contentsExampleFeaturesSupported objects typesInstallationUsageExamplefromaiovantageimportVantageasyncwithVantage("192.168.1.2","username","password")asvantage:asyncforloadinvantage.loads:print(f"{load.name}is at{load.level}%")See theexamplesfolder for more examples.FeaturesUses Python asyncio for non-blocking I/O.Exposes "controllers" to make fetching and controlling various objects easy.Uses SSL connections by default, with automatic reconnection.Fetch objects lazily (withasync for obj in controller).Alternatively, eager-fetch objects withcontroller.initialize.Supported objects typesThe following interfaces/controllers are currently supported.TypeDescriptionControllerExamplesAnemoSensorWind speed sensorsvantage.anemo_sensorsExamplesAreaRooms, etcvantage.areasExamplesBlindShades, blindsvantage.blindsExamplesBlindGroupsGroups of blindsvantage.blind_groupsExamplesButtonsKeypad buttonsvantage.buttonsExamplesDryContactsMotion sensors, etcvantage.dry_contactsExamplesGMemVantage variablesvantage.gmemExamplesLightSensorLight sensorsvantage.light_sensorsExamplesLoadLights, relays, etcvantage.loadsExamplesLoadGroupGroups of loadsvantage.load_groupsExamplesMasterVantage controllersvantage.mastersExamplesModuleDimmer modulesvantage.modulesOmniSensorPower, current, etcvantage.omni_sensorsExamplesPowerProfileLoad power profilesvantage.power_profilesExamplesRGBLoadRGB lightsvantage.rgb_loadsExamplesStationsKeypads, etcvantage.stationsExamplesTasksVantage tasksvantage.tasksExamplesTemperatureTemperature sensorsvantage.temperature_sensorsExamplesThermostatThermostatsvantage.thermostatsExamplesIf you have an object that you expect to show up in one of these controllers but is missing, pleasecreate an issueorsubmit a pull request.InstallationAddaiovantageas a dependency to your project, or install it directly:pipinstallaiovantageUsageCreating a clientBegin by importing theVantageclass:fromaiovantageimportVantageThe most convenient way to create a client is by using the async context manager:asyncwithVantage("hostname","username","password")asvantage:# ...use the vantage clientAlternatively, you can manage the lifecycle of the client yourself:fromaiovantageimportVantagevantage=Vantage("hostname","username","password")# ...use the vantage clientvantage.close()Querying objectsTheVantageclass exposes a number ofcontrollers, which can be used to query objects. Controllers can either be populated lazily (by usingasync for), or eagerly (by usingcontroller.initialize()).For example, to get a list of all loads:asyncwithVantage("hostname","username","password")asvantage:asyncforloadinvantage.loads:print(f"{load.name}is at{load.level}%")Alternatively, you can usecontroller.initialize()to eagerly fetch all objects:asyncwithVantage("hostname","username","password")asvantage:awaitvantage.loads.initialize()forloadinvantage.loads:print(f"{load.name}is at{load.level}%")If you aren't interested in the state of the objects, you can callcontroller.initialize(fetch_state=False)to slightly speed up the initialization:asyncwithVantage("hostname","username","password")asvantage:awaitvantage.loads.initialize(fetch_state=False)forloadinvantage.loads:print(f"{load.name}")All controllers implement a django-like query interface, which can be used to filter objects. You can either query by matching attributes:asyncwithVantage("hostname","username","password")asvantage:asyncforloadinvantage.loads.filter(name="Kitchen"):print(f"{load.name}is at{load.level}%")Or by using a filter predicate:asyncwithVantage("hostname","username","password")asvantage:asyncforloadinvantage.loads.filter(lambdaload:load.level>50):print(f"{load.name}is at{load.level}%")Fetching a single objectYou can fetch a single object by id, by callingcontroller.aget()orcontroller.get():asyncwithVantage("hostname","username","password")asvantage:load=awaitvantage.loads.aget(118)print(f"{load.name}is at{load.level}%")These functions also implement the same query interface ascontroller.filter()for querying by
attributes or filter predicate:asyncwithVantage("hostname","username","password")asvantage:load=awaitvantage.loads.aget(name="Kitchen")print(f"{load.name}is at{load.level}%")Controlling objectsMost controllers expose a various methods for controlling the state of objects. The first parameter to these methods is always the vantage id of the object to control.For example, to turn on a load:asyncwithVantage("hostname","username","password")asvantage:awaitvantage.loads.turn_on(118)Subscribing to state changesYou can subscribe to state changes by using thecontroller.subscribe()method:defon_load_state_change(event,load,data):print(f"{load.name}is at{load.level}%")asyncwithVantage("hostname","username","password")asvantage:vantage.loads.subscribe(on_load_state_change)awaitvantage.loads.initialize()Note that a subscription will only receive state changes for objects that have populated into the controller.