benq-rm-homeassistant/custom_components/benq_smartboard/test.py

42 lines
1.5 KiB
Python

import logging
from benq_smartboard_lib import BenQSmartBoard, ConnectionError, CommandError, PowerState
# Configure detailed debug logging.
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
# Configurable parameters; update these variables with your Smart Board details.
IP_ADDRESS = "10.10.4.173" # Replace with your Smart Board IP.
PORT = 4660
def run_test():
board = BenQSmartBoard(ip=IP_ADDRESS, port=PORT)
try:
logging.debug('Attempting to connect to the Smart Board.')
board.connect()
logging.info('Connected successfully.')
# Get the current power state.
logging.debug('Sending get_power command.')
current_power = board.get_power()
logging.info(f'Current power state: {current_power}')
# Toggle power state for test purposes.
logging.debug('Toggling power state.')
if current_power.strip() == PowerState.OFF.value:
logging.info("Setting power state to ON.")
success = board.set_power(PowerState.ON)
else:
logging.info("Setting power state to OFF.")
success = board.set_power(PowerState.OFF)
logging.info(f'set_power success: {success}')
except (ConnectionError, CommandError, Exception) as ex:
logging.exception(f'Exception during Smart Board interaction: {ex}')
finally:
logging.debug('Disconnecting from Smart Board.')
board.disconnect()
logging.info('Disconnected.')
# Execute the test.
run_test()