### Get All Controller Properties and Device Details Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Retrieves all controller objects, including their full metadata, connected devices (ports), and connected sensors (for AI controllers). This provides a comprehensive overview of the ACInfinity system. ```python # Get all controller objects with full metadata controllers = service.get_all_controller_properties() for controller in controllers: print(f"Controller: {controller.controller_name}") print(f"ID: {controller.controller_id}") print(f"MAC: {controller.mac_addr}") print(f"Is AI Controller: {controller.is_ai_controller}") # Access connected devices (ports) for device in controller.devices: print(f" Port {device.device_port}: {device.device_name}") # Access connected sensors (AI controllers only) for sensor in controller.sensors: print(f" Sensor Port {sensor.sensor_port}: Type {sensor.sensor_type}") ``` -------------------------------- ### ACInfinityClient HTTP API Client Example (Python) Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Demonstrates the usage of the ACInfinityClient class for interacting with the AC Infinity cloud API. This includes initializing the client, logging in, retrieving controller and device information, and updating device controls and settings. It handles potential connection and authentication errors. ```python import aiohttp from custom_components.ac_infinity.client import ( ACInfinityClient, ACInfinityClientCannotConnect, ACInfinityClientInvalidAuth, ) # Initialize the client with AC Infinity credentials client = ACInfinityClient( host="http://www.acinfinityserver.com", email="user@example.com", password="your_password" ) async def example_usage(): try: # Login to obtain authentication token await client.login() # Check if logged in if client.is_logged_in(): # Get all controllers associated with the account controllers = await client.get_account_controllers() # Returns list of controller dictionaries with device info # [{"devId": 12345, "devName": "My Controller", "temperature": 2500, ...}] for controller in controllers: controller_id = controller["devId"] # Get device mode settings for a specific port port_settings = await client.get_device_mode_settings( controller_id=controller_id, device_port=1 # Port 1-4 depending on controller ) # Returns: {"atType": 3, "onSpead": 8, "devHt": 85, ...} # Update device controls (mode, speed, triggers) await client.update_device_controls( controller_id=controller_id, device_port=1, key_values={ "atType": 2, # Set mode to "On" "onSpead": 7, # Set on-speed to 7 "offSpead": 3, # Set off-speed to 3 } ) # Update advanced device settings await client.update_device_settings( controller_id=controller_id, device_port=1, device_name="Exhaust Fan", key_values={ "devCt": 2, # Temperature calibration offset "devCh": -1, # Humidity calibration offset } ) # For AI controllers, use combined control/settings update await client.update_ai_device_control_and_settings( controller_id=controller_id, device_port=1, key_values={ "atType": 3, # Auto mode "onSelfSpead": 8, # On-speed for AI controllers "activeHt": 1, # Enable high temp trigger "devHt": 85, # High temp threshold (Celsius) } ) except ACInfinityClientCannotConnect: print("Failed to connect to AC Infinity API") except ACInfinityClientInvalidAuth: print("Invalid email or password") finally: # Always close the session when done await client.close() ``` -------------------------------- ### Get Advanced Controller Settings (Calibration) Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Retrieves advanced settings for a controller, such as temperature calibration values. This allows for fine-tuning the sensor readings. ```python # Get advanced settings temp_calibration = service.get_controller_setting( controller_id=device_id, setting_key=AdvancedSettingsKey.CALIBRATE_TEMP, default_value=0 ) ``` -------------------------------- ### Home Assistant Automations with AC Infinity Entities (YAML) Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt This YAML code provides examples of Home Assistant automations that interact with AC Infinity entities. It demonstrates how to trigger actions based on sensor states (e.g., temperature) or time, and how to control device settings like fan speed, mode, and auto-trigger configurations. These automations leverage Home Assistant's `service` calls for `number`, `select`, and `switch` entities. ```yaml # Example automation using AC Infinity entities automation: - alias: "Increase Fan Speed When Hot" trigger: - platform: numeric_state entity_id: sensor.my_controller_temperature above: 28 # Celsius action: - service: number.set_value target: entity_id: number.my_controller_port_1_on_power data: value: 10 # Maximum speed - alias: "Switch to VPD Mode During Flowering" trigger: - platform: time at: "18:00:00" action: - service: select.select_option target: entity_id: select.my_controller_port_1_active_mode data: option: "VPD" - service: number.set_value target: entity_id: number.my_controller_port_1_target_vpd data: value: 1.2 # 1.2 kPa target VPD - alias: "Enable Auto Mode Triggers" trigger: - platform: state entity_id: select.my_controller_port_1_active_mode to: "Auto" action: - service: switch.turn_on target: entity_id: switch.my_controller_port_1_auto_mode_temp_high_enabled - service: number.set_value target: entity_id: number.my_controller_port_1_auto_mode_temp_high_trigger data: value: 30 # 30°C high trigger ``` -------------------------------- ### Get Device Control Settings (Mode, Speed, Triggers) Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Fetches device control settings for a specific port, including the current operating mode, ON speed, and auto-trigger thresholds for temperature and VPD. Mode values are enumerated (e.g., 1=Off, 2=On, 3=Auto). ```python # Get device control settings current_mode = service.get_device_control( controller_id=device_id, device_port=1, setting_key=DeviceControlKey.AT_TYPE, default_value=1 # Default: Off ) # Mode values: 1=Off, 2=On, 3=Auto, 4=Timer-On, 5=Timer-Off, 6=Cycle, 7=Schedule, 8=VPD on_speed = service.get_device_control( device_id, 1, DeviceControlKey.ON_SPEED, 0 ) high_temp_trigger = service.get_device_control( device_id, 1, DeviceControlKey.AUTO_TEMP_HIGH_TRIGGER, 85 ) ``` -------------------------------- ### Refresh Data and Get Device IDs Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Refreshes all data from the ACInfinity API, automatically handling login. It then retrieves a list of all available controller device IDs. ```python async def service_example(): # Refresh all data from API (handles login automatically) await service.refresh() # Get list of controller device IDs device_ids = service.get_device_ids() # Returns: ["12345", "12346"] ``` -------------------------------- ### Get Device/Port Properties (Power, Remaining Time) Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Retrieves properties specific to a device port, such as current power level (SPEAK) and the remaining time until the next mode change. This allows for granular control and monitoring of individual ports. ```python # Get device/port properties port_power = service.get_device_property( controller_id=device_id, device_port=1, property_key=DevicePropertyKey.SPEAK, # Current power level default_value=0 ) remaining_time = service.get_device_property( device_id, 1, DevicePropertyKey.REMAINING_TIME, 0 ) # Seconds until next mode change ``` -------------------------------- ### Get Controller Properties (Temperature, Humidity, VPD, Online Status) Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Iterates through device IDs to retrieve controller properties such as temperature, humidity, VPD, and online status. Temperature is stored as an integer (e.g., 2500 = 25.00°C) and needs to be divided by 100. VPD is stored in tenths (e.g., 102 = 1.02 kPa). ```python for device_id in device_ids: # Get controller properties (readings, metadata) temperature = service.get_controller_property( controller_id=device_id, property_key=ControllerPropertyKey.TEMPERATURE, default_value=0 ) # Temperature stored as integer (2500 = 25.00°C) temp_celsius = temperature / 100 humidity = service.get_controller_property( device_id, ControllerPropertyKey.HUMIDITY, 0 ) / 100 vpd = service.get_controller_property( device_id, ControllerPropertyKey.VPD, 0 ) / 100 is_online = service.get_controller_property( device_id, ControllerPropertyKey.ONLINE, 0 ) == 1 ``` -------------------------------- ### Initialize ACInfinity Client and Service Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Initializes the ACInfinity client with host, email, and password, then creates a service instance. This is the first step before interacting with any ACInfinity devices. ```python client = ACInfinityClient( host="http://www.acinfinityserver.com", email="user@example.com", password="password" ) service = ACInfinityService(client) ``` -------------------------------- ### Advanced Settings Definitions (Python) Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Defines read-write advanced settings for AC Infinity controllers, including calibration values for temperature, humidity, and VPD, dynamic response types, buffer settings, and timer configurations. Allows fine-tuning of environmental control logic. ```python ADVANCED_SETTINGS = { "devCt": "Temperature Calibration (°C)", "devCth": "Temperature Calibration (°F)", "devCh": "Humidity Calibration (%)", "vpdCt": "VPD Leaf Temp Offset (°C)", "isFlag": "Dynamic Response Type (0=Transition, 1=Buffer)", "devTt": "Dynamic Transition Temp (°C)", "devTh": "Dynamic Transition Humidity (%)", "devBt": "Dynamic Buffer Temp (°C)", "devBh": "Dynamic Buffer Humidity (%)", "onTimeSwitch": "Sunrise Timer Enabled", "onTime": "Sunrise Timer Duration (minutes)", "loadType": "Device Load Type", "tempCompare": "Outside Temp Compare", "humiCompare": "Outside Humidity Compare", } ``` -------------------------------- ### ACInfinityService Layer Initialization (Python) Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Shows the initialization of the ACInfinityService class, which acts as a higher-level service layer for managing AC Infinity data. This class includes features like caching, property retrieval, and retry logic for API communication. ```python from custom_components.ac_infinity.client import ACInfinityClient from custom_components.ac_infinity.core import ACInfinityService from custom_components.ac_infinity.const import ( ControllerPropertyKey, DevicePropertyKey, DeviceControlKey, AdvancedSettingsKey, ) # Initialization example would typically follow here, using ACInfinityClient instance ``` -------------------------------- ### Device Control Parameters (Python) Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Defines read-write control parameters for device ports, enabling configuration of active modes, speed settings, temperature/humidity triggers, VPD targets, and timers. Supports various automation and scheduling features. ```python DEVICE_CONTROLS = { "atType": "Active Mode (1-8)", "onSpead": "On Speed (0-10)", "offSpead": "Off Speed (0-10)", "onSelfSpead": "On Speed for AI Controllers", "devHt": "Auto High Temp Trigger (°C)", "devLt": "Auto Low Temp Trigger (°C)", "activeHt": "High Temp Trigger Enabled", "activeLt": "Low Temp Trigger Enabled", "devHh": "Auto High Humidity Trigger (%)", "devLh": "Auto Low Humidity Trigger (%)", "activeHh": "High Humidity Enabled", "activeLh": "Low Humidity Enabled", "activeHtVpd": "VPD High Trigger Enabled", "activeLtVpd": "VPD Low Trigger Enabled", "activeHtVpdNums": "VPD High Trigger (×10)", "activeLtVpdNums": "VPD Low Trigger (×10)", "targetVpd": "Target VPD (×10)", "targetVpdSwitch": "Target VPD Enabled", "targetTemp": "Target Temperature (°C)", "targetTSwitch": "Target Temp Enabled", "targetHumi": "Target Humidity (%)", "targetHumiSwitch": "Target Humidity Enabled", "acitveTimerOn": "Timer-to-On Duration (seconds)", "acitveTimerOff": "Timer-to-Off Duration (seconds)", "activeCycleOn": "Cycle On Duration (seconds)", "activeCycleOff": "Cycle Off Duration (seconds)", "schedStartTime": "Schedule Start (minutes from midnight)", "schedEndtTime": "Schedule End (minutes from midnight)", } ``` -------------------------------- ### Update AC Infinity Device Controls and Settings (Python) Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt This Python code demonstrates how to update various device controls and advanced settings for AC Infinity devices using the ACInfinityService. It covers single and multiple updates for device controls, advanced settings, and controller-level settings. Dependencies include the ACInfinityService, ACInfinityController, ACInfinityDevice, and specific key enums. ```python from custom_components.ac_infinity.core import ( ACInfinityService, ACInfinityController, ACInfinityDevice, ) from custom_components.ac_infinity.const import ( DeviceControlKey, AdvancedSettingsKey, AtType, ) async def update_device_example(service: ACInfinityService): # Get controller and device objects controllers = service.get_all_controller_properties() controller = controllers[0] device = controller.devices[0] # First port device # Update single device control await service.update_device_control( device=device, setting_key=DeviceControlKey.AT_TYPE, new_value=AtType.AUTO # Set to Auto mode (value: 3) ) # Update multiple device controls at once await service.update_device_controls( device=device, key_values={ DeviceControlKey.ON_SPEED: 8, DeviceControlKey.OFF_SPEED: 3, DeviceControlKey.AUTO_TEMP_HIGH_ENABLED: 1, DeviceControlKey.AUTO_TEMP_HIGH_TRIGGER: 85, DeviceControlKey.AUTO_HUMIDITY_HIGH_ENABLED: 1, DeviceControlKey.AUTO_HUMIDITY_HIGH_TRIGGER: 70, } ) # Update single advanced setting await service.update_device_setting( device=device, setting_key=AdvancedSettingsKey.SUNRISE_TIMER_ENABLED, new_value=1 # Enable sunrise timer ) # Update multiple advanced settings await service.update_device_settings( device=device, key_values={ AdvancedSettingsKey.SUNRISE_TIMER_ENABLED: 1, AdvancedSettingsKey.SUNRISE_TIMER_DURATION: 30, # 30 minutes AdvancedSettingsKey.DYNAMIC_RESPONSE_TYPE: 0, # Transition mode AdvancedSettingsKey.DYNAMIC_TRANSITION_TEMP: 5, # 5°C transition } ) # Update controller-level settings (non-AI controllers) await service.update_controller_setting( controller=controller, setting_key=AdvancedSettingsKey.CALIBRATE_TEMP, new_value=2 # +2°C calibration offset ) # Update multiple controller settings await service.update_controller_settings( controller=controller, key_values={ AdvancedSettingsKey.CALIBRATE_TEMP: 2, AdvancedSettingsKey.CALIBRATE_HUMIDITY: -3, AdvancedSettingsKey.VPD_LEAF_TEMP_OFFSET: -4, } ) ``` -------------------------------- ### Device Properties Definitions (Python) Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Defines read-only properties for individual device ports, such as port name, current power level, load state, online status, and time remaining until mode change. Useful for monitoring specific device outputs. ```python DEVICE_PROPERTIES = { "port": "Port Number", "portName": "Port Name", "speak": "Current Power Level (0-10)", "loadState": "Load State", "online": "Port Online Status", "remainTime": "Seconds Until Mode Change", } ``` -------------------------------- ### Check Existence of Device Control Setting Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Checks if a specific device control setting exists for a given controller and port before attempting to retrieve its value. This prevents errors when dealing with devices that may not support all features. ```python # Check if properties exist before accessing if service.get_device_control_exists(device_id, 1, DeviceControlKey.VPD_HIGH_TRIGGER): vpd_high = service.get_device_control( device_id, 1, DeviceControlKey.VPD_HIGH_TRIGGER, 0 ) / 10 # Stored as tenths (102 = 1.02 kPa) ``` -------------------------------- ### Sensor Type Mapping (Python) Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Maps numerical sensor type identifiers to their corresponding descriptions, covering various temperature units, humidity, VPD, soil moisture, CO2, light levels, and water sensors. Essential for interpreting raw sensor data from AI controllers. ```python SENSOR_TYPES = { 0: "Probe Temperature (°F unit)", 1: "Probe Temperature (°C unit)", 2: "Probe Humidity", 3: "Probe VPD", 4: "Controller Temperature (°F unit)", 5: "Controller Temperature (°C unit)", 6: "Controller Humidity", 7: "Controller VPD", 10: "Soil Moisture", 11: "CO2 Level", 12: "Light Level", 20: "Water Sensor", } ``` -------------------------------- ### Controller Properties Definitions (Python) Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Defines read-only sensor properties for AC Infinity controllers, including device identification, environmental readings, and firmware/hardware versions. Values like temperature and humidity require division for accurate units. ```python CONTROLLER_PROPERTIES = { "devId": "Device ID", "devName": "Device Name", "temperature": "Temperature (÷100 for °C)", "humidity": "Humidity (÷100 for %)", "vpdnums": "VPD (÷100 for kPa)", "online": "Online Status (1=online)", "firmwareVersion": "Firmware Version", "hardwareVersion": "Hardware Version", } ``` -------------------------------- ### ACInfinityClient - HTTP API Client Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt The ACInfinityClient class handles direct HTTP communication with the AC Infinity cloud API. It manages authentication, session, and data operations for controllers and devices. ```APIDOC ## ACInfinityClient - HTTP API Client ### Description This client class encapsulates all HTTP communication with the AC Infinity cloud API. It handles authentication, session management, and data retrieval/updates for controllers and connected devices. ### Initialization ```python from custom_components.ac_infinity.client import ACInfinityClient client = ACInfinityClient( host="http://www.acinfinityserver.com", email="user@example.com", password="your_password" ) ``` ### Methods #### `login()` Logs into the AC Infinity cloud to obtain an authentication token. #### `is_logged_in()` Checks if the client is currently authenticated. #### `get_account_controllers()` Retrieves a list of all controllers associated with the account. Returns: ```json [ {"devId": 12345, "devName": "My Controller", "temperature": 2500, ...} ] ``` #### `get_device_mode_settings(controller_id, device_port)` Gets the current mode settings for a specific device port on a controller. Parameters: - `controller_id` (int) - The ID of the controller. - `device_port` (int) - The port number (1-4) of the device. Returns: ```json {"atType": 3, "onSpead": 8, "devHt": 85, ...} ``` #### `update_device_controls(controller_id, device_port, key_values)` Updates basic device controls such as mode, speed, and triggers. Parameters: - `controller_id` (int) - The ID of the controller. - `device_port` (int) - The port number (1-4) of the device. - `key_values` (dict) - A dictionary of key-value pairs to update (e.g., `{"atType": 2, "onSpead": 7}`). #### `update_device_settings(controller_id, device_port, device_name, key_values)` Updates advanced device settings like calibration offsets and device name. Parameters: - `controller_id` (int) - The ID of the controller. - `device_port` (int) - The port number (1-4) of the device. - `device_name` (str) - The name of the device. - `key_values` (dict) - A dictionary of key-value pairs for advanced settings (e.g., `{"devCt": 2, "devCh": -1}`). #### `update_ai_device_control_and_settings(controller_id, device_port, key_values)` For AI controllers, this method updates both control and advanced settings in a single call. Parameters: - `controller_id` (int) - The ID of the controller. - `device_port` (int) - The port number (1-4) of the device. - `key_values` (dict) - A dictionary of key-value pairs for AI device control and settings (e.g., `{"atType": 3, "onSelfSpead": 8, "activeHt": 1, "devHt": 85}`). #### `close()` Closes the underlying aiohttp session. ### Error Handling - `ACInfinityClientCannotConnect`: Raised when connection to the API fails. - `ACInfinityClientInvalidAuth`: Raised for invalid email or password. ### Example Usage ```python import aiohttp from custom_components.ac_infinity.client import ( ACInfinityClient, ACInfinityClientCannotConnect, ACInfinityClientInvalidAuth, ) async def example_usage(): client = ACInfinityClient( host="http://www.acinfinityserver.com", email="user@example.com", password="your_password" ) try: await client.login() if client.is_logged_in(): controllers = await client.get_account_controllers() for controller in controllers: controller_id = controller["devId"] port_settings = await client.get_device_mode_settings(controller_id=controller_id, device_port=1) await client.update_device_controls(controller_id=controller_id, device_port=1, key_values={"atType": 2, "onSpead": 7}) await client.update_device_settings(controller_id=controller_id, device_port=1, device_name="Exhaust Fan", key_values={"devCt": 2}) await client.update_ai_device_control_and_settings(controller_id=controller_id, device_port=1, key_values={"atType": 3, "onSelfSpead": 8}) except ACInfinityClientCannotConnect: print("Failed to connect to AC Infinity API") except ACInfinityClientInvalidAuth: print("Invalid email or password") finally: await client.close() ``` ``` -------------------------------- ### AC Infinity Device Mode Types Reference (Python) Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt This Python code snippet lists the available mode types (AtType) used for selecting device modes in AC Infinity devices. These constants are essential for programmatically setting device modes such as OFF, ON, AUTO, TIMER, SCHEDULE, CYCLE, and VPD. They are used in conjunction with the `update_device_control` service. ```python # Mode Types (AtType) - Used for device mode selection MODE_OFF = 1 MODE_ON = 2 MODE_AUTO = 3 MODE_TIMER_TO_ON = 4 MODE_TIMER_TO_OFF = 5 MODE_CYCLE = 6 MODE_SCHEDULE = 7 MODE_VPD = 8 ``` -------------------------------- ### ACInfinityService - Service Layer Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt The ACInfinityService class provides a higher-level abstraction for managing AC Infinity data, including caching, property retrieval, and robust update logic with retries. ```APIDOC ## ACInfinityService - Service Layer ### Description The `ACInfinityService` class offers a higher-level interface for managing AC Infinity data. It incorporates features like data caching, property retrieval, and coordinated updates with automatic retry mechanisms for handling API communication failures. ### Initialization ```python from custom_components.ac_infinity.client import ACInfinityClient from custom_components.ac_infinity.core import ACInfinityService # Assuming client is already initialized and logged in # client = ACInfinityClient(...) # await client.login() service = ACInfinityService(client=client) ``` ### Key Features - **Caching**: Stores retrieved data to reduce redundant API calls. - **Property Retrieval**: Provides access to device and controller properties. - **Coordinated Updates**: Manages updates to device controls and settings. - **Retry Logic**: Automatically retries failed API operations. ### Constants This service layer utilizes constants defined in `custom_components.ac_infinity.const` for keys related to controllers, devices, controls, and advanced settings. ```python from custom_components.ac_infinity.const import ( ControllerPropertyKey, DevicePropertyKey, DeviceControlKey, AdvancedSettingsKey, ) ``` ``` -------------------------------- ### Close ACInfinity Service Connection Source: https://context7.com/dalinicus/homeassistant-acinfinity/llms.txt Closes the connection to the ACInfinity service. This should be called when the interaction with the devices is complete to free up resources. ```python # Close when done await service.close() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.